1*caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*caf5cd79SAndrew Rist * distributed with this work for additional information 6*caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9*caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10*caf5cd79SAndrew Rist * 11*caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*caf5cd79SAndrew Rist * 13*caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15*caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17*caf5cd79SAndrew Rist * specific language governing permissions and limitations 18*caf5cd79SAndrew Rist * under the License. 19*caf5cd79SAndrew Rist * 20*caf5cd79SAndrew Rist *************************************************************/ 21*caf5cd79SAndrew Rist 22*caf5cd79SAndrew Rist 23cdf0e10cSrcweir #ifndef CONNECTIVITY_HSQLDB_DRIVER_HXX 24cdf0e10cSrcweir #define CONNECTIVITY_HSQLDB_DRIVER_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriver.hpp> 27cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> 28cdf0e10cSrcweir #include <com/sun/star/sdbcx/XCreateCatalog.hpp> 29cdf0e10cSrcweir #include <com/sun/star/embed/XTransactionListener.hpp> 30cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 31cdf0e10cSrcweir #include <cppuhelper/compbase5.hxx> 32cdf0e10cSrcweir #include <comphelper/uno3.hxx> 33cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 34cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx> 35cdf0e10cSrcweir #include "connectivity/CommonTools.hxx" 36cdf0e10cSrcweir 37cdf0e10cSrcweir //........................................................................ 38cdf0e10cSrcweir namespace connectivity 39cdf0e10cSrcweir { 40cdf0e10cSrcweir //........................................................................ 41cdf0e10cSrcweir 42cdf0e10cSrcweir class OMetaConnection; 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace hsqldb 45cdf0e10cSrcweir { 46cdf0e10cSrcweir ::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 ); 47cdf0e10cSrcweir 48cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper5< ::com::sun::star::sdbc::XDriver 49cdf0e10cSrcweir ,::com::sun::star::sdbcx::XDataDefinitionSupplier 50cdf0e10cSrcweir , ::com::sun::star::lang::XServiceInfo 51cdf0e10cSrcweir , ::com::sun::star::sdbcx::XCreateCatalog 52cdf0e10cSrcweir , ::com::sun::star::embed::XTransactionListener 53cdf0e10cSrcweir > ODriverDelegator_BASE; 54cdf0e10cSrcweir 55cdf0e10cSrcweir typedef ::std::pair< ::com::sun::star::uno::WeakReferenceHelper,::com::sun::star::uno::WeakReferenceHelper> TWeakRefPair; 56cdf0e10cSrcweir typedef ::std::pair< ::rtl::OUString ,TWeakRefPair > TWeakConnectionPair; 57cdf0e10cSrcweir 58cdf0e10cSrcweir typedef ::std::pair< ::com::sun::star::uno::WeakReferenceHelper,TWeakConnectionPair> TWeakPair; 59cdf0e10cSrcweir typedef ::std::vector< TWeakPair > TWeakPairVector; 60cdf0e10cSrcweir 61cdf0e10cSrcweir 62cdf0e10cSrcweir /** delegates all calls to the orignal driver and extend the existing one with the SDBCX layer. 63cdf0e10cSrcweir 64cdf0e10cSrcweir */ 65cdf0e10cSrcweir class ODriverDelegator : public ::comphelper::OBaseMutex 66cdf0e10cSrcweir ,public ODriverDelegator_BASE 67cdf0e10cSrcweir { 68cdf0e10cSrcweir TWeakPairVector m_aConnections; // vector containing a list 69cdf0e10cSrcweir // of all the Connection objects 70cdf0e10cSrcweir // for this Driver 71cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > m_xDriver; 72cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; 73cdf0e10cSrcweir sal_Bool m_bInShutDownConnections; 74cdf0e10cSrcweir 75cdf0e10cSrcweir /** load the driver we want to delegate. 76cdf0e10cSrcweir The <member>m_xDriver</member> may be <NULL/> if the driver could not be loaded. 77cdf0e10cSrcweir @return 78cdf0e10cSrcweir The driver which was currently selected. 79cdf0e10cSrcweir */ 80cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > loadDriver( ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir /** shut down the connection and revoke the storage from the map 83cdf0e10cSrcweir @param _aIter 84cdf0e10cSrcweir The connection to shut down and storage to revoke. 85cdf0e10cSrcweir */ 86cdf0e10cSrcweir void shutdownConnection(const TWeakPairVector::iterator& _aIter); 87cdf0e10cSrcweir 88cdf0e10cSrcweir public: 89cdf0e10cSrcweir /** creates a new delegator for a HSQLDB driver 90cdf0e10cSrcweir */ 91cdf0e10cSrcweir ODriverDelegator(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); 92cdf0e10cSrcweir 93cdf0e10cSrcweir // XServiceInfo 94cdf0e10cSrcweir DECLARE_SERVICE_INFO(); 95cdf0e10cSrcweir static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException); 96cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException); 97cdf0e10cSrcweir 98cdf0e10cSrcweir // XDriver 99cdf0e10cSrcweir 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); 100cdf0e10cSrcweir virtual sal_Bool SAL_CALL acceptsURL( const ::rtl::OUString& url ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 101cdf0e10cSrcweir 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); 102cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getMajorVersion( ) throw (::com::sun::star::uno::RuntimeException); 103cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getMinorVersion( ) throw (::com::sun::star::uno::RuntimeException); 104cdf0e10cSrcweir 105cdf0e10cSrcweir // XDataDefinitionSupplier 106cdf0e10cSrcweir 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); 107cdf0e10cSrcweir 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); 108cdf0e10cSrcweir 109cdf0e10cSrcweir // XCreateCatalog 110cdf0e10cSrcweir 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); 111cdf0e10cSrcweir 112cdf0e10cSrcweir // XEventListener 113cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 114cdf0e10cSrcweir 115cdf0e10cSrcweir // XTransactionListener 116cdf0e10cSrcweir virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 117cdf0e10cSrcweir virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); 118cdf0e10cSrcweir virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 119cdf0e10cSrcweir virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); 120cdf0e10cSrcweir 121cdf0e10cSrcweir void shutdownConnections(); 122cdf0e10cSrcweir void flushConnections(); 123cdf0e10cSrcweir protected: 124cdf0e10cSrcweir /// dtor 125cdf0e10cSrcweir virtual ~ODriverDelegator(); 126cdf0e10cSrcweir // OComponentHelper 127cdf0e10cSrcweir virtual void SAL_CALL disposing(void); 128cdf0e10cSrcweir 129cdf0e10cSrcweir /** called when we connected to a newly created embedded database 130cdf0e10cSrcweir */ 131cdf0e10cSrcweir void onConnectedNewDatabase( 132cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection 133cdf0e10cSrcweir ); 134cdf0e10cSrcweir }; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir //........................................................................ 138cdf0e10cSrcweir } // namespace connectivity 139cdf0e10cSrcweir //........................................................................ 140cdf0e10cSrcweir #endif // CONNECTIVITY_HSQLDB_DRIVER_HXX 141cdf0e10cSrcweir 142