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