mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-03 15:58:23 +02:00
Reset connection when a session is returned to the SessionPool
This commit is contained in:
parent
8d95644bad
commit
6e6ad28a1f
@ -65,6 +65,9 @@ public:
|
|||||||
void rollback();
|
void rollback();
|
||||||
/// Rollback transaction
|
/// Rollback transaction
|
||||||
|
|
||||||
|
void resetConnection();
|
||||||
|
/// Reset connection with dababase and clears session state, but without disconnecting
|
||||||
|
|
||||||
operator MYSQL* ();
|
operator MYSQL* ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -67,6 +67,9 @@ public:
|
|||||||
void close();
|
void close();
|
||||||
/// Closes the connection.
|
/// Closes the connection.
|
||||||
|
|
||||||
|
void resetConnection();
|
||||||
|
/// Reset connection with dababase and clears session state, but without disconnecting
|
||||||
|
|
||||||
bool isConnected() const;
|
bool isConnected() const;
|
||||||
/// Returns true if connected, false otherwise.
|
/// Returns true if connected, false otherwise.
|
||||||
|
|
||||||
|
@ -176,4 +176,11 @@ void SessionHandle::rollback()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SessionHandle::resetConnection()
|
||||||
|
{
|
||||||
|
if (mysql_reset_connection(_pHandle) != 0)
|
||||||
|
throw TransactionException("Reset connection failed.", _pHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}}} // Poco::Data::MySQL
|
}}} // Poco::Data::MySQL
|
||||||
|
@ -257,6 +257,13 @@ bool SessionImpl::hasTransactionIsolation(Poco::UInt32 ti) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SessionImpl::resetConnection()
|
||||||
|
{
|
||||||
|
if (_connected)
|
||||||
|
_handle.resetConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SessionImpl::close()
|
void SessionImpl::close()
|
||||||
{
|
{
|
||||||
if (_connected)
|
if (_connected)
|
||||||
|
@ -68,6 +68,9 @@ public:
|
|||||||
void close();
|
void close();
|
||||||
/// Closes the session.
|
/// Closes the session.
|
||||||
|
|
||||||
|
void resetConnection();
|
||||||
|
/// Do nothing
|
||||||
|
|
||||||
bool isConnected() const;
|
bool isConnected() const;
|
||||||
/// Returns true if connected, false otherwise.
|
/// Returns true if connected, false otherwise.
|
||||||
|
|
||||||
|
@ -190,6 +190,12 @@ void SessionImpl::close()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SessionImpl::resetConnection()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SessionImpl::isConnected() const
|
bool SessionImpl::isConnected() const
|
||||||
{
|
{
|
||||||
return _connected;
|
return _connected;
|
||||||
|
@ -50,6 +50,7 @@ public:
|
|||||||
void rollback();
|
void rollback();
|
||||||
void open(const std::string& connect = "");
|
void open(const std::string& connect = "");
|
||||||
void close();
|
void close();
|
||||||
|
void resetConnection();
|
||||||
bool isConnected() const;
|
bool isConnected() const;
|
||||||
void setConnectionTimeout(std::size_t timeout);
|
void setConnectionTimeout(std::size_t timeout);
|
||||||
std::size_t getConnectionTimeout() const;
|
std::size_t getConnectionTimeout() const;
|
||||||
|
@ -92,6 +92,9 @@ public:
|
|||||||
void reconnect();
|
void reconnect();
|
||||||
/// Closes the connection and opens it again.
|
/// Closes the connection and opens it again.
|
||||||
|
|
||||||
|
virtual void resetConnection() = 0;
|
||||||
|
/// Reset connection with dababase and clears session state, but without disconnecting
|
||||||
|
|
||||||
virtual void begin() = 0;
|
virtual void begin() = 0;
|
||||||
/// Starts a transaction.
|
/// Starts a transaction.
|
||||||
|
|
||||||
|
@ -148,6 +148,12 @@ void PooledSessionImpl::close()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PooledSessionImpl::resetConnection()
|
||||||
|
{
|
||||||
|
access()->resetConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::string& PooledSessionImpl::connectorName() const
|
const std::string& PooledSessionImpl::connectorName() const
|
||||||
{
|
{
|
||||||
return access()->connectorName();
|
return access()->connectorName();
|
||||||
|
@ -235,6 +235,8 @@ void SessionPool::putBack(PooledSessionHolderPtr pHolder)
|
|||||||
{
|
{
|
||||||
if (pHolder->session()->isConnected())
|
if (pHolder->session()->isConnected())
|
||||||
{
|
{
|
||||||
|
pHolder->session()->resetConnection();
|
||||||
|
|
||||||
// reverse settings applied at acquisition time, if any
|
// reverse settings applied at acquisition time, if any
|
||||||
AddPropertyMap::iterator pIt = _addPropertyMap.find(pHolder->session());
|
AddPropertyMap::iterator pIt = _addPropertyMap.find(pHolder->session());
|
||||||
if (pIt != _addPropertyMap.end())
|
if (pIt != _addPropertyMap.end())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user