Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef _DBA_CORE_CONNECTION_HXX_
20 : #define _DBA_CORE_CONNECTION_HXX_
21 :
22 : #include "apitools.hxx"
23 : #include "querycontainer.hxx"
24 : #include "tablecontainer.hxx"
25 : #include "viewcontainer.hxx"
26 : #include "RefreshListener.hxx"
27 :
28 : #include <com/sun/star/container/XChild.hpp>
29 : #include <com/sun/star/lang/DisposedException.hpp>
30 : #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
31 : #include <com/sun/star/sdb/XCommandPreparation.hpp>
32 : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
33 : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
34 : #include <com/sun/star/sdbcx/XUsersSupplier.hpp>
35 : #include <com/sun/star/sdbcx/XGroupsSupplier.hpp>
36 : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
37 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 : #include <com/sun/star/sdb/tools/XConnectionTools.hpp>
39 : #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
40 :
41 : #ifndef INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_14
42 : #define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_14
43 : #define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 14
44 : #include <comphelper/implbase_var.hxx>
45 : #endif
46 : #include <comphelper/componentcontext.hxx>
47 : #include <comphelper/stl_types.hxx>
48 : #include <connectivity/ConnectionWrapper.hxx>
49 : #include <connectivity/warningscontainer.hxx>
50 :
51 : //........................................................................
52 : namespace dbaccess
53 : {
54 : //........................................................................
55 :
56 : //==========================================================================
57 : //==========================================================================
58 : typedef ::comphelper::ImplHelper14 < ::com::sun::star::container::XChild
59 : , ::com::sun::star::sdbcx::XTablesSupplier
60 : , ::com::sun::star::sdbcx::XViewsSupplier
61 : , ::com::sun::star::sdbc::XConnection
62 : , ::com::sun::star::sdbc::XWarningsSupplier
63 : , ::com::sun::star::sdb::XQueriesSupplier
64 : , ::com::sun::star::sdb::XSQLQueryComposerFactory
65 : , ::com::sun::star::sdb::XCommandPreparation
66 : , ::com::sun::star::lang::XServiceInfo
67 : , ::com::sun::star::lang::XMultiServiceFactory
68 : , ::com::sun::star::sdbcx::XUsersSupplier
69 : , ::com::sun::star::sdbcx::XGroupsSupplier
70 : , ::com::sun::star::sdb::tools::XConnectionTools
71 : , ::com::sun::star::sdb::application::XTableUIProvider
72 : > OConnection_Base;
73 :
74 : class ODatabaseSource;
75 : //==========================================================================
76 : //= OConnection
77 : //==========================================================================
78 : class OConnection :public ::comphelper::OBaseMutex
79 : ,public OSubComponent
80 : ,public ::connectivity::OConnectionWrapper
81 : ,public OConnection_Base
82 : ,public IRefreshListener
83 : {
84 : protected:
85 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier >
86 : m_xMasterTables; // just to avoid the recreation of the catalog
87 : OWeakRefArray m_aStatements;
88 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
89 : m_xQueries;
90 : OWeakRefArray m_aComposers;
91 :
92 : // the filter as set on the parent data link at construction of the connection
93 : ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableFilter;
94 : ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableTypeFilter;
95 : ::comphelper::ComponentContext m_aContext;
96 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_xMasterConnection;
97 : ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XConnectionTools > m_xConnectionTools;
98 : ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XTableUIProvider > m_xTableUIProvider;
99 :
100 : // defines the helper services for example to query the command of a view
101 : // @ see com.sun.star.sdb.tools.XViewAccess
102 : DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>, TSupportServices);
103 : TSupportServices m_aSupportServices;
104 :
105 :
106 : OTableContainer* m_pTables;
107 : OViewContainer* m_pViews;
108 : ::dbtools::WarningsContainer m_aWarnings;
109 : oslInterlockedCount m_nInAppend;
110 : sal_Bool m_bSupportsViews; // true when the getTableTypes return "VIEW" as type
111 : sal_Bool m_bSupportsUsers;
112 : sal_Bool m_bSupportsGroups;
113 :
114 : protected:
115 : virtual ~OConnection();
116 : public:
117 : OConnection(ODatabaseSource& _rDB
118 : ,::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxMaster
119 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB);
120 :
121 : // com::sun::star::lang::XTypeProvider
122 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
123 : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
124 :
125 : // com::sun::star::uno::XInterface
126 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException);
127 : virtual void SAL_CALL acquire() throw( );
128 : virtual void SAL_CALL release() throw( );
129 :
130 : // OComponentHelper
131 : virtual void SAL_CALL disposing(void);
132 :
133 : // ::com::sun::star::container::XChild
134 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent( ) throw(::com::sun::star::uno::RuntimeException);
135 : 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);
136 :
137 : // ::com::sun::star::sdbcx::XTablesSupplier
138 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables( ) throw(::com::sun::star::uno::RuntimeException);
139 : // ::com::sun::star::sdbcx::XViewsSupplier
140 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getViews( ) throw(::com::sun::star::uno::RuntimeException);
141 :
142 : // ::com::sun::star::sdb::XQueriesSupplier
143 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getQueries( ) throw(::com::sun::star::uno::RuntimeException);
144 :
145 : // ::com::sun::star::sdb::XSQLQueryComposerFactory
146 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLQueryComposer > SAL_CALL createQueryComposer( ) throw(::com::sun::star::uno::RuntimeException);
147 :
148 : // ::com::sun::star::sdb::XCommandPreparation
149 : 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);
150 :
151 : // ::com::sun::star::sdbc::XWarningsSupplier
152 : virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
153 : virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
154 :
155 : // ::com::sun::star::lang::XServiceInfo
156 : virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
157 : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
158 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
159 :
160 : // XConnection
161 : 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);
162 : 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);
163 : 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);
164 : virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
165 : virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
166 : virtual sal_Bool SAL_CALL getAutoCommit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
167 : virtual void SAL_CALL commit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
168 : virtual void SAL_CALL rollback( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
169 : virtual sal_Bool SAL_CALL isClosed( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
170 : 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);
171 : virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
172 : virtual sal_Bool SAL_CALL isReadOnly( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
173 : virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
174 : virtual ::rtl::OUString SAL_CALL getCatalog( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
175 : virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
176 : virtual sal_Int32 SAL_CALL getTransactionIsolation( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
177 : 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);
178 : 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);
179 :
180 : // ::com::sun::star::sdbc::XCloseable
181 : virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
182 :
183 : // XMultiServiceFactory
184 : 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);
185 : 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);
186 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
187 :
188 : // XUsersSupplier
189 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getUsers( ) throw(::com::sun::star::uno::RuntimeException);
190 : // XGroupsSupplier
191 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getGroups( ) throw(::com::sun::star::uno::RuntimeException);
192 :
193 : // XConnectionTools
194 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XTableName > SAL_CALL createTableName( ) throw (::com::sun::star::uno::RuntimeException);
195 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XObjectNames > SAL_CALL getObjectNames( ) throw (::com::sun::star::uno::RuntimeException);
196 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::tools::XDataSourceMetaData > SAL_CALL getDataSourceMetaData( ) throw (::com::sun::star::uno::RuntimeException);
197 : 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);
198 : 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);
199 :
200 : // XTableUIProvider
201 : 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);
202 : 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);
203 :
204 : // IRefreshListener
205 : virtual void refresh(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rToBeRefreshed);
206 :
207 : protected:
208 0 : inline void checkDisposed() throw (::com::sun::star::lang::DisposedException)
209 : {
210 0 : if ( rBHelper.bDisposed || !m_xConnection.is() )
211 0 : throw ::com::sun::star::lang::DisposedException();
212 0 : }
213 :
214 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > getMasterTables();
215 :
216 : private:
217 : /** checks whether or not there are naming conflicts between tables and queries
218 : */
219 : void impl_checkTableQueryNames_nothrow();
220 :
221 : /** loads the XConnectionTools implementation which we forward the respective functionality to
222 :
223 : @throws ::com::sun::star::uno::RuntimeException
224 : if the implementation cannot be loaded
225 :
226 : @postcond
227 : m_xConnectionTools is nol <NULL/>
228 : */
229 : void impl_loadConnectionTools_throw();
230 :
231 : /** reads the table filter and table type filter from the datasourfce
232 : */
233 : void impl_fillTableFilter();
234 : };
235 :
236 : //........................................................................
237 : } // namespace dbaccess
238 : //........................................................................
239 :
240 : #endif // _DBA_CORE_CONNECTION_HXX_
241 :
242 :
243 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|