00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef _DBUTILS_H_
00041 #define _DBUTILS_H_
00042 #include <string>
00043 #include <list>
00044 #include <vector>
00045 #include "log4cxx/logger.h"
00046 #include "mysql/mysql.h"
00047 #include "RLSNotifier.h"
00048 #include "FileStatus.h"
00049 #include "Exceptions.h"
00050 #include "TreqsConfig.h"
00051 #include "sql_statements.h"
00052 #include "DBFileRequest.h"
00053 #include "ErrorCode.h"
00054
00055 using namespace treqs;
00056
00057 namespace treqs {
00059
00063 class DBUtils {
00064 public:
00066 static DBUtils *getInstance();
00067
00075 void setRequestStatusById(long r, FileStatus fs, std::string m)
00076 throw (ErrMySQL, ErrMySQLStatement);
00077
00087 void setRequestStatusById(long r, FileStatus fs, int errcode, std::string m,
00088 time_t t)
00089 throw (ErrMySQL, ErrMySQLStatement);
00090
00091
00097 std::string getMediaType(std::string t) throw (Error);
00098
00103 std::vector<DBFileRequest> getNewJobs();
00108 std::vector<DBFileRequest> getNewJobs_prepared();
00109
00115 std::multimap<int, std::pair<std::string, float> > getResourceAllocation();
00116
00121 std::list<pair<int, int> > getMediaAllocations();
00122
00128 int getPvrId(std::string pvrname);
00129
00131
00136 int executeObjectUpdate(std::string s) throw (ErrMySQL, ErrMySQLStatement);
00137
00143 long insertNewQueue(std::string s) throw (ErrMySQL, ErrMySQLStatement);
00144
00145
00147
00151 void abortPendingQueues() throw(ErrMySQL, ErrMySQLStatement);
00152
00154
00157 void updateUnfinishedRequests() throw(ErrMySQL, ErrMySQLStatement);
00158
00160 std::string getDbHost();
00162 int getDbPort();
00164 std::string getDbSocket();
00166 std::string getJobsDbName();
00168 std::string getJobsDbPassword();
00170 std::string getJobsDbUser();
00172 std::string getConfigDbName();
00174 std::string getConfigDbPassword();
00176 std::string getConfigDbUser();
00177
00179 void setDbHost(std::string h);
00181 void setDbPort(int p);
00183 void setDbSocket(std::string s);
00185 void setJobsDbName(std::string n);
00187 void setJobsDbPassword(std::string p);
00189 void setJobsDbUser(std::string s);
00191 void setConfigDbName(std::string n);
00193 void setConfigDbPassword(std::string p);
00195 void setConfigDbUser(std::string s);
00196
00197 private:
00199 static DBUtils *_singleton;
00201 RLSNotifier* RLSNot;
00203 static log4cxx::LoggerPtr logger;
00204
00206 std::string DbHost;
00208 int DbPort;
00210 std::string DbSocket;
00211
00213 std::string jobsDbName;
00215 std::string jobsDbUser;
00217 std::string jobsDbPassword;
00219 std::string configDbName;
00221 std::string configDbUser;
00223 std::string configDbPassword;
00224
00226 bool Lock;
00228 MYSQL msql;
00229 my_bool reconnect;
00230 int msql_init;
00231 MYSQL_STMT *GetJobsStmt;
00232
00233
00235 void Connect() throw (ErrMySQL, ErrMySQLConnection);
00237 void Disconnect();
00239
00242 void executeStatement(const std::string stmnt) throw (ErrMySQL);
00243
00245 void initDB() throw (ErrMySQLInitTable);
00246
00248 void prepareGetJobsStatement() throw (ErrMySQL);
00249
00250 void setLock();
00251
00252 void releaseLock();
00253
00254 protected:
00256
00257
00258
00259 DBUtils();
00261 ~DBUtils();
00262 };
00263 }
00264 #endif