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 .
19 #ifndef INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLCOLLECTION_HXX
20 #define INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLCOLLECTION_HXX
22 #include <sal/config.h>
26 #include <cppuhelper/implbase.hxx>
27 #include <cppuhelper/weakref.hxx>
28 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
29 #include <com/sun/star/sdbc/XDriver.hpp>
30 #include <com/sun/star/sdbc/XDriverManager2.hpp>
31 #include <com/sun/star/sdbc/XConnectionPool.hpp>
32 #include <com/sun/star/sdbc/XPooledConnection.hpp>
33 #include <com/sun/star/sdbc/XConnection.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/lang/XEventListener.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/frame/XDesktop2.hpp>
39 #include <com/sun/star/frame/XTerminateListener.hpp>
40 #include <com/sun/star/reflection/XProxyFactory.hpp>
41 #include <osl/mutex.hxx>
42 #include <rtl/ref.hxx>
44 namespace connectivity
46 class OConnectionPool
;
48 // OPoolCollection - the one-instance service for PooledConnections
49 // manages the active connections and the connections in the pool
51 typedef ::cppu::WeakImplHelper
< css::sdbc::XConnectionPool
,
52 css::lang::XServiceInfo
,
53 css::frame::XTerminateListener
,
54 css::beans::XPropertyChangeListener
55 > OPoolCollection_Base
;
57 /// OPoolCollection: control the whole connection pooling for oo
58 class OPoolCollection
: public OPoolCollection_Base
62 typedef std::map
<OUString
, rtl::Reference
<OConnectionPool
>> OConnectionPools
;
65 css::uno::Reference
< css::sdbc::XDriver
>,
66 css::uno::WeakReference
< css::sdbc::XDriver
>>
69 MapDriver2DriverRef m_aDriverProxies
;
70 ::osl::Mutex m_aMutex
;
71 OConnectionPools m_aPools
; // the driver pools
72 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
73 css::uno::Reference
< css::sdbc::XDriverManager2
> m_xManager
;
74 css::uno::Reference
< css::reflection::XProxyFactory
> m_xProxyFactory
;
75 css::uno::Reference
< css::uno::XInterface
> m_xConfigNode
; // config node for general connection pooling
76 css::uno::Reference
< css::frame::XDesktop2
> m_xDesktop
;
79 OPoolCollection(const OPoolCollection
&) = delete;
80 int operator= (const OPoolCollection
&) = delete;
82 explicit OPoolCollection(
83 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
85 // some configuration helper methods
86 css::uno::Reference
< css::uno::XInterface
> const & getConfigPoolRoot();
87 static css::uno::Reference
< css::uno::XInterface
> createWithProvider( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& _rxConfProvider
,
88 const OUString
& _rPath
);
89 static css::uno::Reference
< css::uno::XInterface
> openNode( const OUString
& _rPath
,
90 const css::uno::Reference
< css::uno::XInterface
>& _xTreeNode
) throw();
91 bool isPoolingEnabled();
92 bool isDriverPoolingEnabled(const OUString
& _sDriverImplName
,
93 css::uno::Reference
< css::uno::XInterface
>& _rxDriverNode
);
94 bool isPoolingEnabledByUrl( const OUString
& _sUrl
,
95 css::uno::Reference
< css::sdbc::XDriver
>& _rxDriver
,
96 OUString
& _rsImplName
,
97 css::uno::Reference
< css::uno::XInterface
>& _rxDriverNode
);
99 OConnectionPool
* getConnectionPool( const OUString
& _sImplName
,
100 const css::uno::Reference
< css::sdbc::XDriver
>& _xDriver
,
101 const css::uno::Reference
< css::uno::XInterface
>& _rxDriverNode
);
102 void clearConnectionPools(bool _bDispose
);
105 virtual ~OPoolCollection() override
;
108 static css::uno::Any
getNodeValue( const OUString
& _rPath
,
109 const css::uno::Reference
< css::uno::XInterface
>& _xTreeNode
)throw();
112 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection( const OUString
& url
) override
;
113 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnectionWithInfo( const OUString
& url
, const css::uno::Sequence
< css::beans::PropertyValue
>& info
) override
;
114 virtual void SAL_CALL
setLoginTimeout( sal_Int32 seconds
) override
;
115 virtual sal_Int32 SAL_CALL
getLoginTimeout( ) override
;
118 virtual css::uno::Reference
< css::sdbc::XDriver
> SAL_CALL
getDriverByURL( const OUString
& url
) override
;
120 virtual OUString SAL_CALL
getImplementationName( ) override
;
121 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
122 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
124 // XServiceInfo - static methods
125 static css::uno::Reference
< css::uno::XInterface
> CreateInstance(const css::uno::Reference
< css::lang::XMultiServiceFactory
>&);
126 /// @throws css::uno::RuntimeException
127 static OUString
getImplementationName_Static( );
128 /// @throws css::uno::RuntimeException
129 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static( );
132 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
133 // XPropertyChangeListener
134 virtual void SAL_CALL
propertyChange( const css::beans::PropertyChangeEvent
& evt
) override
;
136 // XTerminateListener
137 virtual void SAL_CALL
queryTermination( const css::lang::EventObject
& Event
) override
;
138 virtual void SAL_CALL
notifyTermination( const css::lang::EventObject
& Event
) override
;
141 #endif // INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLCOLLECTION_HXX
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */