1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DBA_COREDATAACCESS_DATASOURCE_HXX_
25 #define _DBA_COREDATAACCESS_DATASOURCE_HXX_
26 
27 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_
28 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
29 #endif
30 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #endif
33 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
34 #include <com/sun/star/sdbc/XDataSource.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERLISTENER_HPP_
37 #include <com/sun/star/container/XContainerListener.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_SDB_XBOOKMARKSSUPPLIER_HPP_
40 #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_
43 #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_SDBC_XISOLATEDCONNECTION_HPP_
46 #include <com/sun/star/sdbc/XIsolatedConnection.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
49 #include <com/sun/star/util/XNumberFormatter.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTLISTENER_HPP_
52 #include <com/sun/star/document/XEventListener.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_UTIL_XFLUSHABLE_HPP_
55 #include <com/sun/star/util/XFlushable.hpp>
56 #endif
57 #ifndef _CPPUHELPER_PROPSHLP_HXX
58 #include <cppuhelper/propshlp.hxx>
59 #endif
60 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_
61 #include <comphelper/proparrhlp.hxx>
62 #endif
63 #ifndef _CPPUHELPER_WEAKREF_HXX_
64 #include <cppuhelper/weakref.hxx>
65 #endif
66 #ifndef _CPPUHELPER_COMPBASE11_HXX_
67 #include <cppuhelper/compbase11.hxx>
68 #endif
69 #ifndef _COM_SUN_STAR_EMBED_XTRANSACTIONLISTENER_HPP_
70 #include <com/sun/star/embed/XTransactionListener.hpp>
71 #endif
72 #ifndef _DBASHARED_APITOOLS_HXX_
73 #include "apitools.hxx"
74 #endif
75 #ifndef _DBA_CORE_BOOKMARKCONTAINER_HXX_
76 #include "bookmarkcontainer.hxx"
77 #endif
78 #ifndef _VOS_REF_HXX_
79 #include <vos/ref.hxx>
80 #endif
81 #ifndef _STRING_HXX
82 #include <tools/string.hxx>
83 #endif
84 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
85 #include <connectivity/CommonTools.hxx>
86 #endif
87 #ifndef _COMPHELPER_BROADCASTHELPER_HXX_
88 #include <comphelper/broadcasthelper.hxx>
89 #endif
90 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
91 #include <com/sun/star/beans/PropertyAttribute.hpp>
92 #endif
93 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
94 #include <com/sun/star/beans/PropertyValue.hpp>
95 #endif
96 #ifndef _COM_SUN_STAR_SDB_XCOMPLETEDCONNECTION_HPP_
97 #include <com/sun/star/sdb/XCompletedConnection.hpp>
98 #endif
99 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
100 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
101 #endif
102 #ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
103 #include <com/sun/star/embed/XStorage.hpp>
104 #endif
105 #ifndef DBA_CONTENTHELPER_HXX
106 #include "ContentHelper.hxx"
107 #endif
108 #ifndef _COM_SUN_STAR_DOCUMENT_XSTORAGEBASEDDOCUMENT_HPP_
109 #include <com/sun/star/document/XStorageBasedDocument.hpp>
110 #endif
111 #ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
112 #include <com/sun/star/embed/ElementModes.hpp>
113 #endif
114 #ifndef _COM_SUN_STAR_UTIL_XREFRESHABLE_HPP_
115 #include <com/sun/star/util/XRefreshable.hpp>
116 #endif
117 #ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
118 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
119 #endif
120 #ifndef _DBA_COREDATAACCESS_MODELIMPL_HXX_
121 #include "ModelImpl.hxx"
122 #endif
123 
124 //........................................................................
125 namespace dbaccess
126 {
127 //........................................................................
128 
129 class OSharedConnectionManager;
130 class OChildCommitListen_Impl;
131 
132 //============================================================
133 //= ODatabaseSource
134 //============================================================
135 typedef ::cppu::WeakComponentImplHelper11   <   ::com::sun::star::lang::XServiceInfo
136                                             ,   ::com::sun::star::sdbc::XDataSource
137                                             ,   ::com::sun::star::sdb::XBookmarksSupplier
138                                             ,   ::com::sun::star::sdb::XQueryDefinitionsSupplier
139                                             ,   ::com::sun::star::sdb::XCompletedConnection
140                                             ,   ::com::sun::star::container::XContainerListener
141                                             ,   ::com::sun::star::sdbc::XIsolatedConnection
142                                             ,   ::com::sun::star::sdbcx::XTablesSupplier
143                                             ,   ::com::sun::star::util::XFlushable
144                                             ,   ::com::sun::star::util::XFlushListener
145                                             ,   ::com::sun::star::sdb::XDocumentDataSource
146                                             >   ODatabaseSource_Base;
147 
148 
149 class ODatabaseSource   :public ModelDependentComponent // must be first
150 					    ,public ODatabaseSource_Base
151 					    ,public ::cppu::OPropertySetHelper
152 					    ,public ::comphelper::OPropertyArrayUsageHelper < ODatabaseSource >
153 {
154 	friend class ODatabaseContext;
155 	friend class OConnection;
156 	friend class OSharedConnectionManager;
157 
158 private:
159     using ODatabaseSource_Base::rBHelper;
160     OBookmarkContainer				        m_aBookmarks;
161     ::cppu::OInterfaceContainerHelper		m_aFlushListeners;
162 
163 private:
164 	virtual ~ODatabaseSource();
165 
166 public:
167 	ODatabaseSource( const ::rtl::Reference< ODatabaseModelImpl >& _pImpl );
168 
DBContextAccessdbaccess::ODatabaseSource::DBContextAccess169     struct DBContextAccess { friend class ODatabaseContext; private: DBContextAccess() { } };
170 
171     /** sets a new name for the data source
172 
173         The name of a data source (our m_sName member) is the registration name, *if* the
174         data source actually *is* registered at the database context.
175 
176         Normally, this name is passed at time of creation of the ODatabaseModelImpl instance,
177         but if a newly creaed data source is registered, then it must be possible to propagate
178         the new trgistration name.
179     */
180     static void setName(
181             const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDocumentDataSource >& _rxDocument,
182             const ::rtl::OUString& _rNewName,
183             DBContextAccess
184         );
185 
186     // XContainerListener
187 	virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
188     virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
189     virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
190 	// ::com::sun::star::sdbcx::XTablesSupplier
191 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables(  ) throw(::com::sun::star::uno::RuntimeException);
192 
193 // com::sun::star::lang::XTypeProvider
194 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
195 	virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
196 
197 // com::sun::star::uno::XInterface
198 	virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException);
199     virtual void SAL_CALL acquire() throw( );
200     virtual void SAL_CALL release() throw( );
201 
202 // ::com::sun::star::lang::XServiceInfo
203     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
204     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
205     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
206 
207 // ::com::sun::star::lang::XServiceInfo - static methods
208 	static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException );
209 	static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException );
210 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
211 		SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
212 
213 // OComponentHelper
214 	virtual void SAL_CALL disposing(void);
215 
216 // com::sun::star::beans::XPropertySet
217 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
218 	// XEventListener
219 	virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
220 
221 // comphelper::OPropertyArrayUsageHelper
222 	virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
223 
224 // cppu::OPropertySetHelper
225 	virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
226 
227 	virtual sal_Bool SAL_CALL convertFastPropertyValue(
228 							::com::sun::star::uno::Any & rConvertedValue,
229 							::com::sun::star::uno::Any & rOldValue,
230 							sal_Int32 nHandle,
231 							const ::com::sun::star::uno::Any& rValue )
232 								throw (::com::sun::star::lang::IllegalArgumentException);
233 	virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
234 								sal_Int32 nHandle,
235 								const ::com::sun::star::uno::Any& rValue
236 												 )
237 												 throw (::com::sun::star::uno::Exception);
238 	virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
239 
240 // ::com::sun::star::sdb::XCompletedConnection
241     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL connectWithCompletion( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& handler ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
242 
243 // ::com::sun::star::sdbc::XDataSource
244 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( const ::rtl::OUString& user, const ::rtl::OUString& password ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
245 	virtual void SAL_CALL setLoginTimeout( sal_Int32 seconds ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
246     virtual sal_Int32 SAL_CALL getLoginTimeout(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
247 
248 // :: com::sun::star::sdb::XBookmarksSupplier
249     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getBookmarks(  ) throw (::com::sun::star::uno::RuntimeException);
250 
251 // :: com::sun::star::sdb::XQueryDefinitionsSupplier
252     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getQueryDefinitions(  ) throw(::com::sun::star::uno::RuntimeException);
253 
254 // ::com::sun::star::sdbc::XIsolatedConnection
255 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getIsolatedConnection( const ::rtl::OUString& user, const ::rtl::OUString& password ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
256 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getIsolatedConnectionWithCompletion( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& handler ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
257 
258 // XFlushable
259 	virtual void SAL_CALL flush(  ) throw (::com::sun::star::uno::RuntimeException);
260     virtual void SAL_CALL addFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
261     virtual void SAL_CALL removeFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
262 
263     // XFlushListener
264     virtual void SAL_CALL flushed( const ::com::sun::star::lang::EventObject& rEvent ) throw (::com::sun::star::uno::RuntimeException);
265 
266     // XDocumentDataSource
267     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XOfficeDatabaseDocument > SAL_CALL getDatabaseDocument() throw (::com::sun::star::uno::RuntimeException);
268 
269 protected:
270     // ModelDependentComponent overridables
271     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis() const;
272 
273 private:
274 // helper
275 	/** open a connection for the current settings. this is the simple connection we get from the driver
276 		manager, so it can be used as a master for a "high level" sdb connection.
277 	*/
278 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > buildLowLevelConnection(
279 		const ::rtl::OUString& _rUid, const ::rtl::OUString& _rPwd
280 		);
281 
282 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > buildIsolatedConnection(
283 		const rtl::OUString& user, const rtl::OUString& password
284 		);
285 
286 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( const ::rtl::OUString& user, const ::rtl::OUString& password , sal_Bool _bIsolated) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
287 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL connectWithCompletion( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& handler , sal_Bool _bIsolated) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
288 
289 	void clearConnections();
290 
291 protected:
292     using ::cppu::OPropertySetHelper::getFastPropertyValue;
293 };
294 
295 //........................................................................
296 }	// namespace dbaccess
297 //........................................................................
298 
299 #endif // _DBA_COREDATAACCESS_DATALINK_HXX_
300 
301 
302