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();
|
||||
/// Rollback transaction
|
||||
|
||||
int ping();
|
||||
/// ping to check if connection is currently active
|
||||
|
||||
|
||||
operator MYSQL* ();
|
||||
|
||||
private:
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include "StatementExecutor.h"
|
||||
#include "ResultMetadata.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -122,6 +123,8 @@ public:
|
||||
const std::string& connectorName() const;
|
||||
/// Returns the name of the connector.
|
||||
|
||||
inline void updateTimestamp() { _timestampLastActivity = Poco::Timestamp(); }
|
||||
|
||||
private:
|
||||
|
||||
template <typename T>
|
||||
@ -157,6 +160,7 @@ private:
|
||||
bool _inTransaction;
|
||||
std::size_t _timeout;
|
||||
Poco::FastMutex _mutex;
|
||||
Poco::Timestamp _timestampLastActivity;
|
||||
};
|
||||
|
||||
|
||||
@ -204,11 +208,6 @@ inline bool SessionImpl::isTransactionIsolation(Poco::UInt32 ti)
|
||||
}
|
||||
|
||||
|
||||
inline bool SessionImpl::isConnected()
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t SessionImpl::getConnectionTimeout()
|
||||
{
|
||||
|
||||
@ -175,5 +175,9 @@ void SessionHandle::rollback()
|
||||
throw TransactionException("Rollback failed.", _pHandle);
|
||||
}
|
||||
|
||||
int SessionHandle::ping()
|
||||
{
|
||||
return mysql_ping(_pHandle);
|
||||
}
|
||||
|
||||
}}} // Poco::Data::MySQL
|
||||
|
||||
@ -150,6 +150,7 @@ void SessionImpl::open(const std::string& connect)
|
||||
&SessionImpl::isAutoCommit);
|
||||
|
||||
_connected = true;
|
||||
_timestampLastActivity = Poco::Timestamp();
|
||||
}
|
||||
|
||||
|
||||
@ -174,6 +175,7 @@ void SessionImpl::begin()
|
||||
|
||||
_handle.startTransaction();
|
||||
_inTransaction = true;
|
||||
_timestampLastActivity = Poco::Timestamp();
|
||||
}
|
||||
|
||||
|
||||
@ -181,6 +183,7 @@ void SessionImpl::commit()
|
||||
{
|
||||
_handle.commit();
|
||||
_inTransaction = false;
|
||||
_timestampLastActivity = Poco::Timestamp();
|
||||
}
|
||||
|
||||
|
||||
@ -188,6 +191,7 @@ void SessionImpl::rollback()
|
||||
{
|
||||
_handle.rollback();
|
||||
_inTransaction = false;
|
||||
_timestampLastActivity = Poco::Timestamp();
|
||||
}
|
||||
|
||||
|
||||
@ -196,6 +200,7 @@ void SessionImpl::autoCommit(const std::string&, bool val)
|
||||
StatementExecutor ex(_handle);
|
||||
ex.prepare(Poco::format("SET autocommit=%d", val ? 1 : 0));
|
||||
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)
|
||||
{
|
||||
std::string isolation;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user