LibreOffice Module connectivity (master) 1
ZPoolCollection.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
21#include <sal/config.h>
22
23#include <map>
24
27#include <com/sun/star/beans/XPropertyChangeListener.hpp>
28#include <com/sun/star/sdbc/XDriver.hpp>
29#include <com/sun/star/sdbc/XDriverManager2.hpp>
30#include <com/sun/star/sdbc/XConnectionPool.hpp>
31#include <com/sun/star/sdbc/XConnection.hpp>
32#include <com/sun/star/lang/XMultiServiceFactory.hpp>
33#include <com/sun/star/lang/XServiceInfo.hpp>
34#include <com/sun/star/uno/XComponentContext.hpp>
35#include <com/sun/star/frame/XDesktop2.hpp>
36#include <com/sun/star/frame/XTerminateListener.hpp>
37#include <com/sun/star/reflection/XProxyFactory.hpp>
38#include <osl/mutex.hxx>
39#include <rtl/ref.hxx>
40
41namespace connectivity
42{
43 class OConnectionPool;
44
45 // OPoolCollection - the one-instance service for PooledConnections
46 // manages the active connections and the connections in the pool
47
48 typedef ::cppu::WeakImplHelper< css::sdbc::XConnectionPool,
49 css::lang::XServiceInfo,
50 css::frame::XTerminateListener,
51 css::beans::XPropertyChangeListener
53
56 {
57
58
59 typedef std::map<OUString, rtl::Reference<OConnectionPool>> OConnectionPools;
60
61 typedef std::map<
62 css::uno::Reference< css::sdbc::XDriver >,
63 css::uno::WeakReference< css::sdbc::XDriver >>
65
67 ::osl::Mutex m_aMutex;
68 OConnectionPools m_aPools; // the driver pools
69 css::uno::Reference< css::uno::XComponentContext > m_xContext;
70 css::uno::Reference< css::sdbc::XDriverManager2 > m_xManager;
71 css::uno::Reference< css::reflection::XProxyFactory > m_xProxyFactory;
72 css::uno::Reference< css::uno::XInterface > m_xConfigNode; // config node for general connection pooling
73 css::uno::Reference< css::frame::XDesktop2> m_xDesktop;
74
75 public:
77 int operator= (const OPoolCollection&) = delete;
78
80 const css::uno::Reference< css::uno::XComponentContext >& _rxContext);
81
82 private:
83 // some configuration helper methods
84 css::uno::Reference< css::uno::XInterface > const & getConfigPoolRoot();
85 static css::uno::Reference< css::uno::XInterface > createWithProvider( const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxConfProvider,
86 const OUString& _rPath);
87 static css::uno::Reference< css::uno::XInterface > openNode( const OUString& _rPath,
88 const css::uno::Reference< css::uno::XInterface >& _xTreeNode) noexcept;
89 bool isPoolingEnabled();
90 bool isDriverPoolingEnabled(std::u16string_view _sDriverImplName,
91 css::uno::Reference< css::uno::XInterface >& _rxDriverNode);
92 bool isPoolingEnabledByUrl( const OUString& _sUrl,
93 css::uno::Reference< css::sdbc::XDriver >& _rxDriver,
94 OUString& _rsImplName,
95 css::uno::Reference< css::uno::XInterface >& _rxDriverNode);
96
97 OConnectionPool* getConnectionPool( const OUString& _sImplName,
98 const css::uno::Reference< css::sdbc::XDriver >& _xDriver,
99 const css::uno::Reference< css::uno::XInterface >& _rxDriverNode);
100 void clearConnectionPools(bool _bDispose);
101 void clearDesktop();
102 protected:
103 virtual ~OPoolCollection() override;
104 public:
105
106 static css::uno::Any getNodeValue( const OUString& _rPath,
107 const css::uno::Reference< css::uno::XInterface>& _xTreeNode)noexcept;
108
109 // XDriverManager
110 virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( const OUString& url ) override;
111 virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnectionWithInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override;
112 virtual void SAL_CALL setLoginTimeout( sal_Int32 seconds ) override;
113 virtual sal_Int32 SAL_CALL getLoginTimeout( ) override;
114
115 //XDriverAccess
116 virtual css::uno::Reference< css::sdbc::XDriver > SAL_CALL getDriverByURL( const OUString& url ) override;
117 // XServiceInfo
118 virtual OUString SAL_CALL getImplementationName( ) override;
119 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
120 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
121
122 // XEventListener
123 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
124 // XPropertyChangeListener
125 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
126
127 // XTerminateListener
128 virtual void SAL_CALL queryTermination( const css::lang::EventObject& Event ) override;
129 virtual void SAL_CALL notifyTermination( const css::lang::EventObject& Event ) override;
130 };
131}
132
133/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OPoolCollection: control the whole connection pooling for oo.
css::uno::Reference< css::uno::XInterface > m_xConfigNode
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
static css::uno::Any getNodeValue(const OUString &_rPath, const css::uno::Reference< css::uno::XInterface > &_xTreeNode) noexcept
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &Event) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual void SAL_CALL setLoginTimeout(sal_Int32 seconds) override
virtual sal_Int32 SAL_CALL getLoginTimeout() override
OPoolCollection(const OPoolCollection &)=delete
MapDriver2DriverRef m_aDriverProxies
OConnectionPool * getConnectionPool(const OUString &_sImplName, const css::uno::Reference< css::sdbc::XDriver > &_xDriver, const css::uno::Reference< css::uno::XInterface > &_rxDriverNode)
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection(const OUString &url) override
virtual ~OPoolCollection() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
std::map< css::uno::Reference< css::sdbc::XDriver >, css::uno::WeakReference< css::sdbc::XDriver > > MapDriver2DriverRef
bool isPoolingEnabledByUrl(const OUString &_sUrl, css::uno::Reference< css::sdbc::XDriver > &_rxDriver, OUString &_rsImplName, css::uno::Reference< css::uno::XInterface > &_rxDriverNode)
bool isDriverPoolingEnabled(std::u16string_view _sDriverImplName, css::uno::Reference< css::uno::XInterface > &_rxDriverNode)
virtual OUString SAL_CALL getImplementationName() override
OPoolCollection(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
virtual void SAL_CALL queryTermination(const css::lang::EventObject &Event) override
static css::uno::Reference< css::uno::XInterface > openNode(const OUString &_rPath, const css::uno::Reference< css::uno::XInterface > &_xTreeNode) noexcept
virtual css::uno::Reference< css::sdbc::XDriver > SAL_CALL getDriverByURL(const OUString &url) override
css::uno::Reference< css::sdbc::XDriverManager2 > m_xManager
void clearConnectionPools(bool _bDispose)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
static css::uno::Reference< css::uno::XInterface > createWithProvider(const css::uno::Reference< css::lang::XMultiServiceFactory > &_rxConfProvider, const OUString &_rPath)
css::uno::Reference< css::uno::XInterface > const & getConfigPoolRoot()
int operator=(const OPoolCollection &)=delete
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnectionWithInfo(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
css::uno::Reference< css::reflection::XProxyFactory > m_xProxyFactory
css::uno::Reference< css::frame::XDesktop2 > m_xDesktop
std::map< OUString, rtl::Reference< OConnectionPool > > OConnectionPools
::cppu::WeakImplHelper< css::sdbc::XConnectionPool, css::lang::XServiceInfo, css::frame::XTerminateListener, css::beans::XPropertyChangeListener > OPoolCollection_Base
unsigned char sal_Bool