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

Generated by: LCOV version 1.10