Skip to content
Snippets Groups Projects
Commit c2ba2ed8 authored by Marco De Marco's avatar Marco De Marco
Browse files

Database manager modified, minor fix

parent aced8cce
No related branches found
No related tags found
No related merge requests found
...@@ -16,10 +16,6 @@ DBManager::DBManager(Tango::DeviceImpl* deviceImpl_p, ...@@ -16,10 +16,6 @@ DBManager::DBManager(Tango::DeviceImpl* deviceImpl_p,
m_configuration_sp(configuration_sp) m_configuration_sp(configuration_sp)
{ {
DEBUG_STREAM << "DBManager::DBManager()" << endl; DEBUG_STREAM << "DBManager::DBManager()" << endl;
unsigned int connectionNumber = m_configuration_sp->getDatabaseConnectionNumber();
m_connectionPool_sp.reset(new soci::connection_pool(connectionNumber));
} }
//============================================================================== //==============================================================================
...@@ -51,6 +47,10 @@ void DBManager::connect() throw(soci::soci_error) ...@@ -51,6 +47,10 @@ void DBManager::connect() throw(soci::soci_error)
boost::mutex::scoped_lock lock(m_connectionPoolMutex); boost::mutex::scoped_lock lock(m_connectionPoolMutex);
unsigned int connectionNumber = m_configuration_sp->getDatabaseConnectionNumber();
m_connectionPool_sp.reset(new soci::connection_pool(connectionNumber));
std::stringstream connection; std::stringstream connection;
connection << " host=" << m_configuration_sp->getDatabaseHost(); connection << " host=" << m_configuration_sp->getDatabaseHost();
connection << " port=" << m_configuration_sp->getDatabasePort(); connection << " port=" << m_configuration_sp->getDatabasePort();
...@@ -61,13 +61,9 @@ void DBManager::connect() throw(soci::soci_error) ...@@ -61,13 +61,9 @@ void DBManager::connect() throw(soci::soci_error)
INFO_STREAM << "DBManager::connect(): " << connection.str() << endl; INFO_STREAM << "DBManager::connect(): " << connection.str() << endl;
#endif #endif
unsigned int connectionNumber = m_configuration_sp->getDatabaseConnectionNumber();
for(unsigned int i=0; i<connectionNumber; ++i) for(unsigned int i=0; i<connectionNumber; ++i)
{
m_connectionPool_sp->at(i).open(soci::mysql, connection.str()); m_connectionPool_sp->at(i).open(soci::mysql, connection.str());
} }
}
//============================================================================== //==============================================================================
// DBManager::disconnect() // DBManager::disconnect()
...@@ -78,12 +74,7 @@ void DBManager::disconnect() ...@@ -78,12 +74,7 @@ void DBManager::disconnect()
boost::mutex::scoped_lock lock(m_connectionPoolMutex); boost::mutex::scoped_lock lock(m_connectionPoolMutex);
unsigned int connectionNumber = m_configuration_sp->getDatabaseConnectionNumber(); m_connectionPool_sp.reset();
for(unsigned int i=0; i<connectionNumber; ++i)
{
m_connectionPool_sp->at(i).close();
}
} }
//============================================================================== //==============================================================================
...@@ -94,6 +85,9 @@ DBManager::InformationList DBManager::retrieveInformation(std::string schema, ...@@ -94,6 +85,9 @@ DBManager::InformationList DBManager::retrieveInformation(std::string schema,
{ {
DEBUG_STREAM << "DBManager::retrieveInformation()" << endl; DEBUG_STREAM << "DBManager::retrieveInformation()" << endl;
if(!m_connectionPool_sp)
throw soci::soci_error("Connection pool not initialized");
soci::session session(*m_connectionPool_sp); soci::session session(*m_connectionPool_sp);
if(session.get_backend() == NULL) if(session.get_backend() == NULL)
...@@ -119,6 +113,9 @@ DBManager::RowsetSP DBManager::retrieveNewTuples(std::string schema, ...@@ -119,6 +113,9 @@ DBManager::RowsetSP DBManager::retrieveNewTuples(std::string schema,
{ {
DEBUG_STREAM << "DBManager::retrieveNewTuples()" << endl; DEBUG_STREAM << "DBManager::retrieveNewTuples()" << endl;
if(!m_connectionPool_sp)
throw soci::soci_error("Connection pool not initialized");
soci::session session(*m_connectionPool_sp); soci::session session(*m_connectionPool_sp);
if(session.get_backend() == NULL) if(session.get_backend() == NULL)
......
...@@ -145,7 +145,7 @@ void PlainSession::startWriteResponse() ...@@ -145,7 +145,7 @@ void PlainSession::startWriteResponse()
m_strand.wrap(boost::bind(&PlainSession::handleWriteResponse, m_strand.wrap(boost::bind(&PlainSession::handleWriteResponse,
shared_from_this(), boost::asio::placeholders::error))); shared_from_this(), boost::asio::placeholders::error)));
} }
catch(std::runtime_error& ec) catch(std::exception& ec)
{ {
ERROR_STREAM << "SSLSession::startWriteResponse() " ERROR_STREAM << "SSLSession::startWriteResponse() "
<< ec.what() << " from " << m_remoteEndpoint << endl; << ec.what() << " from " << m_remoteEndpoint << endl;
......
...@@ -46,7 +46,7 @@ public: ...@@ -46,7 +46,7 @@ public:
protected: protected:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Protected] Utilities methods // [Protected] Request response methods
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
virtual void startReadRequestHeader(); virtual void startReadRequestHeader();
......
...@@ -100,13 +100,13 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp) ...@@ -100,13 +100,13 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp)
response_sp->set_type(Response::AUTHORIZATION); response_sp->set_type(Response::AUTHORIZATION);
Response::Authorization* auth_resp = response_sp->mutable_authorization(); Response::Authorization* authResp = response_sp->mutable_authorization();
if(!m_isAuthorised) if(!m_isAuthorised)
{ {
const Request::Authorization& auth_req = request_sp->authorization(); const Request::Authorization& authReq = request_sp->authorization();
std::string username = auth_req.username(); std::string username = authReq.username();
std::string password = auth_req.password(); std::string password = authReq.password();
if(m_configuration_sp->isUserAuthorized(username, password)) if(m_configuration_sp->isUserAuthorized(username, password))
{ {
...@@ -115,8 +115,8 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp) ...@@ -115,8 +115,8 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp)
m_isAuthorised = true; m_isAuthorised = true;
auth_resp->set_state(Response::Authorization::ACCEPTED); authResp->set_state(Response::Authorization::ACCEPTED);
auth_resp->set_status("Authorization accepted"); authResp->set_status("Authorization accepted");
} }
else else
{ {
...@@ -125,8 +125,8 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp) ...@@ -125,8 +125,8 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp)
m_isAuthorised = false; m_isAuthorised = false;
auth_resp->set_state(Response::Authorization::REJECTED); authResp->set_state(Response::Authorization::REJECTED);
auth_resp->set_status("Invalid username or password"); authResp->set_status("Invalid username or password");
} }
} }
else else
...@@ -134,8 +134,8 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp) ...@@ -134,8 +134,8 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp)
WARN_STREAM << "ProtocolManager::prepareAuthroisation() " WARN_STREAM << "ProtocolManager::prepareAuthroisation() "
<< "Already authorized from " << m_remoteEndpoint << endl; << "Already authorized from " << m_remoteEndpoint << endl;
auth_resp->set_state(Response::Authorization::REJECTED); authResp->set_state(Response::Authorization::REJECTED);
auth_resp->set_status("Already authorized"); authResp->set_status("Already authorized");
} }
return response_sp; return response_sp;
...@@ -173,7 +173,7 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp) ...@@ -173,7 +173,7 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp)
std::stringstream errorStream; std::stringstream errorStream;
errorStream << "Table " << m_validatedSchema << "." errorStream << "Table " << m_validatedSchema << "."
<< m_validatedTable << " not exists"; << m_validatedTable << " not exists";
throw soci::soci_error(errorStream.str()); throw std::runtime_error(errorStream.str());
} }
if(validationReq.columns_size() != (int)informationList.size()) if(validationReq.columns_size() != (int)informationList.size())
...@@ -181,7 +181,7 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp) ...@@ -181,7 +181,7 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp)
std::stringstream errorStream; std::stringstream errorStream;
errorStream << "Table " << m_validatedSchema << "." errorStream << "Table " << m_validatedSchema << "."
<< m_validatedTable << " has different columns size"; << m_validatedTable << " has different columns size";
throw soci::soci_error(errorStream.str()); throw std::runtime_error(errorStream.str());
} }
for(int i=0; i<validationReq.columns_size(); ++i) for(int i=0; i<validationReq.columns_size(); ++i)
...@@ -357,10 +357,10 @@ void ProtocolManager::validateColumn(const Request::Validation::Column& column, ...@@ -357,10 +357,10 @@ void ProtocolManager::validateColumn(const Request::Validation::Column& column,
} }
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
INFO_STREAM << "ProtocolManager::validateColumn(): " << columnName INFO_STREAM << "ProtocolManager::validateColumn() "
<< " " << columnType << " " << isNullable << endl; << column.name() << "<->" << columnName << " "
INFO_STREAM << "ProtocolManager::validateColumn(): " << column.name() << column.type() << "<->" << columnType << " "
<< " " << column.type() << " " << column.nullable() << endl; << column.nullable() << "<->" << isNullable << endl;
#endif #endif
} }
} }
......
...@@ -181,7 +181,7 @@ void SSLSession::startWriteResponse() ...@@ -181,7 +181,7 @@ void SSLSession::startWriteResponse()
m_strand.wrap(boost::bind(&SSLSession::handleWriteResponse, m_strand.wrap(boost::bind(&SSLSession::handleWriteResponse,
shared_from_this(), boost::asio::placeholders::error))); shared_from_this(), boost::asio::placeholders::error)));
} }
catch(std::runtime_error& ec) catch(std::exception& ec)
{ {
ERROR_STREAM << "SSLSession::startWriteResponse() " ERROR_STREAM << "SSLSession::startWriteResponse() "
<< ec.what() << " from " << m_remoteEndpoint << endl; << ec.what() << " from " << m_remoteEndpoint << endl;
......
...@@ -51,12 +51,15 @@ public: ...@@ -51,12 +51,15 @@ public:
protected: protected:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Protected] Utilities methods // [Protected] SSL handshake initialization methods
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
virtual void startHandShake(); virtual void startHandShake();
virtual void handleHandShake(const boost::system::error_code&); virtual void handleHandShake(const boost::system::error_code&);
//------------------------------------------------------------------------------
// [Protected] Request response methods
//------------------------------------------------------------------------------
virtual void startReadRequestHeader(); virtual void startReadRequestHeader();
virtual void startReadRequestBody(boost::uint32_t); virtual void startReadRequestBody(boost::uint32_t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment