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 #ifndef CONNECTIVITY_HSQLDB_DRIVER_HXX
28 #define CONNECTIVITY_HSQLDB_DRIVER_HXX
29 
30 #include <com/sun/star/sdbc/XDriver.hpp>
31 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
32 #include <com/sun/star/sdbcx/XCreateCatalog.hpp>
33 #include <com/sun/star/embed/XTransactionListener.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <cppuhelper/compbase5.hxx>
36 #include <comphelper/uno3.hxx>
37 #include <comphelper/stl_types.hxx>
38 #include <comphelper/broadcasthelper.hxx>
39 #include "connectivity/CommonTools.hxx"
40 
41 //........................................................................
42 namespace connectivity
43 {
44 //........................................................................
45 
46 	class OMetaConnection;
47 
48 	namespace hsqldb
49 	{
50 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ODriverDelegator_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception );
51 
52 		typedef ::cppu::WeakComponentImplHelper5<	::com::sun::star::sdbc::XDriver
53 										,::com::sun::star::sdbcx::XDataDefinitionSupplier
54 										, ::com::sun::star::lang::XServiceInfo
55 										, ::com::sun::star::sdbcx::XCreateCatalog
56                                         , ::com::sun::star::embed::XTransactionListener
57 										>	ODriverDelegator_BASE;
58 
59         typedef ::std::pair< ::com::sun::star::uno::WeakReferenceHelper,::com::sun::star::uno::WeakReferenceHelper> TWeakRefPair;
60 		typedef ::std::pair< ::rtl::OUString ,TWeakRefPair > TWeakConnectionPair;
61 
62 		typedef ::std::pair< ::com::sun::star::uno::WeakReferenceHelper,TWeakConnectionPair> TWeakPair;
63 		typedef ::std::vector< TWeakPair > TWeakPairVector;
64 
65 
66 		/** delegates all calls to the orignal driver and extend the existing one with the SDBCX layer.
67 
68 		*/
69 		class ODriverDelegator : public ::comphelper::OBaseMutex
70 								,public ODriverDelegator_BASE
71 		{
72 			TWeakPairVector														m_aConnections;	//	vector containing a list
73 																								//  of all the Connection objects
74 																								//  for this Driver
75 			::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >					m_xDriver;
76 			::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >	m_xFactory;
77             sal_Bool                                                                            m_bInShutDownConnections;
78 
79 			/** load the driver we want to delegate.
80 				The <member>m_xDriver</member> may be <NULL/> if the driver could not be loaded.
81 				@return
82 					The driver which was currently selected.
83 			*/
84 			::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > loadDriver( );
85 
86             /** shut down the connection and revoke the storage from the map
87                 @param  _aIter
88                     The connection to shut down and storage to revoke.
89             */
90             void shutdownConnection(const TWeakPairVector::iterator& _aIter);
91 
92 		public:
93 			/** creates a new delegator for a HSQLDB driver
94 			*/
95 			ODriverDelegator(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory);
96 
97 			// XServiceInfo
98 			DECLARE_SERVICE_INFO();
99 			static ::rtl::OUString getImplementationName_Static(  ) throw(::com::sun::star::uno::RuntimeException);
100             static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(  ) throw (::com::sun::star::uno::RuntimeException);
101 
102 			// XDriver
103 			virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL connect( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
104 			virtual sal_Bool SAL_CALL acceptsURL( const ::rtl::OUString& url ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
105 			virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
106 			virtual sal_Int32 SAL_CALL getMajorVersion(  ) throw (::com::sun::star::uno::RuntimeException);
107 			virtual sal_Int32 SAL_CALL getMinorVersion(  ) throw (::com::sun::star::uno::RuntimeException);
108 
109 			// XDataDefinitionSupplier
110 			virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
111 			virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
112 
113 			// XCreateCatalog
114 			virtual void SAL_CALL createCatalog( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
115 
116 			// XEventListener
117 			virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
118 
119             // XTransactionListener
120             virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
121             virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
122             virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
123             virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
124 
125             void shutdownConnections();
126             void flushConnections();
127 		protected:
128 			/// dtor
129 			virtual ~ODriverDelegator();
130 			// OComponentHelper
131 			virtual void SAL_CALL disposing(void);
132 
133             /** called when we connected to a newly created embedded database
134             */
135             void onConnectedNewDatabase(
136                 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection
137             );
138 		};
139 	}
140 
141 //........................................................................
142 }	// namespace connectivity
143 //........................................................................
144 #endif // CONNECTIVITY_HSQLDB_DRIVER_HXX
145 
146