Branch data 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 : :
20 : : #include "ZPoolCollection.hxx"
21 : : #include "ZDriverWrapper.hxx"
22 : : #include "ZConnectionPool.hxx"
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 <comphelper/extract.hxx>
28 : : #include <comphelper/processfactory.hxx>
29 : : #include <com/sun/star/beans/XPropertySet.hpp>
30 : : #include "diagnose_ex.h"
31 : :
32 : : using namespace ::com::sun::star::uno;
33 : : using namespace ::com::sun::star::lang;
34 : : using namespace ::com::sun::star::sdbc;
35 : : using namespace ::com::sun::star::beans;
36 : : using namespace ::com::sun::star::container;
37 : : using namespace ::com::sun::star::reflection;
38 : : using namespace ::osl;
39 : : using namespace connectivity;
40 : :
41 : : //--------------------------------------------------------------------
42 : 9 : static const ::rtl::OUString& getConnectionPoolNodeName()
43 : : {
44 [ + - ][ + - ]: 9 : static ::rtl::OUString s_sNodeName( "org.openoffice.Office.DataAccess/ConnectionPool" );
45 : 9 : return s_sNodeName;
46 : : }
47 : : //--------------------------------------------------------------------
48 : 121 : static const ::rtl::OUString& getEnablePoolingNodeName()
49 : : {
50 [ + + ][ + - ]: 121 : static ::rtl::OUString s_sNodeName( "EnablePooling" );
51 : 121 : return s_sNodeName;
52 : : }
53 : : //--------------------------------------------------------------------
54 : 0 : static const ::rtl::OUString& getDriverNameNodeName()
55 : : {
56 [ # # ][ # # ]: 0 : static ::rtl::OUString s_sNodeName( "DriverName" );
57 : 0 : return s_sNodeName;
58 : : }
59 : : // -----------------------------------------------------------------------------
60 : 0 : static const ::rtl::OUString& getDriverSettingsNodeName()
61 : : {
62 [ # # ][ # # ]: 0 : static ::rtl::OUString s_sNodeName( "DriverSettings" );
63 : 0 : return s_sNodeName;
64 : : }
65 : : //--------------------------------------------------------------------------
66 : 0 : static const ::rtl::OUString& getEnableNodeName()
67 : : {
68 [ # # ][ # # ]: 0 : static ::rtl::OUString s_sNodeName( "Enable" );
69 : 0 : return s_sNodeName;
70 : : }
71 : :
72 : : //--------------------------------------------------------------------
73 : 9 : OPoolCollection::OPoolCollection(const Reference< XMultiServiceFactory >& _rxFactory)
74 [ + - ][ + - ]: 9 : :m_xServiceFactory(_rxFactory)
[ + - ]
75 : : {
76 : : // bootstrap all objects supporting the .sdb.Driver service
77 [ + - ][ + - ]: 9 : m_xManager = Reference< XDriverManager >(m_xServiceFactory->createInstance(::rtl::OUString("com.sun.star.sdbc.DriverManager") ), UNO_QUERY);
[ + - ][ + - ]
78 [ + - ][ + - ]: 9 : m_xDriverAccess = Reference< XDriverAccess >(m_xManager, UNO_QUERY);
79 : : OSL_ENSURE(m_xDriverAccess.is(), "have no (or an invalid) driver manager!");
80 : :
81 : : m_xProxyFactory = Reference< XProxyFactory >(
82 [ + - ]: 9 : m_xServiceFactory->createInstance(
83 : 9 : ::rtl::OUString("com.sun.star.reflection.ProxyFactory")),
84 [ + - ][ + - ]: 9 : UNO_QUERY);
[ + - ]
85 : : OSL_ENSURE(m_xProxyFactory.is(), "OConnectionPool::OConnectionPool: could not create a proxy factory!");
86 : :
87 [ + - ][ + - ]: 9 : Reference<XPropertySet> xProp(getConfigPoolRoot(),UNO_QUERY);
88 [ + - ]: 9 : if ( xProp.is() )
89 [ + - ][ + - ]: 9 : xProp->addPropertyChangeListener(getEnablePoolingNodeName(),this);
[ + - ][ + - ]
90 : : // attach as desktop listener to know when we have to release our pools
91 [ + - ]: 9 : osl_incrementInterlockedCount( &m_refCount );
92 : : {
93 : :
94 [ + - ][ + - ]: 9 : m_xDesktop = Reference< ::com::sun::star::frame::XDesktop>( m_xServiceFactory->createInstance(::rtl::OUString("com.sun.star.frame.Desktop") ), UNO_QUERY);
[ + - ][ + - ]
95 [ + - ]: 9 : if ( m_xDesktop.is() )
96 [ + - ][ + - ]: 9 : m_xDesktop->addTerminateListener(this);
[ + - ]
97 : :
98 : : }
99 [ + - ]: 9 : osl_decrementInterlockedCount( &m_refCount );
100 : 9 : }
101 : : // -----------------------------------------------------------------------------
102 [ # # ]: 0 : OPoolCollection::~OPoolCollection()
103 : : {
104 [ # # ]: 0 : clearConnectionPools(sal_False);
105 [ # # ]: 0 : }
106 : : // -----------------------------------------------------------------------------
107 : 0 : Reference< XConnection > SAL_CALL OPoolCollection::getConnection( const ::rtl::OUString& _rURL ) throw(SQLException, RuntimeException)
108 : : {
109 [ # # ]: 0 : return getConnectionWithInfo(_rURL,Sequence< PropertyValue >());
110 : : }
111 : : // -----------------------------------------------------------------------------
112 : 56 : Reference< XConnection > SAL_CALL OPoolCollection::getConnectionWithInfo( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rInfo ) throw(SQLException, RuntimeException)
113 : : {
114 [ + - ]: 56 : MutexGuard aGuard(m_aMutex);
115 : 56 : Reference< XConnection > xConnection;
116 : 56 : Reference< XDriver > xDriver;
117 : 56 : Reference< XInterface > xDriverNode;
118 : 56 : ::rtl::OUString sImplName;
119 [ - + ][ # # ]: 56 : if(isPoolingEnabledByUrl(_rURL,xDriver,sImplName,xDriverNode) && xDriver.is())
[ - + ][ + - ]
120 : : {
121 [ # # ]: 0 : OConnectionPool* pConnectionPool = getConnectionPool(sImplName,xDriver,xDriverNode);
122 : :
123 [ # # ]: 0 : if(pConnectionPool)
124 [ # # ][ # # ]: 0 : xConnection = pConnectionPool->getConnectionWithInfo(_rURL,_rInfo);
125 : : }
126 [ + - ]: 56 : else if(xDriver.is())
127 [ + - ][ + - ]: 56 : xConnection = xDriver->connect(_rURL,_rInfo);
[ + - ]
128 : :
129 [ + - ]: 56 : return xConnection;
130 : : }
131 : : // -----------------------------------------------------------------------------
132 : 0 : void SAL_CALL OPoolCollection::setLoginTimeout( sal_Int32 seconds ) throw(RuntimeException)
133 : : {
134 [ # # ]: 0 : MutexGuard aGuard(m_aMutex);
135 [ # # ][ # # ]: 0 : m_xManager->setLoginTimeout(seconds);
[ # # ]
136 : 0 : }
137 : : // -----------------------------------------------------------------------------
138 : 0 : sal_Int32 SAL_CALL OPoolCollection::getLoginTimeout( ) throw(RuntimeException)
139 : : {
140 [ # # ]: 0 : MutexGuard aGuard(m_aMutex);
141 [ # # ][ # # ]: 0 : return m_xManager->getLoginTimeout();
[ # # ]
142 : : }
143 : : // -----------------------------------------------------------------------------
144 : 18 : ::rtl::OUString SAL_CALL OPoolCollection::getImplementationName( ) throw(RuntimeException)
145 : : {
146 [ + - ]: 18 : MutexGuard aGuard(m_aMutex);
147 [ + - ][ + - ]: 18 : return getImplementationName_Static();
148 : : }
149 : :
150 : : //--------------------------------------------------------------------------
151 : 0 : sal_Bool SAL_CALL OPoolCollection::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
152 : : {
153 [ # # ]: 0 : Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
154 : 0 : const ::rtl::OUString* pSupported = aSupported.getConstArray();
155 : 0 : const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
156 [ # # ][ # # ]: 0 : for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
[ # # ]
157 : : ;
158 : :
159 [ # # ]: 0 : return pSupported != pEnd;
160 : : }
161 : :
162 : : //--------------------------------------------------------------------------
163 : 0 : Sequence< ::rtl::OUString > SAL_CALL OPoolCollection::getSupportedServiceNames( ) throw(RuntimeException)
164 : : {
165 : 0 : return getSupportedServiceNames_Static();
166 : : }
167 : :
168 : : //---------------------------------------OPoolCollection----------------------------------
169 : 9 : Reference< XInterface > SAL_CALL OPoolCollection::CreateInstance(const Reference< XMultiServiceFactory >& _rxFactory)
170 : : {
171 [ + - ][ + - ]: 9 : return static_cast<XDriverManager*>(new OPoolCollection(_rxFactory));
172 : : }
173 : :
174 : : //--------------------------------------------------------------------------
175 : 36 : ::rtl::OUString SAL_CALL OPoolCollection::getImplementationName_Static( ) throw(RuntimeException)
176 : : {
177 : 36 : return ::rtl::OUString("com.sun.star.sdbc.OConnectionPool");
178 : : }
179 : :
180 : : //--------------------------------------------------------------------------
181 : 9 : Sequence< ::rtl::OUString > SAL_CALL OPoolCollection::getSupportedServiceNames_Static( ) throw(RuntimeException)
182 : : {
183 : 9 : Sequence< ::rtl::OUString > aSupported(1);
184 [ + - ]: 9 : aSupported[0] = ::rtl::OUString("com.sun.star.sdbc.ConnectionPool");
185 : 9 : return aSupported;
186 : : }
187 : : // -----------------------------------------------------------------------------
188 : 56 : Reference< XDriver > SAL_CALL OPoolCollection::getDriverByURL( const ::rtl::OUString& _rURL ) throw(RuntimeException)
189 : : {
190 : : // returns the original driver when no connection pooling is enabled else it returns the proxy
191 [ + - ]: 56 : MutexGuard aGuard(m_aMutex);
192 : :
193 : 56 : Reference< XDriver > xDriver;
194 : 56 : Reference< XInterface > xDriverNode;
195 : 56 : ::rtl::OUString sImplName;
196 [ - + ][ + - ]: 56 : if(isPoolingEnabledByUrl(_rURL,xDriver,sImplName,xDriverNode))
197 : : {
198 : 0 : Reference< XDriver > xExistentProxy;
199 : : // look if we already have a proxy for this driver
200 [ # # ]: 0 : for ( ConstMapDriver2DriverRefIterator aLookup = m_aDriverProxies.begin();
201 : 0 : aLookup != m_aDriverProxies.end();
202 : : ++aLookup
203 : : )
204 : : {
205 : : // hold the proxy alive as long as we're in this loop round
206 [ # # ][ # # ]: 0 : xExistentProxy = aLookup->second;
207 : :
208 [ # # ][ # # ]: 0 : if (xExistentProxy.is() && (aLookup->first.get() == xDriver.get()))
[ # # ][ # # ]
[ # # ]
209 : : // already created a proxy for this
210 : 0 : break;
211 : : }
212 [ # # ]: 0 : if (xExistentProxy.is())
213 : : {
214 [ # # ]: 0 : xDriver = xExistentProxy;
215 : : }
216 : : else
217 : : { // create a new proxy for the driver
218 : : // this allows us to control the connections created by it
219 [ # # ]: 0 : if (m_xProxyFactory.is())
220 : : {
221 [ # # ][ # # ]: 0 : Reference< XAggregation > xDriverProxy = m_xProxyFactory->createProxy(xDriver.get());
[ # # ][ # # ]
222 : : OSL_ENSURE(xDriverProxy.is(), "OConnectionPool::getDriverByURL: invalid proxy returned by the proxy factory!");
223 : :
224 [ # # ]: 0 : OConnectionPool* pConnectionPool = getConnectionPool(sImplName,xDriver,xDriverNode);
225 [ # # ][ # # ]: 0 : xDriver = new ODriverWrapper(xDriverProxy, pConnectionPool);
[ # # ]
226 : : }
227 : : else
228 : : OSL_FAIL("OConnectionPool::getDriverByURL: could not instantiate a proxy factory!");
229 : 0 : }
230 : : }
231 : :
232 [ + - ]: 56 : return xDriver;
233 : : }
234 : : // -----------------------------------------------------------------------------
235 : 0 : sal_Bool OPoolCollection::isDriverPoolingEnabled(const ::rtl::OUString& _sDriverImplName,
236 : : Reference< XInterface >& _rxDriverNode)
237 : : {
238 : 0 : sal_Bool bEnabled = sal_False;
239 [ # # ]: 0 : Reference<XInterface> xConnectionPoolRoot = getConfigPoolRoot();
240 : : // then look for which of them settings are stored in the configuration
241 [ # # ][ # # ]: 0 : Reference< XNameAccess > xDirectAccess(openNode(getDriverSettingsNodeName(),xConnectionPoolRoot),UNO_QUERY);
242 : :
243 [ # # ]: 0 : if(xDirectAccess.is())
244 : : {
245 [ # # ][ # # ]: 0 : Sequence< ::rtl::OUString > aDriverKeys = xDirectAccess->getElementNames();
246 : 0 : const ::rtl::OUString* pDriverKeys = aDriverKeys.getConstArray();
247 : 0 : const ::rtl::OUString* pDriverKeysEnd = pDriverKeys + aDriverKeys.getLength();
248 [ # # ]: 0 : for (;pDriverKeys != pDriverKeysEnd; ++pDriverKeys)
249 : : {
250 : : // the name of the driver in this round
251 [ # # ]: 0 : if(_sDriverImplName == *pDriverKeys)
252 : : {
253 [ # # ]: 0 : _rxDriverNode = openNode(*pDriverKeys,xDirectAccess);
254 [ # # ]: 0 : if(_rxDriverNode.is())
255 [ # # ]: 0 : getNodeValue(getEnableNodeName(),_rxDriverNode) >>= bEnabled;
256 : 0 : break;
257 : : }
258 [ # # ]: 0 : }
259 : : }
260 : 0 : return bEnabled;
261 : : }
262 : : // -----------------------------------------------------------------------------
263 : 112 : sal_Bool OPoolCollection::isPoolingEnabled()
264 : : {
265 : : // the config node where all pooling relevant info are stored under
266 [ + - ]: 112 : Reference<XInterface> xConnectionPoolRoot = getConfigPoolRoot();
267 : :
268 : : // the global "enabled" flag
269 : 112 : sal_Bool bEnabled = sal_False;
270 [ + - ]: 112 : if(xConnectionPoolRoot.is())
271 [ + - ]: 112 : getNodeValue(getEnablePoolingNodeName(),xConnectionPoolRoot) >>= bEnabled;
272 : 112 : return bEnabled;
273 : : }
274 : : // -----------------------------------------------------------------------------
275 : 121 : Reference<XInterface> OPoolCollection::getConfigPoolRoot()
276 : : {
277 [ + + ]: 121 : if(!m_xConfigNode.is())
278 [ + - ]: 9 : m_xConfigNode = createWithServiceFactory(getConnectionPoolNodeName());
279 : 121 : return m_xConfigNode;
280 : : }
281 : : // -----------------------------------------------------------------------------
282 : 112 : sal_Bool OPoolCollection::isPoolingEnabledByUrl(const ::rtl::OUString& _sUrl,
283 : : Reference< XDriver >& _rxDriver,
284 : : ::rtl::OUString& _rsImplName,
285 : : Reference< XInterface >& _rxDriverNode)
286 : : {
287 : 112 : sal_Bool bEnabled = sal_False;
288 [ + - ]: 112 : if (m_xDriverAccess.is())
289 : : {
290 [ + - ]: 112 : _rxDriver = m_xDriverAccess->getDriverByURL(_sUrl);
291 [ - + ][ - + ]: 112 : if (_rxDriver.is() && isPoolingEnabled())
[ + - ]
292 : : {
293 [ # # ]: 0 : Reference< XServiceInfo > xSerivceInfo(_rxDriver,UNO_QUERY);
294 : : OSL_ENSURE(xSerivceInfo.is(),"Each driver should have a XServiceInfo interface!");
295 : :
296 [ # # ]: 0 : if(xSerivceInfo.is())
297 : : {
298 : : // look for the implementation name of the driver
299 [ # # ][ # # ]: 0 : _rsImplName = xSerivceInfo->getImplementationName();
300 [ # # ]: 0 : bEnabled = isDriverPoolingEnabled(_rsImplName,_rxDriverNode);
301 : 0 : }
302 : : }
303 : : }
304 : 112 : return bEnabled;
305 : : }
306 : : // -----------------------------------------------------------------------------
307 : 9 : void OPoolCollection::clearConnectionPools(sal_Bool _bDispose)
308 : : {
309 : 9 : OConnectionPools::const_iterator aIter = m_aPools.begin();
310 [ - + ]: 9 : while(aIter != m_aPools.end())
311 : : {
312 [ # # ]: 0 : aIter->second->clear(_bDispose);
313 : 0 : aIter->second->release();
314 : 0 : ::rtl::OUString sKeyValue = aIter->first;
315 : 0 : ++aIter;
316 [ # # ]: 0 : m_aPools.erase(sKeyValue);
317 : 0 : }
318 : 9 : }
319 : : // -----------------------------------------------------------------------------
320 : 0 : OConnectionPool* OPoolCollection::getConnectionPool(const ::rtl::OUString& _sImplName,
321 : : const Reference< XDriver >& _xDriver,
322 : : const Reference< XInterface >& _xDriverNode)
323 : : {
324 : 0 : OConnectionPool *pRet = 0;
325 [ # # ]: 0 : OConnectionPools::const_iterator aFind = m_aPools.find(_sImplName);
326 [ # # ]: 0 : if (aFind != m_aPools.end())
327 : 0 : pRet = aFind->second;
328 [ # # ][ # # ]: 0 : else if (_xDriver.is() && _xDriverNode.is())
[ # # ]
329 : : {
330 [ # # ]: 0 : Reference<XPropertySet> xProp(_xDriverNode,UNO_QUERY);
331 [ # # ]: 0 : if(xProp.is())
332 [ # # ][ # # ]: 0 : xProp->addPropertyChangeListener(getEnableNodeName(),this);
[ # # ][ # # ]
333 [ # # ]: 0 : OConnectionPool* pConnectionPool = new OConnectionPool(_xDriver,_xDriverNode,m_xProxyFactory);
334 : 0 : pConnectionPool->acquire();
335 [ # # ]: 0 : aFind = m_aPools.insert(OConnectionPools::value_type(_sImplName,pConnectionPool)).first;
336 : 0 : pRet = aFind->second;
337 : : }
338 : :
339 : : OSL_ENSURE(pRet, "Could not query DriverManager from ConnectionPool!");
340 : :
341 : 0 : return pRet;
342 : : }
343 : : // -----------------------------------------------------------------------------
344 : 9 : Reference< XInterface > OPoolCollection::createWithServiceFactory(const ::rtl::OUString& _rPath) const
345 : : {
346 : : return createWithProvider(
347 : : com::sun::star::configuration::theDefaultProvider::get(
348 : : comphelper::getComponentContext(m_xServiceFactory)),
349 [ + - ][ + - ]: 9 : _rPath);
350 : : }
351 : : //------------------------------------------------------------------------
352 : 9 : Reference< XInterface > OPoolCollection::createWithProvider(const Reference< XMultiServiceFactory >& _rxConfProvider,
353 : : const ::rtl::OUString& _rPath) const
354 : : {
355 : : OSL_ASSERT(_rxConfProvider.is());
356 [ + - ]: 9 : Sequence< Any > args(1);
357 [ + - ]: 9 : args[0] = makeAny(
358 : : NamedValue(
359 : : rtl::OUString("nodepath"),
360 [ + - ][ + - ]: 18 : makeAny(_rPath)));
361 : : Reference< XInterface > xInterface(
362 [ + - ]: 9 : _rxConfProvider->createInstanceWithArguments(
363 : : rtl::OUString( "com.sun.star.configuration.ConfigurationAccess"),
364 [ + - ]: 9 : args));
365 : : OSL_ENSURE(
366 : : xInterface.is(),
367 : : "::createWithProvider: could not create the node access!");
368 [ + - ]: 9 : return xInterface;
369 : : }
370 : : // -----------------------------------------------------------------------------
371 : 0 : Reference<XInterface> OPoolCollection::openNode(const ::rtl::OUString& _rPath,const Reference<XInterface>& _xTreeNode) const throw()
372 : : {
373 [ # # ]: 0 : Reference< XHierarchicalNameAccess > xHierarchyAccess(_xTreeNode, UNO_QUERY);
374 [ # # ]: 0 : Reference< XNameAccess > xDirectAccess(_xTreeNode, UNO_QUERY);
375 : 0 : Reference< XInterface > xNode;
376 : :
377 : : try
378 : : {
379 [ # # ][ # # ]: 0 : if (xDirectAccess.is() && xDirectAccess->hasByName(_rPath))
[ # # ][ # # ]
[ # # ]
380 : : {
381 [ # # ][ # # ]: 0 : if (!::cppu::extractInterface(xNode, xDirectAccess->getByName(_rPath)))
[ # # ]
382 : : OSL_FAIL("OConfigurationNode::openNode: could not open the node!");
383 : : }
384 [ # # ]: 0 : else if (xHierarchyAccess.is())
385 : : {
386 [ # # ][ # # ]: 0 : if (!::cppu::extractInterface(xNode, xHierarchyAccess->getByHierarchicalName(_rPath)))
[ # # ]
[ # # # ]
387 : : OSL_FAIL("OConfigurationNode::openNode: could not open the node!");
388 : : }
389 : :
390 : : }
391 [ # # ]: 0 : catch(const NoSuchElementException&)
392 : : {
393 : : OSL_FAIL((::rtl::OString("::openNode: there is no element named ")
394 : : += ::rtl::OString(_rPath.getStr(), _rPath.getLength(), RTL_TEXTENCODING_ASCII_US)
395 : : += ::rtl::OString("!")).getStr());
396 : : }
397 [ # # ]: 0 : catch(Exception&)
398 : : {
399 : : OSL_FAIL("OConfigurationNode::openNode: caught an exception while retrieving the node!");
400 : : }
401 : 0 : return xNode;
402 : : }
403 : : // -----------------------------------------------------------------------------
404 : 112 : Any OPoolCollection::getNodeValue(const ::rtl::OUString& _rPath,const Reference<XInterface>& _xTreeNode) throw()
405 : : {
406 [ + - ]: 112 : Reference< XHierarchicalNameAccess > xHierarchyAccess(_xTreeNode, UNO_QUERY);
407 [ + - ]: 112 : Reference< XNameAccess > xDirectAccess(_xTreeNode, UNO_QUERY);
408 : 112 : Any aReturn;
409 : : try
410 : : {
411 [ + - ][ + - ]: 112 : if (xDirectAccess.is() && xDirectAccess->hasByName(_rPath) )
[ + - ][ + - ]
[ + - ]
412 : : {
413 [ + - ][ + - ]: 112 : aReturn = xDirectAccess->getByName(_rPath);
414 : : }
415 [ # # ]: 0 : else if (xHierarchyAccess.is())
416 : : {
417 [ # # ][ # # ]: 0 : aReturn = xHierarchyAccess->getByHierarchicalName(_rPath);
418 : : }
419 : : }
420 [ # # ]: 0 : catch(NoSuchElementException& e)
421 : : {
422 : : OSL_UNUSED( e ); // make compiler happy
423 : : OSL_FAIL((::rtl::OString("::getNodeValue: caught a NoSuchElementException while trying to open ")
424 : : += ::rtl::OString(e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US)
425 : : += ::rtl::OString("!")).getStr());
426 : : }
427 [ # # ]: 112 : return aReturn;
428 : : }
429 : : // -----------------------------------------------------------------------------
430 : 9 : void SAL_CALL OPoolCollection::queryTermination( const EventObject& /*Event*/ ) throw (::com::sun::star::frame::TerminationVetoException, RuntimeException)
431 : : {
432 : 9 : }
433 : : // -----------------------------------------------------------------------------
434 : 9 : void SAL_CALL OPoolCollection::notifyTermination( const EventObject& /*Event*/ ) throw (RuntimeException)
435 : : {
436 : 9 : clearDesktop();
437 : 9 : }
438 : : // -----------------------------------------------------------------------------
439 : 0 : void SAL_CALL OPoolCollection::disposing( const EventObject& Source ) throw (RuntimeException)
440 : : {
441 [ # # ]: 0 : MutexGuard aGuard(m_aMutex);
442 [ # # ][ # # ]: 0 : if ( m_xDesktop == Source.Source )
443 : : {
444 [ # # ]: 0 : clearDesktop();
445 : : }
446 : : else
447 : : {
448 : : try
449 : : {
450 [ # # ]: 0 : Reference<XPropertySet> xProp(Source.Source,UNO_QUERY);
451 [ # # ][ # # ]: 0 : if(Source.Source == m_xConfigNode)
452 : : {
453 [ # # ]: 0 : if ( xProp.is() )
454 [ # # ][ # # ]: 0 : xProp->removePropertyChangeListener(getEnablePoolingNodeName(),this);
[ # # ][ # # ]
455 : 0 : m_xConfigNode.clear();
456 : : }
457 [ # # ]: 0 : else if ( xProp.is() )
458 [ # # ][ # # ]: 0 : xProp->removePropertyChangeListener(getEnableNodeName(),this);
[ # # ][ # # ]
[ # # ]
459 : : }
460 [ # # ]: 0 : catch(const Exception&)
461 : : {
462 : : OSL_FAIL("Exception caught");
463 : : }
464 [ # # ]: 0 : }
465 : 0 : }
466 : : // -----------------------------------------------------------------------------
467 : 0 : void SAL_CALL OPoolCollection::propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (RuntimeException)
468 : : {
469 [ # # ]: 0 : MutexGuard aGuard(m_aMutex);
470 [ # # ][ # # ]: 0 : if(evt.Source == m_xConfigNode)
471 : : {
472 : 0 : sal_Bool bEnabled = sal_True;
473 : 0 : evt.NewValue >>= bEnabled;
474 [ # # ]: 0 : if(!bEnabled )
475 : : {
476 : 0 : m_aDriverProxies.clear();
477 [ # # ][ # # ]: 0 : m_aDriverProxies = MapDriver2DriverRef();
478 : 0 : OConnectionPools::iterator aIter = m_aPools.begin();
479 [ # # ]: 0 : for(;aIter != m_aPools.end();++aIter)
480 : : {
481 [ # # ]: 0 : aIter->second->clear(sal_False);
482 : 0 : aIter->second->release();
483 : : }
484 : 0 : m_aPools.clear();
485 [ # # ][ # # ]: 0 : m_aPools = OConnectionPools();
486 : : }
487 : : }
488 [ # # ]: 0 : else if(evt.Source.is())
489 : : {
490 : 0 : sal_Bool bEnabled = sal_True;
491 : 0 : evt.NewValue >>= bEnabled;
492 [ # # ]: 0 : if(!bEnabled)
493 : : {
494 : 0 : ::rtl::OUString sThisDriverName;
495 [ # # ]: 0 : getNodeValue(getDriverNameNodeName(),evt.Source) >>= sThisDriverName;
496 : : // 1nd relase the driver
497 : : // look if we already have a proxy for this driver
498 : 0 : MapDriver2DriverRefIterator aLookup = m_aDriverProxies.begin();
499 [ # # ]: 0 : while( aLookup != m_aDriverProxies.end())
500 : : {
501 : 0 : MapDriver2DriverRefIterator aFind = aLookup;
502 [ # # ]: 0 : Reference<XServiceInfo> xInfo(aLookup->first,UNO_QUERY);
503 : 0 : ++aLookup;
504 [ # # ][ # # ]: 0 : if(xInfo.is() && xInfo->getImplementationName() == sThisDriverName)
[ # # ][ # # ]
[ # # # # ]
[ # # ]
505 [ # # ]: 0 : m_aDriverProxies.erase(aFind);
506 : 0 : }
507 : :
508 : : // 2nd clear the connectionpool
509 [ # # ]: 0 : OConnectionPools::iterator aFind = m_aPools.find(sThisDriverName);
510 [ # # ][ # # ]: 0 : if(aFind != m_aPools.end() && aFind->second)
[ # # ][ # # ]
511 : : {
512 [ # # ]: 0 : aFind->second->clear(sal_False);
513 : 0 : aFind->second->release();
514 [ # # ]: 0 : m_aPools.erase(aFind);
515 : 0 : }
516 : : }
517 [ # # ]: 0 : }
518 : 0 : }
519 : : // -----------------------------------------------------------------------------
520 : 9 : void OPoolCollection::clearDesktop()
521 : : {
522 : 9 : clearConnectionPools(sal_True);
523 [ + - ]: 9 : if ( m_xDesktop.is() )
524 [ + - ]: 9 : m_xDesktop->removeTerminateListener(this);
525 : 9 : m_xDesktop.clear();
526 : 9 : }
527 : : // -----------------------------------------------------------------------------
528 : :
529 : :
530 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|