Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Static Public Member Functions | Private Member Functions | List of all members
KM3NETDB::JDB Class Reference

Auxiliary class for connection to data base. More...

#include <JDB.hh>

Inheritance diagram for KM3NETDB::JDB:

Static Public Member Functions

static JDBget ()
 Get connection to database. More...
 
static void reset ()
 Reset connection to database. More...
 
static void reset (const std::string &usr, const std::string &pwd)
 Reset connection to database. More...
 
static void reset (const std::string &cookie)
 Reset connection to database. More...
 

Private Member Functions

 JDB ()
 Default constructor. More...
 
 JDB (const JDB &)
 
JDBoperator= (const JDB &)
 

Detailed Description

Auxiliary class for connection to data base.

Definition at line 33 of file JDB.hh.

Constructor & Destructor Documentation

KM3NETDB::JDB::JDB ( )
inlineprivate

Default constructor.

Definition at line 111 of file JDB.hh.

112  {}
KM3NETDB::JDB::JDB ( const JDB )
private

Member Function Documentation

static JDB& KM3NETDB::JDB::get ( )
inlinestatic

Get connection to database.

Returns
database connection

Definition at line 42 of file JDB.hh.

43  {
44  static JDB db;
45 
46  return db;
47  }
JDB()
Default constructor.
Definition: JDB.hh:111
static void KM3NETDB::JDB::reset ( )
inlinestatic

Reset connection to database.

Definition at line 53 of file JDB.hh.

54  {
55  JDB& db = JDB::get();
56 
57  if (db.get() != NULL) {
58  db->Close();
59  db. reset();
60  }
61  }
static JDB & get()
Get connection to database.
Definition: JDB.hh:42
JDB()
Default constructor.
Definition: JDB.hh:111
static void reset()
Reset connection to database.
Definition: JDB.hh:53
static void KM3NETDB::JDB::reset ( const std::string &  usr,
const std::string &  pwd 
)
inlinestatic

Reset connection to database.

Parameters
usruser name
pwdpass word

Definition at line 70 of file JDB.hh.

71  {
72  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(Server::Default, usr.c_str(), pwd.c_str());
73  }
static JDB & get()
Get connection to database.
Definition: JDB.hh:42
static void KM3NETDB::JDB::reset ( const std::string &  cookie)
inlinestatic

Reset connection to database.

Parameters
cookiepersistent cookie

Definition at line 81 of file JDB.hh.

82  {
83  using namespace std;
84  using namespace JPP;
85 
86  string buffer = cookie;
87 
88  if (getFileStatus(cookie.c_str())) {
89 
90  ifstream in(cookie.c_str());
91 
92  getline(in, buffer);
93 
94  string::size_type pos = buffer.find(PREFIX_COOKIE);
95 
96  if (pos != string::npos) {
97  buffer.erase(0,pos);
98  }
99 
100  in.close();
101  }
102 
103  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(Server::Default, buffer.c_str());
104  }
static JDB & get()
Get connection to database.
Definition: JDB.hh:42
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
static const char PREFIX_COOKIE
Cookie prefix.
Definition: JDB.hh:27
JDB& KM3NETDB::JDB::operator= ( const JDB )
private

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