1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sal/config.h>
27 #include "querycontainer.hxx"
28 #include "tablecontainer.hxx"
29 #include "viewcontainer.hxx"
30 #include "RefreshListener.hxx"
32 #include <com/sun/star/container/XChild.hpp>
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
35 #include <com/sun/star/sdb/XCommandPreparation.hpp>
36 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
37 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
38 #include <com/sun/star/sdbcx/XUsersSupplier.hpp>
39 #include <com/sun/star/sdbcx/XGroupsSupplier.hpp>
40 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/sdb/tools/XConnectionTools.hpp>
43 #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
44 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
46 #include <cppuhelper/implbase13.hxx>
47 #include <connectivity/ConnectionWrapper.hxx>
48 #include <connectivity/CommonTools.hxx>
49 #include <connectivity/warningscontainer.hxx>
50 #include <unotools/weakref.hxx>
55 typedef cppu::ImplInheritanceHelper
< connectivity::OConnectionWrapper
56 , css::container::XChild
57 , css::sdbcx::XTablesSupplier
58 , css::sdbcx::XViewsSupplier
59 , css::sdbc::XConnection
60 , css::sdbc::XWarningsSupplier
61 , css::sdb::XQueriesSupplier
62 , css::sdb::XSQLQueryComposerFactory
63 , css::sdb::XCommandPreparation
64 , css::lang::XMultiServiceFactory
65 , css::sdbcx::XUsersSupplier
66 , css::sdbcx::XGroupsSupplier
67 , css::sdb::tools::XConnectionTools
68 , css::sdb::application::XTableUIProvider
71 class ODatabaseSource
;
73 class OConnection final
:public OConnection_Base
74 ,public IRefreshListener
76 unotools::WeakReference
<ODatabaseSource
> m_xParent
;
77 css::uno::Reference
< css::sdbcx::XTablesSupplier
>
78 m_xMasterTables
; // just to avoid the recreation of the catalog
79 connectivity::OWeakRefArray m_aStatements
;
80 rtl::Reference
< OQueryContainer
> m_xQueries
;
81 connectivity::OWeakRefArray m_aComposers
;
83 // the filter as set on the parent data link at construction of the connection
84 css::uno::Sequence
< OUString
> m_aTableFilter
;
85 css::uno::Sequence
< OUString
> m_aTableTypeFilter
;
86 css::uno::Reference
< css::uno::XComponentContext
> m_aContext
;
87 css::uno::Reference
< css::sdbc::XConnection
> m_xMasterConnection
;
88 css::uno::Reference
< css::sdb::tools::XConnectionTools
> m_xConnectionTools
;
89 css::uno::Reference
< css::sdb::application::XTableUIProvider
> m_xTableUIProvider
;
91 // defines the helper services for example to query the command of a view
92 // @ see com.sun.star.sdb.tools.XViewAccess
93 typedef std::map
< OUString
, css::uno::Reference
< css::uno::XInterface
> > TSupportServices
;
94 TSupportServices m_aSupportServices
;
96 std::unique_ptr
<OTableContainer
> m_pTables
;
97 std::unique_ptr
<OViewContainer
> m_pViews
;
98 ::dbtools::WarningsContainer m_aWarnings
;
99 std::atomic
<std::size_t> m_nInAppend
;
100 bool m_bSupportsViews
; // true when the getTableTypes return "VIEW" as type
101 bool m_bSupportsUsers
;
102 bool m_bSupportsGroups
;
104 virtual ~OConnection() override
;
106 OConnection(ODatabaseSource
& _rDB
107 ,css::uno::Reference
< css::sdbc::XConnection
> const & _rxMaster
108 ,const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
);
110 // css::lang::XTypeProvider
111 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
113 // css::uno::XInterface
114 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
117 virtual void SAL_CALL
disposing() override
;
119 // css::container::XChild
120 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getParent( ) override
;
121 virtual void SAL_CALL
setParent( const css::uno::Reference
< css::uno::XInterface
>& Parent
) override
;
123 // css::sdbcx::XTablesSupplier
124 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getTables( ) override
;
125 // css::sdbcx::XViewsSupplier
126 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getViews( ) override
;
128 // css::sdb::XQueriesSupplier
129 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getQueries( ) override
;
131 // css::sdb::XSQLQueryComposerFactory
132 virtual css::uno::Reference
< css::sdb::XSQLQueryComposer
> SAL_CALL
createQueryComposer( ) override
;
134 // css::sdb::XCommandPreparation
135 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareCommand( const OUString
& command
, sal_Int32 commandType
) override
;
137 // css::sdbc::XWarningsSupplier
138 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
139 virtual void SAL_CALL
clearWarnings( ) override
;
141 // css::lang::XServiceInfo
142 virtual OUString SAL_CALL
getImplementationName( ) override
;
143 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
144 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
147 virtual css::uno::Reference
< css::sdbc::XStatement
> SAL_CALL
createStatement( ) override
;
148 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareStatement( const OUString
& sql
) override
;
149 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareCall( const OUString
& sql
) override
;
150 virtual OUString SAL_CALL
nativeSQL( const OUString
& sql
) override
;
151 virtual void SAL_CALL
setAutoCommit( sal_Bool autoCommit
) override
;
152 virtual sal_Bool SAL_CALL
getAutoCommit( ) override
;
153 virtual void SAL_CALL
commit( ) override
;
154 virtual void SAL_CALL
rollback( ) override
;
155 virtual sal_Bool SAL_CALL
isClosed( ) override
;
156 virtual css::uno::Reference
< css::sdbc::XDatabaseMetaData
> SAL_CALL
getMetaData( ) override
;
157 virtual void SAL_CALL
setReadOnly( sal_Bool readOnly
) override
;
158 virtual sal_Bool SAL_CALL
isReadOnly( ) override
;
159 virtual void SAL_CALL
setCatalog( const OUString
& catalog
) override
;
160 virtual OUString SAL_CALL
getCatalog( ) override
;
161 virtual void SAL_CALL
setTransactionIsolation( sal_Int32 level
) override
;
162 virtual sal_Int32 SAL_CALL
getTransactionIsolation( ) override
;
163 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getTypeMap( ) override
;
164 virtual void SAL_CALL
setTypeMap( const css::uno::Reference
< css::container::XNameAccess
>& typeMap
) override
;
166 // css::sdbc::XCloseable
167 virtual void SAL_CALL
close( ) override
;
169 // XMultiServiceFactory
170 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstance( const OUString
& aServiceSpecifier
) override
;
171 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstanceWithArguments( const OUString
& ServiceSpecifier
, const css::uno::Sequence
< css::uno::Any
>& Arguments
) override
;
172 virtual css::uno::Sequence
< OUString
> SAL_CALL
getAvailableServiceNames( ) override
;
175 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getUsers( ) override
;
177 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getGroups( ) override
;
180 virtual css::uno::Reference
< css::sdb::tools::XTableName
> SAL_CALL
createTableName( ) override
;
181 virtual css::uno::Reference
< css::sdb::tools::XObjectNames
> SAL_CALL
getObjectNames( ) override
;
182 virtual css::uno::Reference
< css::sdb::tools::XDataSourceMetaData
> SAL_CALL
getDataSourceMetaData( ) override
;
183 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getFieldsByCommandDescriptor( ::sal_Int32 commandType
, const OUString
& command
, css::uno::Reference
< css::lang::XComponent
>& keepFieldsAlive
) override
;
184 virtual css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
> SAL_CALL
getComposer( ::sal_Int32 commandType
, const OUString
& command
) override
;
187 virtual css::uno::Reference
< css::graphic::XGraphic
> SAL_CALL
getTableIcon( const OUString
& TableName
, ::sal_Int32 ColorMode
) override
;
188 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getTableEditor( const css::uno::Reference
< css::sdb::application::XDatabaseDocumentUI
>& DocumentUI
, const OUString
& TableName
) override
;
191 virtual void refresh(const css::uno::Reference
< css::container::XNameAccess
>& _rToBeRefreshed
) override
;
194 /// @throws css::lang::DisposedException
197 if ( rBHelper
.bDisposed
|| !m_xConnection
.is() )
198 throw css::lang::DisposedException();
201 css::uno::Reference
< css::sdbcx::XTablesSupplier
> const & getMasterTables();
203 /** checks whether or not there are naming conflicts between tables and queries
205 void impl_checkTableQueryNames_nothrow();
207 /** loads the XConnectionTools implementation which we forward the respective functionality to
209 @throws css::uno::RuntimeException
210 if the implementation cannot be loaded
213 m_xConnectionTools is not <NULL/>
215 void impl_loadConnectionTools_throw();
217 /** reads the table filter and table type filter from the datasource
219 void impl_fillTableFilter();
222 } // namespace dbaccess
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */