22#include <com/sun/star/lang/XComponent.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
39void SAL_CALL OPoolTimer::onShot()
47 const Reference< XInterface >& _xDriverNode,
48 const Reference< css::reflection::XProxyFactory >& _rxProxyFactory)
50 ,m_xDriverNode(_xDriverNode)
51 ,m_xProxyFactory(_rxProxyFactory)
58 xComponent->addEventListener(
this);
78struct TRemoveEventListenerFunctor
83 TRemoveEventListenerFunctor(
OConnectionPool* _pConnectionPool,
bool _bDispose)
84 : m_pConnectionPool(_pConnectionPool)
85 ,m_bDispose(_bDispose)
87 OSL_ENSURE(m_pConnectionPool,
"No connection pool!");
90 void dispose(
const Reference<XInterface>& _xComponent)
92 Reference< XComponent > xComponent(_xComponent, UNO_QUERY);
94 if ( xComponent.is() )
96 xComponent->removeEventListener(m_pConnectionPool);
98 xComponent->dispose();
102 void operator()(
const TPooledConnections::value_type& _aValue)
107 void operator()(
const TActiveConnectionMap::value_type& _aValue)
113struct TConnectionPoolFunctor
118 : m_pConnectionPool(_pConnectionPool)
120 OSL_ENSURE(m_pConnectionPool,
"No connection pool!");
122 void operator()(
const TConnectionMap::value_type& _aValue)
124 std::for_each(_aValue.second.aConnections.begin(),_aValue.second.aConnections.end(),TRemoveEventListenerFunctor(m_pConnectionPool,
true));
137 std::for_each(
m_aPool.begin(),
m_aPool.end(),TConnectionPoolFunctor(
this));
143 Reference< XComponent > xComponent(
m_xDriverNode, UNO_QUERY);
145 xComponent->removeEventListener(
this);
158 Reference<XConnection> xConnection;
161 Sequence< PropertyValue > aInfo(_rInfo);
162 TConnectionMap::key_type
nId;
164 TConnectionMap::iterator aIter =
m_aPool.find(
nId);
169 if ( !xConnection.is() )
177 Reference<XConnection> xConnection(
Source.Source,UNO_QUERY);
182 OSL_ENSURE(aIter !=
m_aActiveConnections.end(),
"OConnectionPool::disposing: Connection wasn't in pool");
186 aIter->second.aPos->second.aConnections.push_back(aIter->second.xPooledConnection);
199 Reference< XPooledConnection > xPooledConnection = new ::connectivity::OPooledConnection(
m_xDriver->connect(_rURL,_rInfo),
m_xProxyFactory);
201 Reference<XConnection> xConnection = xPooledConnection->getConnection();
205 Reference< XComponent > xComponent(xConnection, UNO_QUERY);
207 xComponent->addEventListener(
this);
210 Sequence< PropertyValue > aInfo(_rInfo);
211 TConnectionMap::key_type
nId;
232 TConnectionMap::iterator aIter =
m_aPool.begin();
233 for (; aIter !=
m_aPool.end(); )
235 if(!(--(aIter->second.nALiveCount)))
237 std::for_each(aIter->second.aConnections.begin(),aIter->second.aConnections.end(),TRemoveEventListenerFunctor(
this,
true));
239 aIter->second.aConnections.clear();
243 [&aIter](
const TActiveConnectionMap::value_type& rEntry) { return rEntry.second.aPos == aIter; });
260 Reference<XConnection> xConnection;
262 if(!_rIter->second.aConnections.empty())
264 Reference< XPooledConnection > xPooledConnection = _rIter->second.aConnections.back();
265 _rIter->second.aConnections.pop_back();
267 OSL_ENSURE(xPooledConnection.is(),
"Can not be null here!");
268 xConnection = xPooledConnection->getConnection();
269 Reference< XComponent > xComponent(xConnection, UNO_QUERY);
271 xComponent->addEventListener(
this);
274 aActiveInfo.
aPos = _rIter;
292 sal_Int32 nTimeOutCorrection = 10;
294 nTimeOutCorrection = 20;
constexpr OUStringLiteral TIMEOUT_NODENAME
::rtl::Reference< OPoolTimer > m_xInvalidator
css::uno::Reference< css::sdbc::XConnection > getConnectionWithInfo(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info)
css::uno::Reference< css::sdbc::XDriver > m_xDriver
css::uno::Reference< css::sdbc::XConnection > createNewConnection(const OUString &_rURL, const css::uno::Sequence< css::beans::PropertyValue > &_rInfo)
css::uno::Reference< css::uno::XInterface > m_xDriverNode
css::uno::Reference< css::reflection::XProxyFactory > m_xProxyFactory
void clear(bool _bDispose)
OConnectionPool(const css::uno::Reference< css::sdbc::XDriver > &_xDriver, const css::uno::Reference< css::uno::XInterface > &_xDriverNode, const css::uno::Reference< css::reflection::XProxyFactory > &_rxProxyFactory)
TActiveConnectionMap m_aActiveConnections
virtual ~OConnectionPool() override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
css::uno::Reference< css::sdbc::XConnection > getPooledConnection(TConnectionMap::iterator const &_rIter)
void invalidatePooledConnections()
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
static void createUniqueId(const OUString &_rURL, css::uno::Sequence< css::beans::PropertyValue > &_rInfo, sal_uInt8 *_pBuffer, const OUString &_rUserName=OUString(), const OUString &_rPassword=OUString())
method to create unique ids
static css::uno::Any getNodeValue(const OUString &_rPath, const css::uno::Reference< css::uno::XInterface > &_xTreeNode) noexcept
OPoolTimer - Invalidates the connection pool.
OConnectionPool * m_pPool
TConnectionMap::iterator aPos
css::uno::Reference< css::sdbc::XPooledConnection > xPooledConnection