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