mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add ping and update isConnected now pinging mysql server, instead returning bool value
This commit is contained in:
parent
c74f27b458
commit
7cc13d11f9
@ -65,6 +65,10 @@ public:
|
|||||||
void rollback();
|
void rollback();
|
||||||
/// Rollback transaction
|
/// Rollback transaction
|
||||||
|
|
||||||
|
int ping();
|
||||||
|
/// ping to check if connection is currently active
|
||||||
|
|
||||||
|
|
||||||
operator MYSQL* ();
|
operator MYSQL* ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
#include "StatementExecutor.h"
|
#include "StatementExecutor.h"
|
||||||
#include "ResultMetadata.h"
|
#include "ResultMetadata.h"
|
||||||
#include "Poco/Mutex.h"
|
#include "Poco/Mutex.h"
|
||||||
|
#include "Poco/Timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@ -122,6 +123,8 @@ public:
|
|||||||
const std::string& connectorName() const;
|
const std::string& connectorName() const;
|
||||||
/// Returns the name of the connector.
|
/// Returns the name of the connector.
|
||||||
|
|
||||||
|
inline void updateTimestamp() { _timestampLastActivity = Poco::Timestamp(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -157,6 +160,7 @@ private:
|
|||||||
bool _inTransaction;
|
bool _inTransaction;
|
||||||
std::size_t _timeout;
|
std::size_t _timeout;
|
||||||
Poco::FastMutex _mutex;
|
Poco::FastMutex _mutex;
|
||||||
|
Poco::Timestamp _timestampLastActivity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -203,11 +207,6 @@ inline bool SessionImpl::isTransactionIsolation(Poco::UInt32 ti)
|
|||||||
return getTransactionIsolation() == ti;
|
return getTransactionIsolation() == ti;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool SessionImpl::isConnected()
|
|
||||||
{
|
|
||||||
return _connected;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline std::size_t SessionImpl::getConnectionTimeout()
|
inline std::size_t SessionImpl::getConnectionTimeout()
|
||||||
|
|||||||
@ -175,5 +175,9 @@ void SessionHandle::rollback()
|
|||||||
throw TransactionException("Rollback failed.", _pHandle);
|
throw TransactionException("Rollback failed.", _pHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SessionHandle::ping()
|
||||||
|
{
|
||||||
|
return mysql_ping(_pHandle);
|
||||||
|
}
|
||||||
|
|
||||||
}}} // Poco::Data::MySQL
|
}}} // Poco::Data::MySQL
|
||||||
|
|||||||
@ -150,6 +150,7 @@ void SessionImpl::open(const std::string& connect)
|
|||||||
&SessionImpl::isAutoCommit);
|
&SessionImpl::isAutoCommit);
|
||||||
|
|
||||||
_connected = true;
|
_connected = true;
|
||||||
|
_timestampLastActivity = Poco::Timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -174,6 +175,7 @@ void SessionImpl::begin()
|
|||||||
|
|
||||||
_handle.startTransaction();
|
_handle.startTransaction();
|
||||||
_inTransaction = true;
|
_inTransaction = true;
|
||||||
|
_timestampLastActivity = Poco::Timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -181,6 +183,7 @@ void SessionImpl::commit()
|
|||||||
{
|
{
|
||||||
_handle.commit();
|
_handle.commit();
|
||||||
_inTransaction = false;
|
_inTransaction = false;
|
||||||
|
_timestampLastActivity = Poco::Timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -188,6 +191,7 @@ void SessionImpl::rollback()
|
|||||||
{
|
{
|
||||||
_handle.rollback();
|
_handle.rollback();
|
||||||
_inTransaction = false;
|
_inTransaction = false;
|
||||||
|
_timestampLastActivity = Poco::Timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -196,6 +200,7 @@ void SessionImpl::autoCommit(const std::string&, bool val)
|
|||||||
StatementExecutor ex(_handle);
|
StatementExecutor ex(_handle);
|
||||||
ex.prepare(Poco::format("SET autocommit=%d", val ? 1 : 0));
|
ex.prepare(Poco::format("SET autocommit=%d", val ? 1 : 0));
|
||||||
ex.execute();
|
ex.execute();
|
||||||
|
_timestampLastActivity = Poco::Timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -206,6 +211,27 @@ bool SessionImpl::isAutoCommit(const std::string&)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionImpl::isConnected()
|
||||||
|
{
|
||||||
|
return !_handle.ping();
|
||||||
|
/*
|
||||||
|
if (Poco::Timestamp() > _timestampLastActivity + Poco::Timespan(_timeout, 0)) {
|
||||||
|
return _connected;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_timestampLastActivity = Poco::Timestamp();
|
||||||
|
if (!_handle.ping()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SessionImpl::setTransactionIsolation(Poco::UInt32 ti)
|
void SessionImpl::setTransactionIsolation(Poco::UInt32 ti)
|
||||||
{
|
{
|
||||||
std::string isolation;
|
std::string isolation;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user