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 .
20 #ifndef INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DATASOURCE_HXX
21 #define INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DATASOURCE_HXX
23 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/sdbc/XDataSource.hpp>
26 #include <com/sun/star/container/XContainerListener.hpp>
27 #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
28 #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
29 #include <com/sun/star/sdbc/XIsolatedConnection.hpp>
30 #include <com/sun/star/util/XNumberFormatter.hpp>
31 #include <com/sun/star/document/XEventListener.hpp>
32 #include <com/sun/star/util/XFlushable.hpp>
33 #include <cppuhelper/propshlp.hxx>
34 #include <comphelper/proparrhlp.hxx>
35 #include <cppuhelper/weakref.hxx>
36 #include <cppuhelper/compbase.hxx>
37 #include <com/sun/star/embed/XTransactionListener.hpp>
38 #include "apitools.hxx"
39 #include "bookmarkcontainer.hxx"
40 #include <rtl/ref.hxx>
41 #include <connectivity/CommonTools.hxx>
42 #include <comphelper/broadcasthelper.hxx>
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #include <com/sun/star/beans/PropertyValue.hpp>
45 #include <com/sun/star/sdb/XCompletedConnection.hpp>
46 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
47 #include <com/sun/star/embed/XStorage.hpp>
48 #include "ContentHelper.hxx"
49 #include <com/sun/star/document/XStorageBasedDocument.hpp>
50 #include <com/sun/star/embed/ElementModes.hpp>
51 #include <com/sun/star/util/XRefreshable.hpp>
52 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
53 #include "ModelImpl.hxx"
58 class OSharedConnectionManager
;
61 typedef ::cppu::WeakComponentImplHelper
< css::lang::XServiceInfo
62 , css::sdbc::XDataSource
63 , css::sdb::XBookmarksSupplier
64 , css::sdb::XQueryDefinitionsSupplier
65 , css::sdb::XCompletedConnection
66 , css::container::XContainerListener
67 , css::sdbc::XIsolatedConnection
68 , css::sdbcx::XTablesSupplier
69 , css::util::XFlushable
70 , css::util::XFlushListener
71 , css::sdb::XDocumentDataSource
72 > ODatabaseSource_Base
;
74 class ODatabaseSource
:public ModelDependentComponent
// must be first
75 ,public ODatabaseSource_Base
76 ,public ::cppu::OPropertySetHelper
77 ,public ::comphelper::OPropertyArrayUsageHelper
< ODatabaseSource
>
79 friend class ODatabaseContext
;
80 friend class OConnection
;
81 friend class OSharedConnectionManager
;
84 using ODatabaseSource_Base::rBHelper
;
85 // note: this thing uses the ref-count of "this", see OBookmarkContainer::acquire!
86 OBookmarkContainer m_Bookmarks
;
87 ::comphelper::OInterfaceContainerHelper2 m_aFlushListeners
;
90 virtual ~ODatabaseSource() override
;
93 explicit ODatabaseSource( const ::rtl::Reference
< ODatabaseModelImpl
>& _pImpl
);
95 struct DBContextAccess
{ friend class ODatabaseContext
; private: DBContextAccess() { } };
97 /** sets a new name for the data source
99 The name of a data source (our m_sName member) is the registration name, *if* the
100 data source actually *is* registered at the database context.
102 Normally, this name is passed at time of creation of the ODatabaseModelImpl instance,
103 but if a newly created data source is registered, then it must be possible to propagate
104 the new trgistration name.
107 const css::uno::Reference
< css::sdb::XDocumentDataSource
>& _rxDocument
,
108 const OUString
& _rNewName
,
112 // XContainerListener
113 virtual void SAL_CALL
elementInserted( const css::container::ContainerEvent
& Event
) throw (css::uno::RuntimeException
, std::exception
) override
;
114 virtual void SAL_CALL
elementRemoved( const css::container::ContainerEvent
& Event
) throw (css::uno::RuntimeException
, std::exception
) override
;
115 virtual void SAL_CALL
elementReplaced( const css::container::ContainerEvent
& Event
) throw (css::uno::RuntimeException
, std::exception
) override
;
116 // css::sdbcx::XTablesSupplier
117 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getTables( ) throw(css::uno::RuntimeException
, std::exception
) override
;
119 // css::lang::XTypeProvider
120 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() throw (css::uno::RuntimeException
, std::exception
) override
;
121 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() throw (css::uno::RuntimeException
, std::exception
) override
;
123 // css::uno::XInterface
124 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) throw (css::uno::RuntimeException
, std::exception
) override
;
125 virtual void SAL_CALL
acquire() throw( ) override
;
126 virtual void SAL_CALL
release() throw( ) override
;
128 // css::lang::XServiceInfo
129 virtual OUString SAL_CALL
getImplementationName( ) throw(css::uno::RuntimeException
, std::exception
) override
;
130 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(css::uno::RuntimeException
, std::exception
) override
;
131 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(css::uno::RuntimeException
, std::exception
) override
;
134 virtual void SAL_CALL
disposing() override
;
136 // css::beans::XPropertySet
137 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(css::uno::RuntimeException
, std::exception
) override
;
139 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) throw(css::uno::RuntimeException
, std::exception
) override
;
141 // comphelper::OPropertyArrayUsageHelper
142 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const override
;
144 // cppu::OPropertySetHelper
145 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
147 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
148 css::uno::Any
& rConvertedValue
,
149 css::uno::Any
& rOldValue
,
151 const css::uno::Any
& rValue
)
152 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) override
;
153 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
155 const css::uno::Any
& rValue
157 throw (css::uno::Exception
, std::exception
) override
;
158 virtual void SAL_CALL
getFastPropertyValue( css::uno::Any
& rValue
, sal_Int32 nHandle
) const override
;
160 // css::sdb::XCompletedConnection
161 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
connectWithCompletion( const css::uno::Reference
< css::task::XInteractionHandler
>& handler
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
163 // css::sdbc::XDataSource
164 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection( const OUString
& user
, const OUString
& password
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
165 virtual void SAL_CALL
setLoginTimeout( sal_Int32 seconds
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
166 virtual sal_Int32 SAL_CALL
getLoginTimeout( ) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
168 //::css::sdb::XBookmarksSupplier
169 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getBookmarks( ) throw (css::uno::RuntimeException
, std::exception
) override
;
171 //::css::sdb::XQueryDefinitionsSupplier
172 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getQueryDefinitions( ) throw(css::uno::RuntimeException
, std::exception
) override
;
174 // css::sdbc::XIsolatedConnection
175 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getIsolatedConnection( const OUString
& user
, const OUString
& password
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
176 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getIsolatedConnectionWithCompletion( const css::uno::Reference
< css::task::XInteractionHandler
>& handler
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
) override
;
179 virtual void SAL_CALL
flush( ) throw (css::uno::RuntimeException
, std::exception
) override
;
180 virtual void SAL_CALL
addFlushListener( const css::uno::Reference
< css::util::XFlushListener
>& l
) throw (css::uno::RuntimeException
, std::exception
) override
;
181 virtual void SAL_CALL
removeFlushListener( const css::uno::Reference
< css::util::XFlushListener
>& l
) throw (css::uno::RuntimeException
, std::exception
) override
;
184 virtual void SAL_CALL
flushed( const css::lang::EventObject
& rEvent
) throw (css::uno::RuntimeException
, std::exception
) override
;
186 // XDocumentDataSource
187 virtual css::uno::Reference
< css::sdb::XOfficeDatabaseDocument
> SAL_CALL
getDatabaseDocument() throw (css::uno::RuntimeException
, std::exception
) override
;
190 // ModelDependentComponent overridables
191 virtual css::uno::Reference
< css::uno::XInterface
> getThis() const override
;
195 /** open a connection for the current settings. this is the simple connection we get from the driver
196 manager, so it can be used as a master for a "high level" sdb connection.
198 css::uno::Reference
< css::sdbc::XConnection
> buildLowLevelConnection(
199 const OUString
& _rUid
, const OUString
& _rPwd
202 css::uno::Reference
< css::sdbc::XConnection
> buildIsolatedConnection(
203 const OUString
& user
, const OUString
& password
206 /// @throws css::sdbc::SQLException
207 /// @throws css::uno::RuntimeException
208 css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection( const OUString
& user
, const OUString
& password
, bool _bIsolated
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
);
209 /// @throws css::sdbc::SQLException
210 /// @throws css::uno::RuntimeException
211 css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
connectWithCompletion( const css::uno::Reference
< css::task::XInteractionHandler
>& handler
, bool _bIsolated
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
);
214 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
217 } // namespace dbaccess
219 #endif // _DBA_COREDATAACCESS_DATALINK_HXX_
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */