LibreOffice Module connectivity (master) 1
ZConnectionPool.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#pragma once
20#include <sal/config.h>
21
22#include <map>
23#include <mutex>
24#include <vector>
25
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>
32#include <osl/mutex.hxx>
33#include <salhelper/timer.hxx>
34#include <rtl/ref.hxx>
35#include <rtl/digest.h>
36
37namespace connectivity
38{
39 class OConnectionPool;
40
42
44 {
46 public:
47 OPoolTimer(OConnectionPool* _pPool,const ::salhelper::TTimeValue& Time)
48 : ::salhelper::Timer(Time)
49 ,m_pPool(_pPool)
50 {}
51 protected:
52 virtual void SAL_CALL onShot() override;
53 };
54
55
56 // OConnectionPool - the one-instance service for PooledConnections
57 // manages the active connections and the connections in the pool
58
59 // typedef for the internal structure
60 typedef std::vector< css::uno::Reference< css::sdbc::XPooledConnection> > TPooledConnections;
61
62 // contains the currently pooled connections
64 {
66 sal_Int32 nALiveCount; // will be decremented every time a time says to, when will reach zero the pool will be deleted
67 };
68
70 {
71 sal_uInt8 m_pBuffer[RTL_DIGEST_LENGTH_SHA1];
73 {
74 m_pBuffer[0] = 0;
75 }
76
77 };
78
79 // typedef TDigestHolder
80
82 {
83 bool operator() (const TDigestHolder& x, const TDigestHolder& y) const
84 {
85 sal_uInt32 i;
86 for(i=0;i < RTL_DIGEST_LENGTH_SHA1 && (x.m_pBuffer[i] >= y.m_pBuffer[i]); ++i)
87 ;
88 return i < RTL_DIGEST_LENGTH_SHA1;
89 }
90 };
91
92 typedef std::map< TDigestHolder,TConnectionPool,TDigestLess> TConnectionMap;
93
94 // contains additional information about an activeconnection which is needed to put it back to the pool
96 {
97 TConnectionMap::iterator aPos;
98 css::uno::Reference< css::sdbc::XPooledConnection> xPooledConnection;
99 };
100
101 typedef std::map< css::uno::Reference< css::sdbc::XConnection>,
103
104 class OConnectionPool : public ::cppu::WeakImplHelper< css::beans::XPropertyChangeListener>
105 {
106 TConnectionMap m_aPool; // the pooled connections
107 TActiveConnectionMap m_aActiveConnections; // the currently active connections
108
109 std::mutex m_aMutex;
110 ::rtl::Reference<OPoolTimer> m_xInvalidator; // invalidates the conntection pool when shot
111
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;
117
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();
124
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);
132
133 // delete all refs
134 void clear(bool _bDispose);
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;
142
144 };
145}
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::rtl::Reference< OPoolTimer > m_xInvalidator
css::uno::Reference< css::sdbc::XConnection > getConnectionWithInfo(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info)
css::uno::Reference< css::sdbc::XDriver > m_xDriver
css::uno::Reference< css::sdbc::XConnection > createNewConnection(const OUString &_rURL, const css::uno::Sequence< css::beans::PropertyValue > &_rInfo)
css::uno::Reference< css::uno::XInterface > m_xDriverNode
css::uno::Reference< css::reflection::XProxyFactory > m_xProxyFactory
OConnectionPool(const css::uno::Reference< css::sdbc::XDriver > &_xDriver, const css::uno::Reference< css::uno::XInterface > &_xDriverNode, const css::uno::Reference< css::reflection::XProxyFactory > &_rxProxyFactory)
TActiveConnectionMap m_aActiveConnections
virtual ~OConnectionPool() override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
css::uno::Reference< css::sdbc::XConnection > getPooledConnection(TConnectionMap::iterator const &_rIter)
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
OPoolTimer - Invalidates the connection pool.
virtual void SAL_CALL onShot() override
OPoolTimer(OConnectionPool *_pPool, const ::salhelper::TTimeValue &Time)
OConnectionPool * m_pPool
float y
float x
std::vector< css::uno::Reference< css::sdbc::XPooledConnection > > TPooledConnections
std::map< css::uno::Reference< css::sdbc::XConnection >, TActiveConnectionInfo > TActiveConnectionMap
std::map< TDigestHolder, TConnectionPool, TDigestLess > TConnectionMap
int i
css::uno::Reference< css::sdbc::XPooledConnection > xPooledConnection
sal_uInt8 m_pBuffer[RTL_DIGEST_LENGTH_SHA1]
bool operator()(const TDigestHolder &x, const TDigestHolder &y) const
unsigned char sal_uInt8