LibreOffice Module connectivity (master) 1
ZPooledConnection.cxx
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
20#include "ZPooledConnection.hxx"
22#include <comphelper/types.hxx>
23
24using namespace ::com::sun::star::uno;
25using namespace ::com::sun::star::lang;
26using namespace ::com::sun::star::sdbc;
27using namespace ::com::sun::star::container;
28using namespace ::com::sun::star::reflection;
29using namespace connectivity;
30using namespace ::osl;
31
32OPooledConnection::OPooledConnection(const Reference< XConnection >& _xConnection,
33 const Reference< css::reflection::XProxyFactory >& _rxProxyFactory)
35 ,m_xRealConnection(_xConnection)
36 ,m_xProxyFactory(_rxProxyFactory)
37{
38
39}
40
41// OComponentHelper
43{
44 MutexGuard aGuard(m_aMutex);
45 if (m_xComponent.is())
46 m_xComponent->removeEventListener(this);
47 m_xComponent.clear();
48 ::comphelper::disposeComponent(m_xRealConnection);
49}
50
51// XEventListener
52void SAL_CALL OPooledConnection::disposing( const EventObject& /*Source*/ )
53{
54m_xComponent.clear();
55}
56
57//XPooledConnection
58Reference< XConnection > OPooledConnection::getConnection()
59{
60 if(!m_xComponent.is() && m_xRealConnection.is())
61 {
62 Reference< XAggregation > xConProxy = m_xProxyFactory->createProxy(m_xRealConnection);
63 m_xComponent = new OConnectionWeakWrapper(xConProxy);
64 // register as event listener for the new connection
65 if (m_xComponent.is())
66 m_xComponent->addEventListener(this);
67 }
68 return Reference< XConnection >(m_xComponent,UNO_QUERY);
69}
70
71
72/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::lang::XComponent > m_xComponent
css::uno::Reference< css::sdbc::XConnection > m_xRealConnection
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection() override
css::uno::Reference< css::reflection::XProxyFactory > m_xProxyFactory
virtual void SAL_CALL disposing() override
mutable::osl::Mutex m_aMutex
std::mutex m_aMutex
::cppu::WeakComponentImplHelper< css::sdbc::XPooledConnection,css::lang::XEventListener > OPooledConnection_Base