1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: HDriver.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CONNECTIVITY_HSQLDB_DRIVER_HXX
31 #define CONNECTIVITY_HSQLDB_DRIVER_HXX
33 #include <com/sun/star/sdbc/XDriver.hpp>
34 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
35 #include <com/sun/star/sdbcx/XCreateCatalog.hpp>
36 #include <com/sun/star/embed/XTransactionListener.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <cppuhelper/compbase5.hxx>
39 #include <comphelper/uno3.hxx>
40 #include <comphelper/stl_types.hxx>
41 #include <comphelper/broadcasthelper.hxx>
42 #include "connectivity/CommonTools.hxx"
44 //........................................................................
45 namespace connectivity
47 //........................................................................
49 class OMetaConnection
;
53 ::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
);
55 typedef ::cppu::WeakComponentImplHelper5
< ::com::sun::star::sdbc::XDriver
56 ,::com::sun::star::sdbcx::XDataDefinitionSupplier
57 , ::com::sun::star::lang::XServiceInfo
58 , ::com::sun::star::sdbcx::XCreateCatalog
59 , ::com::sun::star::embed::XTransactionListener
60 > ODriverDelegator_BASE
;
62 typedef ::std::pair
< ::com::sun::star::uno::WeakReferenceHelper
,::com::sun::star::uno::WeakReferenceHelper
> TWeakRefPair
;
63 typedef ::std::pair
< ::rtl::OUString
,TWeakRefPair
> TWeakConnectionPair
;
65 typedef ::std::pair
< ::com::sun::star::uno::WeakReferenceHelper
,TWeakConnectionPair
> TWeakPair
;
66 typedef ::std::vector
< TWeakPair
> TWeakPairVector
;
69 /** delegates all calls to the orignal driver and extend the existing one with the SDBCX layer.
72 class ODriverDelegator
: public ::comphelper::OBaseMutex
73 ,public ODriverDelegator_BASE
75 TWeakPairVector m_aConnections
; // vector containing a list
76 // of all the Connection objects
78 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
> m_xDriver
;
79 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> m_xFactory
;
80 sal_Bool m_bInShutDownConnections
;
82 /** load the driver we want to delegate.
83 The <member>m_xDriver</member> may be <NULL/> if the driver could not be loaded.
85 The driver which was currently selected.
87 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
> loadDriver( );
89 /** shut down the connection and revoke the storage from the map
91 The connection to shut down and storage to revoke.
93 void shutdownConnection(const TWeakPairVector::iterator
& _aIter
);
96 /** creates a new delegator for a HSQLDB driver
98 ODriverDelegator(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
);
101 DECLARE_SERVICE_INFO();
102 static ::rtl::OUString
getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException
);
103 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException
);
106 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
);
107 virtual sal_Bool SAL_CALL
acceptsURL( const ::rtl::OUString
& url
) throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
108 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
);
109 virtual sal_Int32 SAL_CALL
getMajorVersion( ) throw (::com::sun::star::uno::RuntimeException
);
110 virtual sal_Int32 SAL_CALL
getMinorVersion( ) throw (::com::sun::star::uno::RuntimeException
);
112 // XDataDefinitionSupplier
113 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
);
114 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
);
117 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
);
120 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
);
122 // XTransactionListener
123 virtual void SAL_CALL
preCommit( const ::com::sun::star::lang::EventObject
& aEvent
) throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
124 virtual void SAL_CALL
commited( const ::com::sun::star::lang::EventObject
& aEvent
) throw (::com::sun::star::uno::RuntimeException
);
125 virtual void SAL_CALL
preRevert( const ::com::sun::star::lang::EventObject
& aEvent
) throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
126 virtual void SAL_CALL
reverted( const ::com::sun::star::lang::EventObject
& aEvent
) throw (::com::sun::star::uno::RuntimeException
);
128 void shutdownConnections();
131 virtual ~ODriverDelegator();
133 virtual void SAL_CALL
disposing(void);
135 /** called when we connected to a newly created embedded database
137 void onConnectedNewDatabase(
138 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _rxConnection
143 //........................................................................
144 } // namespace connectivity
145 //........................................................................
146 #endif // CONNECTIVITY_HSQLDB_DRIVER_HXX