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