1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _DBA_CORE_CONNECTION_HXX_ 28 #define _DBA_CORE_CONNECTION_HXX_ 29 30 #include "apitools.hxx" 31 #include "querycontainer.hxx" 32 #include "tablecontainer.hxx" 33 #include "viewcontainer.hxx" 34 #include "RefreshListener.hxx" 35 36 /** === begin UNO includes === **/ 37 #include <com/sun/star/container/XChild.hpp> 38 #include <com/sun/star/lang/DisposedException.hpp> 39 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> 40 #include <com/sun/star/sdb/XCommandPreparation.hpp> 41 #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 42 #include <com/sun/star/sdbcx/XViewsSupplier.hpp> 43 #include <com/sun/star/sdbcx/XUsersSupplier.hpp> 44 #include <com/sun/star/sdbcx/XGroupsSupplier.hpp> 45 #include <com/sun/star/sdb/XQueriesSupplier.hpp> 46 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 47 #include <com/sun/star/sdb/tools/XConnectionTools.hpp> 48 #include <com/sun/star/sdb/application/XTableUIProvider.hpp> 49 /** === end UNO includes === **/ 50 51 #if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_14) 52 #define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_14 53 #define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 14 54 #include <comphelper/implbase_var.hxx> 55 #endif 56 #include <comphelper/componentcontext.hxx> 57 #include <comphelper/stl_types.hxx> 58 #include <connectivity/ConnectionWrapper.hxx> 59 #include <connectivity/warningscontainer.hxx> 60 61 //........................................................................ 62 namespace dbaccess 63 { 64 //........................................................................ 65 66 //========================================================================== 67 //========================================================================== 68 typedef ::comphelper::ImplHelper14 < ::com::sun::star::container::XChild 69 , ::com::sun::star::sdbcx::XTablesSupplier 70 , ::com::sun::star::sdbcx::XViewsSupplier 71 , ::com::sun::star::sdbc::XConnection 72 , ::com::sun::star::sdbc::XWarningsSupplier 73 , ::com::sun::star::sdb::XQueriesSupplier 74 , ::com::sun::star::sdb::XSQLQueryComposerFactory 75 , ::com::sun::star::sdb::XCommandPreparation 76 , ::com::sun::star::lang::XServiceInfo 77 , ::com::sun::star::lang::XMultiServiceFactory 78 , ::com::sun::star::sdbcx::XUsersSupplier 79 , ::com::sun::star::sdbcx::XGroupsSupplier 80 , ::com::sun::star::sdb::tools::XConnectionTools 81 , ::com::sun::star::sdb::application::XTableUIProvider 82 > OConnection_Base; 83 84 class ODatabaseSource; 85 //========================================================================== 86 //= OConnection 87 //========================================================================== 88 class OConnection :public ::comphelper::OBaseMutex 89 ,public OSubComponent 90 ,public ::connectivity::OConnectionWrapper 91 ,public OConnection_Base 92 ,public IRefreshListener 93 { 94 protected: 95 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > 96 m_xMasterTables; // just to avoid the recreation of the catalog 97 OWeakRefArray m_aStatements; 98 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > 99 m_xQueries; 100 OWeakRefArray m_aComposers; 101 102 // the filter as set on the parent data link at construction of the connection 103 ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableFilter; 104 ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableTypeFilter; 105 ::comphelper::ComponentContext m_aContext; 106 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xMasterConnection; 107 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XConnectionTools > m_xConnectionTools; 108 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XTableUIProvider > m_xTableUIProvider; 109 110 // defines the helper services for example to query the command of a view 111 // @ see com.sun.star.sdb.tools.XViewAccess 112 DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>, TSupportServices); 113 TSupportServices m_aSupportServices; 114 115 116 OTableContainer* m_pTables; 117 OViewContainer* m_pViews; 118 ::dbtools::WarningsContainer m_aWarnings; 119 oslInterlockedCount m_nInAppend; 120 sal_Bool m_bSupportsViews; // true when the getTableTypes return "VIEW" as type 121 sal_Bool m_bSupportsUsers; 122 sal_Bool m_bSupportsGroups; 123 124 protected: 125 virtual ~OConnection(); 126 public: 127 OConnection(ODatabaseSource& _rDB 128 ,::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxMaster 129 ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB); 130 131 // com::sun::star::lang::XTypeProvider 132 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); 133 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException); 134 135 // com::sun::star::uno::XInterface 136 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException); 137 virtual void SAL_CALL acquire() throw( ); 138 virtual void SAL_CALL release() throw( ); 139 140 // OComponentHelper 141 virtual void SAL_CALL disposing(void); 142 143 // ::com::sun::star::container::XChild 144 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent( ) throw(::com::sun::star::uno::RuntimeException); 145 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); 146 147 // ::com::sun::star::sdbcx::XTablesSupplier 148 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables( ) throw(::com::sun::star::uno::RuntimeException); 149 // ::com::sun::star::sdbcx::XViewsSupplier 150 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getViews( ) throw(::com::sun::star::uno::RuntimeException); 151 152 // ::com::sun::star::sdb::XQueriesSupplier 153 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getQueries( ) throw(::com::sun::star::uno::RuntimeException); 154 155 // ::com::sun::star::sdb::XSQLQueryComposerFactory 156 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLQueryComposer > SAL_CALL createQueryComposer( ) throw(::com::sun::star::uno::RuntimeException); 157 158 // ::com::sun::star::sdb::XCommandPreparation 159 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); 160 161 // ::com::sun::star::sdbc::XWarningsSupplier 162 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 163 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 164 165 // ::com::sun::star::lang::XServiceInfo 166 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 167 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 168 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 169 170 // XConnection 171 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); 172 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); 173 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); 174 virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 175 virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 176 virtual sal_Bool SAL_CALL getAutoCommit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 177 virtual void SAL_CALL commit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 178 virtual void SAL_CALL rollback( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 179 virtual sal_Bool SAL_CALL isClosed( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 180 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); 181 virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 182 virtual sal_Bool SAL_CALL isReadOnly( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 183 virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 184 virtual ::rtl::OUString SAL_CALL getCatalog( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 185 virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 186 virtual sal_Int32 SAL_CALL getTransactionIsolation( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 187 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); 188 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); 189 190 // ::com::sun::star::sdbc::XCloseable 191 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 192 193 // XMultiServiceFactory 194 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); 195 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); 196 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 197 198 // XUsersSupplier 199 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getUsers( ) throw(::com::sun::star::uno::RuntimeException); 200 // XGroupsSupplier 201 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getGroups( ) throw(::com::sun::star::uno::RuntimeException); 202 203 // XConnectionTools 204 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XTableName > SAL_CALL createTableName( ) throw (::com::sun::star::uno::RuntimeException); 205 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XObjectNames > SAL_CALL getObjectNames( ) throw (::com::sun::star::uno::RuntimeException); 206 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XDataSourceMetaData > SAL_CALL getDataSourceMetaData( ) throw (::com::sun::star::uno::RuntimeException); 207 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); 208 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); 209 210 // XTableUIProvider 211 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); 212 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); 213 214 // IRefreshListener 215 virtual void refresh(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rToBeRefreshed); 216 217 protected: 218 inline void checkDisposed() throw (::com::sun::star::lang::DisposedException) 219 { 220 if ( rBHelper.bDisposed || !m_xConnection.is() ) 221 throw ::com::sun::star::lang::DisposedException(); 222 } 223 224 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > getMasterTables(); 225 226 private: 227 /** checks whether or not there are naming conflicts between tables and queries 228 */ 229 void impl_checkTableQueryNames_nothrow(); 230 231 /** loads the XConnectionTools implementation which we forward the respective functionality to 232 233 @throws ::com::sun::star::uno::RuntimeException 234 if the implementation cannot be loaded 235 236 @postcond 237 m_xConnectionTools is nol <NULL/> 238 */ 239 void impl_loadConnectionTools_throw(); 240 241 /** reads the table filter and table type filter from the datasourfce 242 */ 243 void impl_fillTableFilter(); 244 }; 245 246 //........................................................................ 247 } // namespace dbaccess 248 //........................................................................ 249 250 #endif // _DBA_CORE_CONNECTION_HXX_ 251 252 253