1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/sdbc/XDriver.hpp>
22 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
23 #include <com/sun/star/sdbcx/XCreateCatalog.hpp>
24 #include <com/sun/star/embed/XTransactionListener.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <cppuhelper/compbase.hxx>
28 #include <cppuhelper/basemutex.hxx>
29 #include <connectivity/CommonTools.hxx>
32 namespace connectivity::hsqldb
34 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XDriver
35 , css::sdbcx::XDataDefinitionSupplier
36 , css::lang::XServiceInfo
37 , css::sdbcx::XCreateCatalog
38 , css::embed::XTransactionListener
39 > ODriverDelegator_BASE
;
41 typedef std::pair
< css::uno::WeakReferenceHelper
,css::uno::WeakReferenceHelper
> TWeakRefPair
;
42 typedef std::pair
< OUString
,TWeakRefPair
> TWeakConnectionPair
;
44 typedef std::pair
< css::uno::WeakReferenceHelper
,TWeakConnectionPair
> TWeakPair
;
45 typedef std::vector
< TWeakPair
> TWeakPairVector
;
48 /** delegates all calls to the original driver and extend the existing one with the SDBCX layer.
51 class ODriverDelegator final
: public ::cppu::BaseMutex
52 ,public ODriverDelegator_BASE
54 TWeakPairVector m_aConnections
; // vector containing a list
55 // of all the Connection objects
57 css::uno::Reference
< css::sdbc::XDriver
> m_xDriver
;
58 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
59 bool m_bInShutDownConnections
;
61 /** load the driver we want to delegate.
62 The <member>m_xDriver</member> may be <NULL/> if the driver could not be loaded.
64 The driver which was currently selected.
66 css::uno::Reference
< css::sdbc::XDriver
> const & loadDriver( );
68 /** shut down the connection and revoke the storage from the map
70 The connection to shut down and storage to revoke.
72 void shutdownConnection(const TWeakPairVector::iterator
& _aIter
);
75 /** creates a new delegator for a HSQLDB driver
77 ODriverDelegator(const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
80 DECLARE_SERVICE_INFO();
83 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
connect( const OUString
& url
, const css::uno::Sequence
< css::beans::PropertyValue
>& info
) override
;
84 virtual sal_Bool SAL_CALL
acceptsURL( const OUString
& url
) override
;
85 virtual css::uno::Sequence
< css::sdbc::DriverPropertyInfo
> SAL_CALL
getPropertyInfo( const OUString
& url
, const css::uno::Sequence
< css::beans::PropertyValue
>& info
) override
;
86 virtual sal_Int32 SAL_CALL
getMajorVersion( ) override
;
87 virtual sal_Int32 SAL_CALL
getMinorVersion( ) override
;
89 // XDataDefinitionSupplier
90 virtual css::uno::Reference
< css::sdbcx::XTablesSupplier
> SAL_CALL
getDataDefinitionByConnection( const css::uno::Reference
< css::sdbc::XConnection
>& connection
) override
;
91 virtual css::uno::Reference
< css::sdbcx::XTablesSupplier
> SAL_CALL
getDataDefinitionByURL( const OUString
& url
, const css::uno::Sequence
< css::beans::PropertyValue
>& info
) override
;
94 virtual void SAL_CALL
createCatalog( const css::uno::Sequence
< css::beans::PropertyValue
>& info
) override
;
97 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
99 // XTransactionListener
100 virtual void SAL_CALL
preCommit( const css::lang::EventObject
& aEvent
) override
;
101 virtual void SAL_CALL
commited( const css::lang::EventObject
& aEvent
) override
;
102 virtual void SAL_CALL
preRevert( const css::lang::EventObject
& aEvent
) override
;
103 virtual void SAL_CALL
reverted( const css::lang::EventObject
& aEvent
) override
;
105 void shutdownConnections();
106 void flushConnections();
109 virtual ~ODriverDelegator() override
;
111 virtual void SAL_CALL
disposing() override
;
113 /** called when we connected to a newly created embedded database
115 void onConnectedNewDatabase(
116 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
121 } // namespace connectivity::hsqldb
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */