LCOV - code coverage report
Current view: top level - connectivity/source/cpool - ZConnectionPool.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 14 0.0 %
Date: 2014-04-14 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #ifndef _CONNECTIVITY_ZCONNECTIONPOOL_HXX_
      20             : #define _CONNECTIVITY_ZCONNECTIONPOOL_HXX_
      21             : 
      22             : #include <sal/config.h>
      23             : 
      24             : #include <map>
      25             : #include <vector>
      26             : 
      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/implbase1.hxx>
      35             : #include <osl/mutex.hxx>
      36             : #include <salhelper/timer.hxx>
      37             : #include <rtl/ref.hxx>
      38             : #include <rtl/digest.h>
      39             : 
      40             : namespace connectivity
      41             : {
      42             :     class OConnectionPool;
      43             : 
      44             :     /// OPoolTimer - Invalidates the connection pool
      45             : 
      46           0 :     class OPoolTimer : public ::salhelper::Timer
      47             :     {
      48             :         OConnectionPool* m_pPool;
      49             :     public:
      50           0 :         OPoolTimer(OConnectionPool* _pPool,const ::salhelper::TTimeValue& _Time)
      51             :             : ::salhelper::Timer(_Time)
      52           0 :             ,m_pPool(_pPool)
      53           0 :         {}
      54             :     protected:
      55             :         virtual void SAL_CALL onShot() SAL_OVERRIDE;
      56             :     };
      57             : 
      58             : 
      59             :     //= OConnectionPool - the one-instance service for PooledConnections
      60             :     //= manages the active connections and the connections in the pool
      61             : 
      62             :     typedef ::cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertyChangeListener>  OConnectionPool_Base;
      63             : 
      64             :     // typedef for the interanl structure
      65             :     typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPooledConnection> > TPooledConnections;
      66             : 
      67             :      // contains the currently pooled connections
      68             :     typedef struct
      69           0 :     {
      70             :         TPooledConnections  aConnections;
      71             :         sal_Int32           nALiveCount; // will be decremented everytime a time says to, when will reach zero the pool will be deleted
      72           0 :     } TConnectionPool;
      73             : 
      74             :     struct TDigestHolder
      75             :     {
      76             :         sal_uInt8 m_pBuffer[RTL_DIGEST_LENGTH_SHA1];
      77           0 :         TDigestHolder()
      78             :         {
      79           0 :             m_pBuffer[0] = 0;
      80           0 :         }
      81             : 
      82             :     };
      83             : 
      84             :     //  typedef TDigestHolder
      85             : 
      86             :     struct TDigestLess : public ::std::binary_function< TDigestHolder, TDigestHolder, bool>
      87             :     {
      88           0 :         bool operator() (const TDigestHolder& x, const TDigestHolder& y) const
      89             :         {
      90             :             sal_uInt32 i;
      91           0 :             for(i=0;i < RTL_DIGEST_LENGTH_SHA1 && (x.m_pBuffer[i] >= y.m_pBuffer[i]); ++i)
      92             :                 ;
      93           0 :             return i < RTL_DIGEST_LENGTH_SHA1;
      94             :         }
      95             :     };
      96             : 
      97             :     typedef ::std::map< TDigestHolder,TConnectionPool,TDigestLess> TConnectionMap;
      98             : 
      99             :     // contains additional information about a activeconnection which is needed to put it back to the pool
     100             :     typedef struct
     101           0 :     {
     102             :         TConnectionMap::iterator aPos;
     103             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPooledConnection> xPooledConnection;
     104           0 :     } TActiveConnectionInfo;
     105             : 
     106             :     typedef ::std::map< ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>,
     107             :                         TActiveConnectionInfo> TActiveConnectionMap;
     108             : 
     109             :     class OConnectionPool : public OConnectionPool_Base
     110             :     {
     111             :         TConnectionMap          m_aPool;                // the pooled connections
     112             :         TActiveConnectionMap    m_aActiveConnections;   // the currently active connections
     113             : 
     114             :         ::osl::Mutex            m_aMutex;
     115             :         ::rtl::Reference<OPoolTimer>    m_xInvalidator;         // invalidates the conntection pool when shot
     116             : 
     117             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >             m_xDriver;      // the one and only driver for this connectionpool
     118             :         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >           m_xDriverNode;  // config node entry
     119             :         ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XProxyFactory > m_xProxyFactory;
     120             :         sal_Int32               m_nTimeOut;
     121             :         sal_Int32               m_nALiveCount;
     122             : 
     123             :     private:
     124             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> createNewConnection(const OUString& _rURL,
     125             :                                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo);
     126             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getPooledConnection(TConnectionMap::iterator& _rIter);
     127             :         // calculate the timeout and the corresponding ALiveCount
     128             :         void calculateTimeOuts();
     129             : 
     130             :     protected:
     131             :         // the dtor will be called from the last instance  (last release call)
     132             :         virtual ~OConnectionPool();
     133             :     public:
     134             :         OConnectionPool(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >& _xDriver,
     135             :                         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xDriverNode,
     136             :                         const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XProxyFactory >& _rxProxyFactory);
     137             : 
     138             :         // delete all refs
     139             :         void clear(sal_Bool _bDispose);
     140             :         ::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);
     141             :         // XEventListener
     142             :         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     143             :         // XPropertyChangeListener
     144             :         virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     145             : 
     146             :         void invalidatePooledConnections();
     147             :     };
     148             : }
     149             : #endif // _CONNECTIVITY_ZCONNECTIONPOOL_HXX_
     150             : 
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10