change auto-reconnect

This commit is contained in:
Dario 2020-07-17 13:35:14 +02:00
parent 9a0018a03d
commit 12e4d68abf
2 changed files with 23 additions and 13 deletions

View File

@ -56,10 +56,28 @@ bool ConnectionManager::setConnectionsFromConfig(const Poco::Util::LayeredConfig
dbConfig << "db=" << dbName << ";";
dbConfig << "user=" << config.getString(firstKeyPart + ".db.user", "root") << ";";
dbConfig << "password=" << config.getString(firstKeyPart + ".db.password", "") << ";";
dbConfig << "auto-reconnect=true";
dbConfig << "auto-reconnect=false";
setConnection(dbConfig.str(), type);
return true;
}
Poco::Data::Session ConnectionManager::getConnection(ConnectionType type)
{
Poco::ScopedLock<Poco::FastMutex> _lock(mWorkingMutex);
if (CONNECTION_MYSQL_LOGIN_SERVER != type && CONNECTION_MYSQL_PHP_SERVER != type) {
addError(new ParamError("[ConnectionManager::getConnection]", "Connection Type unknown", std::to_string(type)));
throw Poco::NotFoundException("Connection Type unknown", std::to_string(type));
}
auto session = mSessionPools.getPool(mSessionPoolNames[type]).get();
if (!session.isConnected()) {
printf("reconnect called\n");
session.reconnect();
}
//std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S");
//printf("[getConnection] %s impl: %p\n", dateTimeString.data(), session.impl());
return session;
}

View File

@ -35,18 +35,10 @@ public:
}
}
inline Poco::Data::Session getConnection(ConnectionType type) {
Poco::ScopedLock<Poco::FastMutex> _lock(mWorkingMutex);
if (CONNECTION_MYSQL_LOGIN_SERVER != type && CONNECTION_MYSQL_PHP_SERVER != type) {
addError(new ParamError("[ConnectionManager::getConnection]", "Connection Type unknown", std::to_string(type)));
throw Poco::NotFoundException("Connection Type unknown", std::to_string(type));
}
auto session = mSessionPools.getPool(mSessionPoolNames[type]).get();
//std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S");
//printf("[getConnection] %s impl: %p\n", dateTimeString.data(), session.impl());
return session;
}
//! \brief return connection from pool, check if connected in if not, call reconnect on it
//!
//! In the past I used auto-reconnect but it didn't work everytime as expectet
Poco::Data::Session getConnection(ConnectionType type);
protected:
ConnectionManager();