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