Class handling connection to MySQL database. More...
#include <DBUtils.h>
Public Member Functions | |
void | setRequestStatusById (long r, FileStatus fs, std::string m) throw (ErrMySQL, ErrMySQLStatement) |
void | setRequestStatusById (long r, FileStatus fs, int errcode, std::string m, time_t t) throw (ErrMySQL, ErrMySQLStatement) |
std::string | getMediaType (std::string t) throw (Error) |
std::vector< DBFileRequest > | getNewJobs () |
std::vector< DBFileRequest > | getNewJobs_prepared () |
std::multimap< int, std::pair < std::string, float > > | getResourceAllocation () |
std::list< pair< int, int > > | getMediaAllocations () |
int | getPvrId (std::string pvrname) |
int | executeObjectUpdate (std::string s) throw (ErrMySQL, ErrMySQLStatement) |
Sends an update query to the jobs database. | |
long | insertNewQueue (std::string s) throw (ErrMySQL, ErrMySQLStatement) |
void | abortPendingQueues () throw (ErrMySQL, ErrMySQLStatement) |
Called on startup. All the queues from a previous run should be aborted. | |
void | updateUnfinishedRequests () throw (ErrMySQL, ErrMySQLStatement) |
Called on startup. All requests in non-final states should be considered as new. | |
std::string | getDbHost () |
Getter. | |
int | getDbPort () |
Getter. | |
std::string | getDbSocket () |
Getter. | |
std::string | getJobsDbName () |
Getter. | |
std::string | getJobsDbPassword () |
Getter. | |
std::string | getJobsDbUser () |
Getter. | |
std::string | getConfigDbName () |
Getter. | |
std::string | getConfigDbPassword () |
Getter. | |
std::string | getConfigDbUser () |
Getter. | |
void | setDbHost (std::string h) |
Setter. | |
void | setDbPort (int p) |
Setter. | |
void | setDbSocket (std::string s) |
Setter. | |
void | setJobsDbName (std::string n) |
Setter. | |
void | setJobsDbPassword (std::string p) |
Setter. | |
void | setJobsDbUser (std::string s) |
Setter. | |
void | setConfigDbName (std::string n) |
Setter. | |
void | setConfigDbPassword (std::string p) |
Setter. | |
void | setConfigDbUser (std::string s) |
Setter. | |
Static Public Member Functions | |
static DBUtils * | getInstance () |
provide access to singleton instance | |
Protected Member Functions | |
DBUtils () | |
Constructor. | |
~DBUtils () | |
Destructor. | |
Private Member Functions | |
void | Connect () throw (ErrMySQL, ErrMySQLConnection) |
Connects to the database. | |
void | Disconnect () |
Disconnects from the database. | |
void | executeStatement (const std::string stmnt) throw (ErrMySQL) |
Sends a custom statement to the database. | |
void | initDB () throw (ErrMySQLInitTable) |
test if the tables are suitable, if not, create them or throw exception | |
void | prepareGetJobsStatement () throw (ErrMySQL) |
Prepare the statement in mysql to select jobs on their status. | |
void | setLock () |
void | releaseLock () |
Private Attributes | |
RLSNotifier * | RLSNot |
reference to the RLS notifier | |
std::string | DbHost |
Connection parameter. | |
int | DbPort |
Connection parameter. | |
std::string | DbSocket |
Connection parameter. | |
std::string | jobsDbName |
Connection parameter. | |
std::string | jobsDbUser |
Connection parameter. | |
std::string | jobsDbPassword |
Connection parameter. | |
std::string | configDbName |
Connection parameter. | |
std::string | configDbUser |
Connection parameter. | |
std::string | configDbPassword |
Connection parameter. | |
bool | Lock |
This is a lock to be avoid several functions to access to mysql simultaneously. | |
MYSQL | msql |
MySQL session. | |
my_bool | reconnect |
int | msql_init |
MYSQL_STMT * | GetJobsStmt |
Static Private Attributes | |
static DBUtils * | _singleton = 0 |
instance of the singleton | |
static log4cxx::LoggerPtr | logger |
Log4CXX logger. |
Class handling connection to MySQL database.
This class is a singleton allowing connection and queries to the TReqS server database.
treqs::DBUtils::DBUtils | ( | ) | [protected] |
Constructor.
treqs::DBUtils::~DBUtils | ( | ) | [protected] |
Destructor.
void treqs::DBUtils::abortPendingQueues | ( | ) | throw (ErrMySQL, ErrMySQLStatement) |
Called on startup. All the queues from a previous run should be aborted.
When TReqS starts, she cleans the queues table in the database. Previous queues should be set as QS_ABORTED
void treqs::DBUtils::Connect | ( | ) | throw (ErrMySQL, ErrMySQLConnection) [private] |
Connects to the database.
set the reconnection option If a connection is closed by the server, next request will reopen the connection.
void treqs::DBUtils::Disconnect | ( | ) | [private] |
Disconnects from the database.
int treqs::DBUtils::executeObjectUpdate | ( | std::string | s | ) | throw (ErrMySQL, ErrMySQLStatement) |
Sends an update query to the jobs database.
Sends an update query to the jobs database. Usually the query is prepared by a DAO instance
s | the statement |
void treqs::DBUtils::executeStatement | ( | const std::string | stmnt | ) | throw (ErrMySQL) [private] |
Sends a custom statement to the database.
stmnt | an SQL statement |
std::string treqs::DBUtils::getConfigDbName | ( | ) |
Getter.
std::string treqs::DBUtils::getConfigDbPassword | ( | ) |
Getter.
std::string treqs::DBUtils::getConfigDbUser | ( | ) |
Getter.
std::string treqs::DBUtils::getDbHost | ( | ) |
Getter.
int treqs::DBUtils::getDbPort | ( | ) |
Getter.
std::string treqs::DBUtils::getDbSocket | ( | ) |
Getter.
DBUtils * treqs::DBUtils::getInstance | ( | ) | [static] |
provide access to singleton instance
std::string treqs::DBUtils::getJobsDbName | ( | ) |
Getter.
std::string treqs::DBUtils::getJobsDbPassword | ( | ) |
Getter.
std::string treqs::DBUtils::getJobsDbUser | ( | ) |
Getter.
list< pair< int, int > > treqs::DBUtils::getMediaAllocations | ( | ) |
Get the list of PVRs referenced in the configuration table
std::string treqs::DBUtils::getMediaType | ( | std::string | t | ) | throw (Error) |
Find the media type from the treqsconf.pvrconfig table
t | a tape name |
std::vector< DBFileRequest > treqs::DBUtils::getNewJobs | ( | ) |
Find new jobs in the requests table
std::vector< DBFileRequest > treqs::DBUtils::getNewJobs_prepared | ( | ) |
Find new jobs in the requests table using prepared statement
int treqs::DBUtils::getPvrId | ( | std::string | pvrname | ) |
Get the PVR id out of a PVR name
pvrname | the PVR name |
std::multimap< int, std::pair< std::string, float > > treqs::DBUtils::getResourceAllocation | ( | ) |
Collects the resource settings in the configuration table
void treqs::DBUtils::initDB | ( | ) | throw (ErrMySQLInitTable) [private] |
test if the tables are suitable, if not, create them or throw exception
long treqs::DBUtils::insertNewQueue | ( | std::string | s | ) | throw (ErrMySQL, ErrMySQLStatement) |
Insert a new queue in the queues table. Returns the unique identifier of the queue.
s | the inserrt statement |
void treqs::DBUtils::prepareGetJobsStatement | ( | ) | throw (ErrMySQL) [private] |
Prepare the statement in mysql to select jobs on their status.
void treqs::DBUtils::releaseLock | ( | ) | [private] |
void treqs::DBUtils::setConfigDbName | ( | std::string | n | ) |
Setter.
void treqs::DBUtils::setConfigDbPassword | ( | std::string | p | ) |
Setter.
void treqs::DBUtils::setConfigDbUser | ( | std::string | s | ) |
Setter.
void treqs::DBUtils::setDbHost | ( | std::string | h | ) |
Setter.
void treqs::DBUtils::setDbPort | ( | int | p | ) |
Setter.
void treqs::DBUtils::setDbSocket | ( | std::string | s | ) |
Setter.
void treqs::DBUtils::setJobsDbName | ( | std::string | n | ) |
Setter.
void treqs::DBUtils::setJobsDbPassword | ( | std::string | p | ) |
Setter.
void treqs::DBUtils::setJobsDbUser | ( | std::string | s | ) |
Setter.
void treqs::DBUtils::setLock | ( | ) | [private] |
void treqs::DBUtils::setRequestStatusById | ( | long | r, | |
FileStatus | fs, | |||
int | errcode, | |||
std::string | m, | |||
time_t | t | |||
) | throw (ErrMySQL, ErrMySQLStatement) |
Changes a file request status in the database
r | request identifier | |
fs | the file status | |
errcode | errorcode to report | |
m | message | |
t | time stamp to put as an end time |
void treqs::DBUtils::setRequestStatusById | ( | long | r, | |
FileStatus | fs, | |||
std::string | m | |||
) | throw (ErrMySQL, ErrMySQLStatement) |
Changes a file request status in the database
r | request identifier | |
fs | the file status | |
m | message |
void treqs::DBUtils::updateUnfinishedRequests | ( | ) | throw (ErrMySQL, ErrMySQLStatement) |
Called on startup. All requests in non-final states should be considered as new.
Set the status of non-final requests to show them as new jobs
DBUtils * treqs::DBUtils::_singleton = 0 [static, private] |
instance of the singleton
std::string treqs::DBUtils::configDbName [private] |
Connection parameter.
std::string treqs::DBUtils::configDbPassword [private] |
Connection parameter.
std::string treqs::DBUtils::configDbUser [private] |
Connection parameter.
std::string treqs::DBUtils::DbHost [private] |
Connection parameter.
int treqs::DBUtils::DbPort [private] |
Connection parameter.
std::string treqs::DBUtils::DbSocket [private] |
Connection parameter.
MYSQL_STMT* treqs::DBUtils::GetJobsStmt [private] |
std::string treqs::DBUtils::jobsDbName [private] |
Connection parameter.
std::string treqs::DBUtils::jobsDbPassword [private] |
Connection parameter.
std::string treqs::DBUtils::jobsDbUser [private] |
Connection parameter.
bool treqs::DBUtils::Lock [private] |
This is a lock to be avoid several functions to access to mysql simultaneously.
LoggerPtr treqs::DBUtils::logger [static, private] |
Log4CXX logger.
MYSQL treqs::DBUtils::msql [private] |
MySQL session.
int treqs::DBUtils::msql_init [private] |
my_bool treqs::DBUtils::reconnect [private] |
RLSNotifier* treqs::DBUtils::RLSNot [private] |
reference to the RLS notifier