1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef DBACCESS_CORE_FILTERED_CONTAINER_HXX 24 #define DBACCESS_CORE_FILTERED_CONTAINER_HXX 25 26 #include <com/sun/star/container/XNameAccess.hpp> 27 #include <com/sun/star/sdbc/XConnection.hpp> 28 29 #include <connectivity/sdbcx/VCollection.hxx> 30 31 namespace dbtools 32 { 33 class IWarningsContainer; 34 } 35 36 namespace dbaccess 37 { 38 class IRefreshListener; 39 40 class OFilteredContainer : public ::connectivity::sdbcx::OCollection 41 { 42 private: 43 mutable sal_Bool m_bConstructed; // late ctor called 44 45 protected: 46 ::dbtools::IWarningsContainer* m_pWarningsContainer; 47 IRefreshListener* m_pRefreshListener; 48 oslInterlockedCount& m_nInAppend; 49 50 // holds the original container which where set in construct but they can be null 51 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xMasterContainer; 52 ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XConnection > m_xConnection; 53 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData; 54 55 /** returns a string denoting the only type of tables allowed in this container, or an empty string 56 if there is no such restriction 57 */ 58 virtual ::rtl::OUString getTableTypeRestriction() const = 0; 59 addMasterContainerListener()60 inline virtual void addMasterContainerListener(){} removeMasterContainerListener()61 inline virtual void removeMasterContainerListener(){} 62 63 // ::connectivity::sdbcx::OCollection 64 virtual void impl_refresh() throw(::com::sun::star::uno::RuntimeException); 65 66 virtual ::rtl::OUString getNameForObject(const ::connectivity::sdbcx::ObjectType& _xObject); 67 68 /** tell the container to free all elements and all additional resources.<BR> 69 After using this method the object may be reconstructed by calling one of the <code>constrcuct</code> methods. 70 */ 71 virtual void SAL_CALL disposing(); 72 73 class EnsureReset 74 { 75 public: EnsureReset(oslInterlockedCount & _rValueLocation)76 EnsureReset( oslInterlockedCount& _rValueLocation) 77 :m_rValue( _rValueLocation ) 78 { 79 osl_incrementInterlockedCount(&m_rValue); 80 } 81 ~EnsureReset()82 ~EnsureReset() 83 { 84 osl_decrementInterlockedCount(&m_rValue); 85 } 86 87 private: 88 oslInterlockedCount& m_rValue; 89 }; 90 91 /** retrieve a table type filter to pass to <member scope="com::sun::star::sdbc">XDatabaseMetaData::getTables</member>, 92 according to the current data source settings 93 */ 94 void getAllTableTypeFilter( ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rFilter ) const; 95 96 public: 97 /** ctor of the container. The parent has to support the <type scope="com::sun::star::sdbc">XConnection</type> 98 interface.<BR> 99 @param _rParent the object which acts as parent for the container. 100 all refcounting is rerouted to this object 101 @param _rMutex the access safety object of the parent 102 @param _rTableFilter restricts the visible tables by name 103 @param _rTableTypeFilter restricts the visible tables by type 104 @see construct 105 */ 106 OFilteredContainer( ::cppu::OWeakObject& _rParent, 107 ::osl::Mutex& _rMutex, 108 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xCon, 109 sal_Bool _bCase, 110 IRefreshListener* _pRefreshListener, 111 ::dbtools::IWarningsContainer* _pWarningsContainer, 112 oslInterlockedCount& _nInAppend 113 ); 114 dispose()115 inline void dispose() { disposing(); } 116 117 /** late ctor. The container will fill itself with the data got by the connection meta data, considering the 118 filters given (the connection is the parent object you passed in the ctor). 119 */ 120 void construct( 121 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rTableFilter, 122 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rTableTypeFilter 123 ); 124 125 /** late ctor. The container will fill itself with wrapper objects for the tables returned by the given 126 name container. 127 */ 128 void construct( 129 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxMasterContainer, 130 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rTableFilter, 131 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rTableTypeFilter 132 ); 133 isInitialized() const134 inline sal_Bool isInitialized() const { return m_bConstructed; } 135 }; 136 // .............................................................................. 137 } // namespace 138 // .............................................................................. 139 140 #endif // DBACCESS_CORE_FILTERED_CONTAINER_HXX 141