23#include <com/sun/star/configuration/theDefaultProvider.hpp>
24#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
25#include <com/sun/star/beans/NamedValue.hpp>
26#include <com/sun/star/beans/PropertyValue.hpp>
27#include <com/sun/star/frame/Desktop.hpp>
28#include <com/sun/star/reflection/ProxyFactory.hpp>
29#include <com/sun/star/sdbc/DriverManager.hpp>
31#include <com/sun/star/beans/XPropertySet.hpp>
32#include <osl/diagnose.h>
48 return "org.openoffice.Office.DataAccess/ConnectionPool";
53 return "EnablePooling";
63 return "DriverSettings";
72OPoolCollection::OPoolCollection(
const Reference< XComponentContext >& _rxContext)
76 m_xManager = DriverManager::create( m_xContext );
78 m_xProxyFactory = ProxyFactory::create( m_xContext );
80 Reference<XPropertySet> xProp(getConfigPoolRoot(),UNO_QUERY);
84 osl_atomic_increment( &m_refCount );
87 m_xDesktop = css::frame::Desktop::create( m_xContext );
91 osl_atomic_decrement( &m_refCount );
94OPoolCollection::~OPoolCollection()
107 Reference< XConnection > xConnection;
108 Reference< XDriver > xDriver;
109 Reference< XInterface > xDriverNode;
118 else if(xDriver.is())
119 xConnection = xDriver->connect(_rURL,_rInfo);
138 return "com.sun.star.sdbc.OConnectionPool";
149 return {
"com.sun.star.sdbc.ConnectionPool" };
157 Reference< XDriver > xDriver;
158 Reference< XInterface > xDriverNode;
162 Reference< XDriver > xExistentProxy;
167 xExistentProxy = rxDriverRef;
169 if (xExistentProxy.is() && (rxDriver.get() == xDriver.get()))
173 if (xExistentProxy.is())
175 xDriver = xExistentProxy;
180 Reference< XAggregation > xDriverProxy =
m_xProxyFactory->createProxy(xDriver);
181 OSL_ENSURE(xDriverProxy.is(),
"OConnectionPool::getDriverByURL: invalid proxy returned by the proxy factory!");
192 Reference< XInterface >& _rxDriverNode)
194 bool bEnabled =
false;
199 if(xDirectAccess.is())
201 Sequence< OUString > aDriverKeys = xDirectAccess->getElementNames();
202 const OUString* pDriverKeys = aDriverKeys.getConstArray();
203 const OUString* pDriverKeysEnd = pDriverKeys + aDriverKeys.getLength();
204 for (;pDriverKeys != pDriverKeysEnd; ++pDriverKeys)
207 if(_sDriverImplName == *pDriverKeys)
209 _rxDriverNode =
openNode(*pDriverKeys,xDirectAccess);
210 if(_rxDriverNode.is())
225 bool bEnabled =
false;
226 if(xConnectionPoolRoot.is())
235 css::configuration::theDefaultProvider::get(
m_xContext),
241 Reference< XDriver >& _rxDriver,
242 OUString& _rsImplName,
243 Reference< XInterface >& _rxDriverNode)
245 bool bEnabled =
false;
246 _rxDriver =
m_xManager->getDriverByURL(_sUrl);
249 Reference< XServiceInfo > xServiceInfo(_rxDriver,UNO_QUERY);
250 OSL_ENSURE(xServiceInfo.is(),
"Each driver should have a XServiceInfo interface!");
252 if(xServiceInfo.is())
255 _rsImplName = xServiceInfo->getImplementationName();
266 rEntry.second->clear(_bDispose);
272 const Reference< XDriver >& _xDriver,
273 const Reference< XInterface >& _xDriverNode)
276 OConnectionPools::const_iterator aFind =
m_aPools.find(_sImplName);
278 pRet = aFind->second.get();
279 else if (_xDriver.is() && _xDriverNode.is())
281 Reference<XPropertySet> xProp(_xDriverNode,UNO_QUERY);
285 m_aPools.emplace(_sImplName,pConnectionPool);
286 pRet = pConnectionPool.get();
289 OSL_ENSURE(pRet,
"Could not query DriverManager from ConnectionPool!");
295 const OUString& _rPath)
297 OSL_ASSERT(_rxConfProvider.is());
298 Sequence< Any >
args{
Any(NamedValue(
"nodepath",
Any(_rPath))) };
299 Reference< XInterface > xInterface(
300 _rxConfProvider->createInstanceWithArguments(
301 "com.sun.star.configuration.ConfigurationAccess",
305 "::createWithProvider: could not create the node access!");
311 Reference< XHierarchicalNameAccess > xHierarchyAccess(_xTreeNode, UNO_QUERY);
312 Reference< XNameAccess > xDirectAccess(_xTreeNode, UNO_QUERY);
313 Reference< XInterface > xNode;
317 if (xDirectAccess.is() && xDirectAccess->hasByName(_rPath))
319 xNode.set(xDirectAccess->getByName(_rPath), css::uno::UNO_QUERY);
321 !xNode.is(),
"connectivity.cpool",
322 "OConfigurationNode::openNode: could not open the node!");
324 else if (xHierarchyAccess.is())
327 xHierarchyAccess->getByHierarchicalName(_rPath),
328 css::uno::UNO_QUERY);
330 !xNode.is(),
"connectivity.cpool",
331 "OConfigurationNode::openNode: could not open the node!");
335 catch(
const NoSuchElementException&)
337 SAL_WARN(
"connectivity.cpool",
"::openNode: there is no element named " <<
342 TOOLS_WARN_EXCEPTION(
"connectivity.cpool",
"OConfigurationNode::openNode: caught an exception while retrieving the node");
349 Reference< XHierarchicalNameAccess > xHierarchyAccess(_xTreeNode, UNO_QUERY);
350 Reference< XNameAccess > xDirectAccess(_xTreeNode, UNO_QUERY);
354 if (xDirectAccess.is() && xDirectAccess->hasByName(_rPath) )
356 aReturn = xDirectAccess->getByName(_rPath);
358 else if (xHierarchyAccess.is())
360 aReturn = xHierarchyAccess->getByHierarchicalName(_rPath);
363 catch(
const NoSuchElementException&)
390 Reference<XPropertySet> xProp(
Source.Source,UNO_QUERY);
397 else if ( xProp.is() )
412 bool bEnabled =
true;
413 evt.NewValue >>= bEnabled;
421 else if(evt.Source.is())
423 bool bEnabled =
true;
424 evt.NewValue >>= bEnabled;
427 OUString sThisDriverName;
434 MapDriver2DriverRef::iterator aFind = aLookup;
435 Reference<XServiceInfo> xInfo(aLookup->first,UNO_QUERY);
437 if(xInfo.is() && xInfo->getImplementationName() == sThisDriverName)
442 OConnectionPools::iterator aFind =
m_aPools.find(sThisDriverName);
445 aFind->second->clear(
false);
460extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
462 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
Reference< XComponentContext > m_xContext
static OUString getEnableNodeName()
static OUString getDriverSettingsNodeName()
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * connectivity_OPoolCollection_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
static OUString getEnablePoolingNodeName()
static OUString getConnectionPoolNodeName()
static OUString getDriverNameNodeName()
css::uno::Reference< css::sdbc::XConnection > getConnectionWithInfo(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info)
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
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 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
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()
OConnectionPools m_aPools
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
Reference< XDesktop2 > m_xDesktop
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)