bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / cpool / ZConnectionPool.hxx
blob5f87cee16baa5470121c086013ddf6b4700d4cb8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_ZCONNECTIONPOOL_HXX
20 #define INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZCONNECTIONPOOL_HXX
22 #include <sal/config.h>
24 #include <map>
25 #include <vector>
27 #include <com/sun/star/lang/XEventListener.hpp>
28 #include <com/sun/star/sdbc/XPooledConnection.hpp>
29 #include <com/sun/star/sdbc/XDriver.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
32 #include <com/sun/star/reflection/XProxyFactory.hpp>
33 #include <cppuhelper/weakref.hxx>
34 #include <cppuhelper/implbase.hxx>
35 #include <osl/mutex.hxx>
36 #include <salhelper/timer.hxx>
37 #include <rtl/ref.hxx>
38 #include <rtl/digest.h>
40 namespace connectivity
42 class OConnectionPool;
44 /// OPoolTimer - Invalidates the connection pool
46 class OPoolTimer : public ::salhelper::Timer
48 OConnectionPool* m_pPool;
49 public:
50 OPoolTimer(OConnectionPool* _pPool,const ::salhelper::TTimeValue& Time)
51 : ::salhelper::Timer(Time)
52 ,m_pPool(_pPool)
54 protected:
55 virtual void SAL_CALL onShot() override;
59 // OConnectionPool - the one-instance service for PooledConnections
60 // manages the active connections and the connections in the pool
62 // typedef for the internal structure
63 typedef std::vector< css::uno::Reference< css::sdbc::XPooledConnection> > TPooledConnections;
65 // contains the currently pooled connections
66 typedef struct
68 TPooledConnections aConnections;
69 sal_Int32 nALiveCount; // will be decremented every time a time says to, when will reach zero the pool will be deleted
70 } TConnectionPool;
72 struct TDigestHolder
74 sal_uInt8 m_pBuffer[RTL_DIGEST_LENGTH_SHA1];
75 TDigestHolder()
77 m_pBuffer[0] = 0;
82 // typedef TDigestHolder
84 struct TDigestLess
86 bool operator() (const TDigestHolder& x, const TDigestHolder& y) const
88 sal_uInt32 i;
89 for(i=0;i < RTL_DIGEST_LENGTH_SHA1 && (x.m_pBuffer[i] >= y.m_pBuffer[i]); ++i)
91 return i < RTL_DIGEST_LENGTH_SHA1;
95 typedef std::map< TDigestHolder,TConnectionPool,TDigestLess> TConnectionMap;
97 // contains additional information about an activeconnection which is needed to put it back to the pool
98 typedef struct
100 TConnectionMap::iterator aPos;
101 css::uno::Reference< css::sdbc::XPooledConnection> xPooledConnection;
102 } TActiveConnectionInfo;
104 typedef std::map< css::uno::Reference< css::sdbc::XConnection>,
105 TActiveConnectionInfo> TActiveConnectionMap;
107 class OConnectionPool : public ::cppu::WeakImplHelper< css::beans::XPropertyChangeListener>
109 TConnectionMap m_aPool; // the pooled connections
110 TActiveConnectionMap m_aActiveConnections; // the currently active connections
112 ::osl::Mutex m_aMutex;
113 ::rtl::Reference<OPoolTimer> m_xInvalidator; // invalidates the conntection pool when shot
115 css::uno::Reference< css::sdbc::XDriver > m_xDriver; // the one and only driver for this connectionpool
116 css::uno::Reference< css::uno::XInterface > m_xDriverNode; // config node entry
117 css::uno::Reference< css::reflection::XProxyFactory > m_xProxyFactory;
118 sal_Int32 m_nTimeOut;
119 sal_Int32 m_nALiveCount;
121 private:
122 css::uno::Reference< css::sdbc::XConnection> createNewConnection(const OUString& _rURL,
123 const css::uno::Sequence< css::beans::PropertyValue >& _rInfo);
124 css::uno::Reference< css::sdbc::XConnection> getPooledConnection(TConnectionMap::iterator const & _rIter);
125 // calculate the timeout and the corresponding ALiveCount
126 void calculateTimeOuts();
128 protected:
129 // the dtor will be called from the last instance (last release call)
130 virtual ~OConnectionPool() override;
131 public:
132 OConnectionPool(const css::uno::Reference< css::sdbc::XDriver >& _xDriver,
133 const css::uno::Reference< css::uno::XInterface >& _xDriverNode,
134 const css::uno::Reference< css::reflection::XProxyFactory >& _rxProxyFactory);
136 // delete all refs
137 void clear(bool _bDispose);
138 /// @throws css::sdbc::SQLException
139 /// @throws css::uno::RuntimeException
140 css::uno::Reference< css::sdbc::XConnection > getConnectionWithInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info );
141 // XEventListener
142 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
143 // XPropertyChangeListener
144 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
146 void invalidatePooledConnections();
149 #endif // INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZCONNECTIONPOOL_HXX
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */