treqs::DBUtils Class Reference

Class handling connection to MySQL database. More...

#include <DBUtils.h>

Collaboration diagram for treqs::DBUtils:
Collaboration graph
[legend]

List of all members.

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< DBFileRequestgetNewJobs ()
std::vector< DBFileRequestgetNewJobs_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 DBUtilsgetInstance ()
 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

RLSNotifierRLSNot
 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.

Detailed Description

Class handling connection to MySQL database.

This class is a singleton allowing connection and queries to the TReqS server database.


Constructor & Destructor Documentation

treqs::DBUtils::DBUtils (  )  [protected]

Constructor.

Here is the call graph for this function:

Here is the caller graph for this function:

treqs::DBUtils::~DBUtils (  )  [protected]

Destructor.

Here is the call graph for this function:


Member Function Documentation

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

Here is the call graph for this function:

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.

Here is the call graph for this function:

Here is the caller graph for this function:

void treqs::DBUtils::Disconnect (  )  [private]

Disconnects from the database.

Here is the caller graph for this function:

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

Parameters:
s the statement
Returns:
the number of rows updated

Here is the call graph for this function:

void treqs::DBUtils::executeStatement ( const std::string  stmnt  )  throw (ErrMySQL) [private]

Sends a custom statement to the database.

Parameters:
stmnt an SQL statement

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Returns:
a list of pairs (PVR Ids, drives)

Here is the call graph for this function:

Here is the caller graph for this function:

std::string treqs::DBUtils::getMediaType ( std::string  t  )  throw (Error)

Find the media type from the treqsconf.pvrconfig table

Parameters:
t a tape name
Returns:
the media type

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< DBFileRequest > treqs::DBUtils::getNewJobs (  ) 

Find new jobs in the requests table

Returns:
a vector of DBFileRequest

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< DBFileRequest > treqs::DBUtils::getNewJobs_prepared (  ) 

Find new jobs in the requests table using prepared statement

Returns:
A vector of DBFileRequest

Here is the call graph for this function:

int treqs::DBUtils::getPvrId ( std::string  pvrname  ) 

Get the PVR id out of a PVR name

Parameters:
pvrname the PVR name
Returns:
the PVR id

Here is the call graph for this function:

Here is the caller graph for this function:

std::multimap< int, std::pair< std::string, float > > treqs::DBUtils::getResourceAllocation (  ) 

Collects the resource settings in the configuration table

Returns:
a map containing the resource share for each user and each element is a pair with values : pvrid => ( user, share )

Here is the call graph for this function:

Here is the caller graph for this function:

void treqs::DBUtils::initDB (  )  throw (ErrMySQLInitTable) [private]

test if the tables are suitable, if not, create them or throw exception

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
s the inserrt statement
Returns:
the unique identifier of the queue

Here is the call graph for this function:

void treqs::DBUtils::prepareGetJobsStatement (  )  throw (ErrMySQL) [private]

Prepare the statement in mysql to select jobs on their status.

Here is the call graph for this function:

Here is the caller graph for this function:

void treqs::DBUtils::releaseLock (  )  [private]

Here is the caller graph for this function:

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]

Here is the call graph for this function:

Here is the caller graph for this function:

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

Parameters:
r request identifier
fs the file status
errcode errorcode to report
m message
t time stamp to put as an end time
Returns:

Here is the call graph for this function:

void treqs::DBUtils::setRequestStatusById ( long  r,
FileStatus  fs,
std::string  m 
) throw (ErrMySQL, ErrMySQLStatement)

Changes a file request status in the database

Parameters:
r request identifier
fs the file status
m message
Returns:

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:


Member Data Documentation

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.

my_bool treqs::DBUtils::reconnect [private]

reference to the RLS notifier


The documentation for this class was generated from the following files:

Generated on 4 Mar 2010 for TReqS by  doxygen 1.6.1