tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / connectivity / source / cpool / ZConnectionPool.hxx
blobc5938f133f3cdcde1ffdcd3b22ab237ab022ea40
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 #pragma once
20 #include <sal/config.h>
22 #include <map>
23 #include <mutex>
24 #include <vector>
26 #include <com/sun/star/sdbc/XPooledConnection.hpp>
27 #include <com/sun/star/sdbc/XDriver.hpp>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
30 #include <com/sun/star/reflection/XProxyFactory.hpp>
31 #include <cppuhelper/implbase.hxx>
32 #include <osl/mutex.hxx>
33 #include <salhelper/timer.hxx>
34 #include <rtl/ref.hxx>
35 #include <rtl/digest.h>
37 namespace connectivity
39 class OConnectionPool;
41 /// OPoolTimer - Invalidates the connection pool
43 class OPoolTimer : public ::salhelper::Timer
45 OConnectionPool* m_pPool;
46 public:
47 OPoolTimer(OConnectionPool* _pPool,const ::salhelper::TTimeValue& Time)
48 : ::salhelper::Timer(Time)
49 ,m_pPool(_pPool)
51 protected:
52 virtual void SAL_CALL onShot() override;
56 // OConnectionPool - the one-instance service for PooledConnections
57 // manages the active connections and the connections in the pool
59 // typedef for the internal structure
60 typedef std::vector< css::uno::Reference< css::sdbc::XPooledConnection> > TPooledConnections;
62 // contains the currently pooled connections
63 struct TConnectionPool
65 TPooledConnections aConnections;
66 sal_Int32 nALiveCount; // will be decremented every time a time says to, when will reach zero the pool will be deleted
69 struct TDigestHolder
71 sal_uInt8 m_pBuffer[RTL_DIGEST_LENGTH_SHA1];
72 TDigestHolder()
74 m_pBuffer[0] = 0;
79 // typedef TDigestHolder
81 struct TDigestLess
83 bool operator() (const TDigestHolder& x, const TDigestHolder& y) const
85 sal_uInt32 i;
86 for(i=0;i < RTL_DIGEST_LENGTH_SHA1 && (x.m_pBuffer[i] >= y.m_pBuffer[i]); ++i)
88 return i < RTL_DIGEST_LENGTH_SHA1;
92 typedef std::map< TDigestHolder,TConnectionPool,TDigestLess> TConnectionMap;
94 // contains additional information about an activeconnection which is needed to put it back to the pool
95 struct TActiveConnectionInfo
97 TConnectionMap::iterator aPos;
98 css::uno::Reference< css::sdbc::XPooledConnection> xPooledConnection;
101 typedef std::map< css::uno::Reference< css::sdbc::XConnection>,
102 TActiveConnectionInfo> TActiveConnectionMap;
104 class OConnectionPool : public ::cppu::WeakImplHelper< css::beans::XPropertyChangeListener>
106 TConnectionMap m_aPool; // the pooled connections
107 TActiveConnectionMap m_aActiveConnections; // the currently active connections
109 std::mutex m_aMutex;
110 ::rtl::Reference<OPoolTimer> m_xInvalidator; // invalidates the connection pool when shot
112 css::uno::Reference< css::sdbc::XDriver > m_xDriver; // the one and only driver for this connectionpool
113 css::uno::Reference< css::uno::XInterface > m_xDriverNode; // config node entry
114 css::uno::Reference< css::reflection::XProxyFactory > m_xProxyFactory;
115 sal_Int32 m_nTimeOut;
116 sal_Int32 m_nALiveCount;
118 private:
119 css::uno::Reference< css::sdbc::XConnection> createNewConnection(const OUString& _rURL,
120 const css::uno::Sequence< css::beans::PropertyValue >& _rInfo);
121 css::uno::Reference< css::sdbc::XConnection> getPooledConnection(TConnectionMap::iterator const & _rIter);
122 // calculate the timeout and the corresponding ALiveCount
123 void calculateTimeOuts();
125 protected:
126 // the dtor will be called from the last instance (last release call)
127 virtual ~OConnectionPool() override;
128 public:
129 OConnectionPool(const css::uno::Reference< css::sdbc::XDriver >& _xDriver,
130 const css::uno::Reference< css::uno::XInterface >& _xDriverNode,
131 const css::uno::Reference< css::reflection::XProxyFactory >& _rxProxyFactory);
133 // delete all refs
134 void clear(bool _bDispose);
135 /// @throws css::sdbc::SQLException
136 /// @throws css::uno::RuntimeException
137 css::uno::Reference< css::sdbc::XConnection > getConnectionWithInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info );
138 // XEventListener
139 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
140 // XPropertyChangeListener
141 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
143 void invalidatePooledConnections();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */