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 <apitools.hxx>
28 #include <querycontainer.hxx>
29 #include <tablecontainer.hxx>
30 #include <viewcontainer.hxx>
31 #include <RefreshListener.hxx>
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 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
47 #include <cppuhelper/implbase13.hxx>
48 #include <connectivity/ConnectionWrapper.hxx>
49 #include <connectivity/CommonTools.hxx>
50 #include <connectivity/warningscontainer.hxx>
55 typedef cppu::ImplHelper13
< css::container::XChild
56 , css::sdbcx::XTablesSupplier
57 , css::sdbcx::XViewsSupplier
58 , css::sdbc::XConnection
59 , css::sdbc::XWarningsSupplier
60 , css::sdb::XQueriesSupplier
61 , css::sdb::XSQLQueryComposerFactory
62 , css::sdb::XCommandPreparation
63 , css::lang::XMultiServiceFactory
64 , css::sdbcx::XUsersSupplier
65 , css::sdbcx::XGroupsSupplier
66 , css::sdb::tools::XConnectionTools
67 , css::sdb::application::XTableUIProvider
70 class ODatabaseSource
;
72 class OConnection final
:public ::cppu::BaseMutex
74 ,public ::connectivity::OConnectionWrapper
75 ,public OConnection_Base
76 ,public IRefreshListener
78 css::uno::Reference
< css::sdbcx::XTablesSupplier
>
79 m_xMasterTables
; // just to avoid the recreation of the catalog
80 connectivity::OWeakRefArray m_aStatements
;
81 css::uno::Reference
< css::container::XNameAccess
>
83 connectivity::OWeakRefArray m_aComposers
;
85 // the filter as set on the parent data link at construction of the connection
86 css::uno::Sequence
< OUString
> m_aTableFilter
;
87 css::uno::Sequence
< OUString
> m_aTableTypeFilter
;
88 css::uno::Reference
< css::uno::XComponentContext
> m_aContext
;
89 css::uno::Reference
< css::sdbc::XConnection
> m_xMasterConnection
;
90 css::uno::Reference
< css::sdb::tools::XConnectionTools
> m_xConnectionTools
;
91 css::uno::Reference
< css::sdb::application::XTableUIProvider
> m_xTableUIProvider
;
93 // defines the helper services for example to query the command of a view
94 // @ see com.sun.star.sdb.tools.XViewAccess
95 typedef std::map
< OUString
, css::uno::Reference
< css::uno::XInterface
> > TSupportServices
;
96 TSupportServices m_aSupportServices
;
98 std::unique_ptr
<OTableContainer
> m_pTables
;
99 std::unique_ptr
<OViewContainer
> m_pViews
;
100 ::dbtools::WarningsContainer m_aWarnings
;
101 std::atomic
<std::size_t> m_nInAppend
;
102 bool m_bSupportsViews
; // true when the getTableTypes return "VIEW" as type
103 bool m_bSupportsUsers
;
104 bool m_bSupportsGroups
;
106 virtual ~OConnection() override
;
108 OConnection(ODatabaseSource
& _rDB
109 ,css::uno::Reference
< css::sdbc::XConnection
> const & _rxMaster
110 ,const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
);
112 // css::lang::XTypeProvider
113 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
114 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
116 // css::uno::XInterface
117 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
118 virtual void SAL_CALL
acquire() throw( ) override
;
119 virtual void SAL_CALL
release() throw( ) override
;
122 virtual void SAL_CALL
disposing() override
;
124 // css::container::XChild
125 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getParent( ) override
;
126 virtual void SAL_CALL
setParent( const css::uno::Reference
< css::uno::XInterface
>& Parent
) override
;
128 // css::sdbcx::XTablesSupplier
129 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getTables( ) override
;
130 // css::sdbcx::XViewsSupplier
131 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getViews( ) override
;
133 // css::sdb::XQueriesSupplier
134 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getQueries( ) override
;
136 // css::sdb::XSQLQueryComposerFactory
137 virtual css::uno::Reference
< css::sdb::XSQLQueryComposer
> SAL_CALL
createQueryComposer( ) override
;
139 // css::sdb::XCommandPreparation
140 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareCommand( const OUString
& command
, sal_Int32 commandType
) override
;
142 // css::sdbc::XWarningsSupplier
143 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
144 virtual void SAL_CALL
clearWarnings( ) override
;
146 // css::lang::XServiceInfo
147 virtual OUString SAL_CALL
getImplementationName( ) override
;
148 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
149 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
152 virtual css::uno::Reference
< css::sdbc::XStatement
> SAL_CALL
createStatement( ) override
;
153 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareStatement( const OUString
& sql
) override
;
154 virtual css::uno::Reference
< css::sdbc::XPreparedStatement
> SAL_CALL
prepareCall( const OUString
& sql
) override
;
155 virtual OUString SAL_CALL
nativeSQL( const OUString
& sql
) override
;
156 virtual void SAL_CALL
setAutoCommit( sal_Bool autoCommit
) override
;
157 virtual sal_Bool SAL_CALL
getAutoCommit( ) override
;
158 virtual void SAL_CALL
commit( ) override
;
159 virtual void SAL_CALL
rollback( ) override
;
160 virtual sal_Bool SAL_CALL
isClosed( ) override
;
161 virtual css::uno::Reference
< css::sdbc::XDatabaseMetaData
> SAL_CALL
getMetaData( ) override
;
162 virtual void SAL_CALL
setReadOnly( sal_Bool readOnly
) override
;
163 virtual sal_Bool SAL_CALL
isReadOnly( ) override
;
164 virtual void SAL_CALL
setCatalog( const OUString
& catalog
) override
;
165 virtual OUString SAL_CALL
getCatalog( ) override
;
166 virtual void SAL_CALL
setTransactionIsolation( sal_Int32 level
) override
;
167 virtual sal_Int32 SAL_CALL
getTransactionIsolation( ) override
;
168 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getTypeMap( ) override
;
169 virtual void SAL_CALL
setTypeMap( const css::uno::Reference
< css::container::XNameAccess
>& typeMap
) override
;
171 // css::sdbc::XCloseable
172 virtual void SAL_CALL
close( ) override
;
174 // XMultiServiceFactory
175 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstance( const OUString
& aServiceSpecifier
) override
;
176 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstanceWithArguments( const OUString
& ServiceSpecifier
, const css::uno::Sequence
< css::uno::Any
>& Arguments
) override
;
177 virtual css::uno::Sequence
< OUString
> SAL_CALL
getAvailableServiceNames( ) override
;
180 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getUsers( ) override
;
182 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getGroups( ) override
;
185 virtual css::uno::Reference
< css::sdb::tools::XTableName
> SAL_CALL
createTableName( ) override
;
186 virtual css::uno::Reference
< css::sdb::tools::XObjectNames
> SAL_CALL
getObjectNames( ) override
;
187 virtual css::uno::Reference
< css::sdb::tools::XDataSourceMetaData
> SAL_CALL
getDataSourceMetaData( ) override
;
188 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getFieldsByCommandDescriptor( ::sal_Int32 commandType
, const OUString
& command
, css::uno::Reference
< css::lang::XComponent
>& keepFieldsAlive
) override
;
189 virtual css::uno::Reference
< css::sdb::XSingleSelectQueryComposer
> SAL_CALL
getComposer( ::sal_Int32 commandType
, const OUString
& command
) override
;
192 virtual css::uno::Reference
< css::graphic::XGraphic
> SAL_CALL
getTableIcon( const OUString
& TableName
, ::sal_Int32 ColorMode
) override
;
193 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getTableEditor( const css::uno::Reference
< css::sdb::application::XDatabaseDocumentUI
>& DocumentUI
, const OUString
& TableName
) override
;
196 virtual void refresh(const css::uno::Reference
< css::container::XNameAccess
>& _rToBeRefreshed
) override
;
199 /// @throws css::lang::DisposedException
202 if ( rBHelper
.bDisposed
|| !m_xConnection
.is() )
203 throw css::lang::DisposedException();
206 css::uno::Reference
< css::sdbcx::XTablesSupplier
> const & getMasterTables();
208 /** checks whether or not there are naming conflicts between tables and queries
210 void impl_checkTableQueryNames_nothrow();
212 /** loads the XConnectionTools implementation which we forward the respective functionality to
214 @throws css::uno::RuntimeException
215 if the implementation cannot be loaded
218 m_xConnectionTools is nol <NULL/>
220 void impl_loadConnectionTools_throw();
222 /** reads the table filter and table type filter from the datasource
224 void impl_fillTableFilter();
227 } // namespace dbaccess
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */