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/implbase4.hxx>
27 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
28 #include <com/sun/star/sdbc/XDriver.hpp>
29 #include <com/sun/star/sdbc/XDriverManager2.hpp>
30 #include <com/sun/star/sdbc/XConnectionPool.hpp>
31 #include <com/sun/star/sdbc/XPooledConnection.hpp>
32 #include <com/sun/star/sdbc/XConnection.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/lang/XEventListener.hpp>
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <com/sun/star/frame/XDesktop2.hpp>
38 #include <com/sun/star/frame/XTerminateListener.hpp>
39 #include <com/sun/star/reflection/XProxyFactory.hpp>
40 #include <comphelper/stl_types.hxx>
41 #include <osl/mutex.hxx>
43 namespace connectivity
45 class OConnectionPool
;
47 // OPoolCollection - the one-instance service for PooledConnections
48 // manages the active connections and the connections in the pool
50 typedef ::cppu::WeakImplHelper4
< ::com::sun::star::sdbc::XConnectionPool
,
51 ::com::sun::star::lang::XServiceInfo
,
52 ::com::sun::star::frame::XTerminateListener
,
53 ::com::sun::star::beans::XPropertyChangeListener
54 > OPoolCollection_Base
;
56 /// OPoolCollection: control the whole connection pooling for oo
57 class OPoolCollection
: public OPoolCollection_Base
61 typedef ::comphelper::OInterfaceCompare
< ::com::sun::star::sdbc::XDriver
> ODriverCompare
;
62 typedef std::map
<OUString
, OConnectionPool
*> OConnectionPools
;
65 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
>,
66 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XDriver
>,
70 MapDriver2DriverRef m_aDriverProxies
;
71 ::osl::Mutex m_aMutex
;
72 OConnectionPools m_aPools
; // the driver pools
73 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
74 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriverManager2
> m_xManager
;
75 ::com::sun::star::uno::Reference
< ::com::sun::star::reflection::XProxyFactory
> m_xProxyFactory
;
76 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xConfigNode
; // config node for general connection pooling
77 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDesktop2
> m_xDesktop
;
80 OPoolCollection(const OPoolCollection
&) SAL_DELETED_FUNCTION
;
81 int operator= (const OPoolCollection
&) SAL_DELETED_FUNCTION
;
84 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
86 // some configuration helper methods
87 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> createWithServiceFactory(const OUString
& _rPath
) const;
88 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> getConfigPoolRoot();
89 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> createWithProvider( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxConfProvider
,
90 const OUString
& _rPath
);
91 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> openNode( const OUString
& _rPath
,
92 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xTreeNode
) throw();
93 bool isPoolingEnabled();
94 bool isDriverPoolingEnabled(const OUString
& _sDriverImplName
,
95 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxDriverNode
);
96 bool isPoolingEnabledByUrl( const OUString
& _sUrl
,
97 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
>& _rxDriver
,
98 OUString
& _rsImplName
,
99 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxDriverNode
);
101 OConnectionPool
* getConnectionPool( const OUString
& _sImplName
,
102 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
>& _xDriver
,
103 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxDriverNode
);
104 void clearConnectionPools(bool _bDispose
);
107 virtual ~OPoolCollection();
110 static ::com::sun::star::uno::Any
getNodeValue( const OUString
& _rPath
,
111 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xTreeNode
)throw();
114 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
> SAL_CALL
getConnection( const OUString
& url
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
115 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
> SAL_CALL
getConnectionWithInfo( const 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
, std::exception
) SAL_OVERRIDE
;
116 virtual void SAL_CALL
setLoginTimeout( sal_Int32 seconds
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
117 virtual sal_Int32 SAL_CALL
getLoginTimeout( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
120 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
> SAL_CALL
getDriverByURL( const OUString
& url
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
122 virtual OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
124 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
126 // XServiceInfo - static methods
127 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
CreateInstance(const::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&);
128 static OUString SAL_CALL
getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException
);
129 static ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException
);
132 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
133 // XPropertyChangeListener
134 virtual void SAL_CALL
propertyChange( const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
136 // XTerminateListener
137 virtual void SAL_CALL
queryTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
138 virtual void SAL_CALL
notifyTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
141 #endif // INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLCOLLECTION_HXX
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */