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 _DBA_CORE_CONNECTION_HXX_ 24 #define _DBA_CORE_CONNECTION_HXX_ 25 26 #include "apitools.hxx" 27 #include "querycontainer.hxx" 28 #include "tablecontainer.hxx" 29 #include "viewcontainer.hxx" 30 #include "RefreshListener.hxx" 31 32 /** === begin UNO includes === **/ 33 #include <com/sun/star/container/XChild.hpp> 34 #include <com/sun/star/lang/DisposedException.hpp> 35 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> 36 #include <com/sun/star/sdb/XCommandPreparation.hpp> 37 #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 38 #include <com/sun/star/sdbcx/XViewsSupplier.hpp> 39 #include <com/sun/star/sdbcx/XUsersSupplier.hpp> 40 #include <com/sun/star/sdbcx/XGroupsSupplier.hpp> 41 #include <com/sun/star/sdb/XQueriesSupplier.hpp> 42 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 43 #include <com/sun/star/sdb/tools/XConnectionTools.hpp> 44 #include <com/sun/star/sdb/application/XTableUIProvider.hpp> 45 /** === end UNO includes === **/ 46 47 #if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_14) 48 #define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_14 49 #define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 14 50 #include <comphelper/implbase_var.hxx> 51 #endif 52 #include <comphelper/componentcontext.hxx> 53 #include <comphelper/stl_types.hxx> 54 #include <connectivity/ConnectionWrapper.hxx> 55 #include <connectivity/warningscontainer.hxx> 56 57 //........................................................................ 58 namespace dbaccess 59 { 60 //........................................................................ 61 62 //========================================================================== 63 //========================================================================== 64 typedef ::comphelper::ImplHelper14 < ::com::sun::star::container::XChild 65 , ::com::sun::star::sdbcx::XTablesSupplier 66 , ::com::sun::star::sdbcx::XViewsSupplier 67 , ::com::sun::star::sdbc::XConnection 68 , ::com::sun::star::sdbc::XWarningsSupplier 69 , ::com::sun::star::sdb::XQueriesSupplier 70 , ::com::sun::star::sdb::XSQLQueryComposerFactory 71 , ::com::sun::star::sdb::XCommandPreparation 72 , ::com::sun::star::lang::XServiceInfo 73 , ::com::sun::star::lang::XMultiServiceFactory 74 , ::com::sun::star::sdbcx::XUsersSupplier 75 , ::com::sun::star::sdbcx::XGroupsSupplier 76 , ::com::sun::star::sdb::tools::XConnectionTools 77 , ::com::sun::star::sdb::application::XTableUIProvider 78 > OConnection_Base; 79 80 class ODatabaseSource; 81 //========================================================================== 82 //= OConnection 83 //========================================================================== 84 class OConnection :public ::comphelper::OBaseMutex 85 ,public OSubComponent 86 ,public ::connectivity::OConnectionWrapper 87 ,public OConnection_Base 88 ,public IRefreshListener 89 { 90 protected: 91 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > 92 m_xMasterTables; // just to avoid the recreation of the catalog 93 OWeakRefArray m_aStatements; 94 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > 95 m_xQueries; 96 OWeakRefArray m_aComposers; 97 98 // the filter as set on the parent data link at construction of the connection 99 ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableFilter; 100 ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableTypeFilter; 101 ::comphelper::ComponentContext m_aContext; 102 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xMasterConnection; 103 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XConnectionTools > m_xConnectionTools; 104 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XTableUIProvider > m_xTableUIProvider; 105 106 // defines the helper services for example to query the command of a view 107 // @ see com.sun.star.sdb.tools.XViewAccess 108 DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>, TSupportServices); 109 TSupportServices m_aSupportServices; 110 111 112 OTableContainer* m_pTables; 113 OViewContainer* m_pViews; 114 ::dbtools::WarningsContainer m_aWarnings; 115 oslInterlockedCount m_nInAppend; 116 sal_Bool m_bSupportsViews; // true when the getTableTypes return "VIEW" as type 117 sal_Bool m_bSupportsUsers; 118 sal_Bool m_bSupportsGroups; 119 120 protected: 121 virtual ~OConnection(); 122 public: 123 OConnection(ODatabaseSource& _rDB 124 ,::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxMaster 125 ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB); 126 127 // com::sun::star::lang::XTypeProvider 128 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); 129 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException); 130 131 // com::sun::star::uno::XInterface 132 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException); 133 virtual void SAL_CALL acquire() throw( ); 134 virtual void SAL_CALL release() throw( ); 135 136 // OComponentHelper 137 virtual void SAL_CALL disposing(void); 138 139 // ::com::sun::star::container::XChild 140 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent( ) throw(::com::sun::star::uno::RuntimeException); 141 virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) throw(::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); 142 143 // ::com::sun::star::sdbcx::XTablesSupplier 144 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables( ) throw(::com::sun::star::uno::RuntimeException); 145 // ::com::sun::star::sdbcx::XViewsSupplier 146 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getViews( ) throw(::com::sun::star::uno::RuntimeException); 147 148 // ::com::sun::star::sdb::XQueriesSupplier 149 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getQueries( ) throw(::com::sun::star::uno::RuntimeException); 150 151 // ::com::sun::star::sdb::XSQLQueryComposerFactory 152 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLQueryComposer > SAL_CALL createQueryComposer( ) throw(::com::sun::star::uno::RuntimeException); 153 154 // ::com::sun::star::sdb::XCommandPreparation 155 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCommand( const ::rtl::OUString& command, sal_Int32 commandType ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 156 157 // ::com::sun::star::sdbc::XWarningsSupplier 158 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 159 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 160 161 // ::com::sun::star::lang::XServiceInfo 162 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 163 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 164 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 165 166 // XConnection 167 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 168 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 169 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 170 virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 171 virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 172 virtual sal_Bool SAL_CALL getAutoCommit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 173 virtual void SAL_CALL commit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 174 virtual void SAL_CALL rollback( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 175 virtual sal_Bool SAL_CALL isClosed( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 176 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 177 virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 178 virtual sal_Bool SAL_CALL isReadOnly( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 179 virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 180 virtual ::rtl::OUString SAL_CALL getCatalog( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 181 virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 182 virtual sal_Int32 SAL_CALL getTransactionIsolation( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 183 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTypeMap( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 184 virtual void SAL_CALL setTypeMap( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 185 186 // ::com::sun::star::sdbc::XCloseable 187 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 188 189 // XMultiServiceFactory 190 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 191 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 192 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 193 194 // XUsersSupplier 195 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getUsers( ) throw(::com::sun::star::uno::RuntimeException); 196 // XGroupsSupplier 197 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getGroups( ) throw(::com::sun::star::uno::RuntimeException); 198 199 // XConnectionTools 200 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XTableName > SAL_CALL createTableName( ) throw (::com::sun::star::uno::RuntimeException); 201 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XObjectNames > SAL_CALL getObjectNames( ) throw (::com::sun::star::uno::RuntimeException); 202 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XDataSourceMetaData > SAL_CALL getDataSourceMetaData( ) throw (::com::sun::star::uno::RuntimeException); 203 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getFieldsByCommandDescriptor( ::sal_Int32 commandType, const ::rtl::OUString& command, ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& keepFieldsAlive ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 204 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer > SAL_CALL getComposer( ::sal_Int32 commandType, const ::rtl::OUString& command ) throw (::com::sun::star::uno::RuntimeException); 205 206 // XTableUIProvider 207 virtual ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL getTableIcon( const ::rtl::OUString& TableName, ::sal_Int32 ColorMode ) throw (::com::sun::star::uno::RuntimeException); 208 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getTableEditor( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& DocumentUI, const ::rtl::OUString& TableName ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 209 210 // IRefreshListener 211 virtual void refresh(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rToBeRefreshed); 212 213 protected: checkDisposed()214 inline void checkDisposed() throw (::com::sun::star::lang::DisposedException) 215 { 216 if ( rBHelper.bDisposed || !m_xConnection.is() ) 217 throw ::com::sun::star::lang::DisposedException(); 218 } 219 220 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > getMasterTables(); 221 222 private: 223 /** checks whether or not there are naming conflicts between tables and queries 224 */ 225 void impl_checkTableQueryNames_nothrow(); 226 227 /** loads the XConnectionTools implementation which we forward the respective functionality to 228 229 @throws ::com::sun::star::uno::RuntimeException 230 if the implementation cannot be loaded 231 232 @postcond 233 m_xConnectionTools is nol <NULL/> 234 */ 235 void impl_loadConnectionTools_throw(); 236 237 /** reads the table filter and table type filter from the datasourfce 238 */ 239 void impl_fillTableFilter(); 240 }; 241 242 //........................................................................ 243 } // namespace dbaccess 244 //........................................................................ 245 246 #endif // _DBA_CORE_CONNECTION_HXX_ 247 248 249