/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
OPoolCollection::OPoolCollection(const Reference< XComponentContext >& _rxContext)
:m_xContext(_rxContext)
{ // bootstrap all objects supporting the .sdb.Driver service
m_xManager = DriverManager::create( m_xContext );
m_xProxyFactory = ProxyFactory::create( m_xContext );
Reference<XPropertySet> xProp(getConfigPoolRoot(),UNO_QUERY); if ( xProp.is() )
xProp->addPropertyChangeListener(ENABLE_POOLING,this); // attach as desktop listener to know when we have to release our pools
osl_atomic_increment( &m_refCount );
{
Reference< XDriver > SAL_CALL OPoolCollection::getDriverByURL( const OUString& _rURL )
{ // returns the original driver when no connection pooling is enabled else it returns the proxy
MutexGuard aGuard(m_aMutex);
Reference< XDriver > xDriver;
Reference< XInterface > xDriverNode;
OUString sImplName; if(isPoolingEnabledByUrl(_rURL,xDriver,sImplName,xDriverNode))
{
Reference< XDriver > xExistentProxy; // look if we already have a proxy for this driver for (constauto& [rxDriver, rxDriverRef] : m_aDriverProxies)
{ // hold the proxy alive as long as we're in this loop round
xExistentProxy = rxDriverRef;
if (xExistentProxy.is() && (rxDriver.get() == xDriver.get())) // already created a proxy for this break;
} if (xExistentProxy.is())
{
xDriver = std::move(xExistentProxy);
} else
{ // create a new proxy for the driver // this allows us to control the connections created by it
Reference< XAggregation > xDriverProxy = m_xProxyFactory->createProxy(xDriver);
OSL_ENSURE(xDriverProxy.is(), "OConnectionPool::getDriverByURL: invalid proxy returned by the proxy factory!");
bool OPoolCollection::isDriverPoolingEnabled(std::u16string_view _sDriverImplName,
Reference< XInterface >& _rxDriverNode)
{ bool bEnabled = false;
Reference<XInterface> xConnectionPoolRoot = getConfigPoolRoot(); // then look for which of them settings are stored in the configuration
Reference< XNameAccess > xDirectAccess(openNode(DRIVER_SETTINGS,xConnectionPoolRoot),UNO_QUERY);
if(xDirectAccess.is())
{ for (auto& driverKey : xDirectAccess->getElementNames())
{ // the name of the driver in this round if (_sDriverImplName == driverKey)
{
_rxDriverNode = openNode(driverKey, xDirectAccess); if(_rxDriverNode.is())
getNodeValue(ENABLE,_rxDriverNode) >>= bEnabled; break;
}
}
} return bEnabled;
}
bool OPoolCollection::isPoolingEnabled()
{ // the config node where all pooling relevant info are stored under
Reference<XInterface> xConnectionPoolRoot = getConfigPoolRoot();
// the global "enabled" flag bool bEnabled = false; if(xConnectionPoolRoot.is())
getNodeValue(ENABLE_POOLING,xConnectionPoolRoot) >>= bEnabled; return bEnabled;
}
bool OPoolCollection::isPoolingEnabledByUrl(const OUString& _sUrl,
Reference< XDriver >& _rxDriver,
OUString& _rsImplName,
Reference< XInterface >& _rxDriverNode)
{ bool bEnabled = false;
_rxDriver = m_xManager->getDriverByURL(_sUrl); if (_rxDriver.is() && isPoolingEnabled())
{
Reference< XServiceInfo > xServiceInfo(_rxDriver,UNO_QUERY);
OSL_ENSURE(xServiceInfo.is(),"Each driver should have a XServiceInfo interface!");
if(xServiceInfo.is())
{ // look for the implementation name of the driver
_rsImplName = xServiceInfo->getImplementationName();
bEnabled = isDriverPoolingEnabled(_rsImplName,_rxDriverNode);
}
} return bEnabled;
}
try
{ if (xDirectAccess.is() && xDirectAccess->hasByName(_rPath))
{
xNode.set(xDirectAccess->getByName(_rPath), css::uno::UNO_QUERY);
SAL_WARN_IF(
!xNode.is(), "connectivity.cpool", "OConfigurationNode::openNode: could not open the node!");
} elseif (xHierarchyAccess.is())
{
xNode.set(
xHierarchyAccess->getByHierarchicalName(_rPath),
css::uno::UNO_QUERY);
SAL_WARN_IF(
!xNode.is(), "connectivity.cpool", "OConfigurationNode::openNode: could not open the node!");
}
} catch(const NoSuchElementException&)
{
SAL_WARN("connectivity.cpool", "::openNode: there is no element named " <<
_rPath << "!");
} catch(const Exception&)
{
TOOLS_WARN_EXCEPTION("connectivity.cpool", "OConfigurationNode::openNode: caught an exception while retrieving the node");
} return xNode;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.