Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JDATABASE::JDB Class Reference

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

#include <JDB.hh>

Inheritance diagram for JDATABASE::JDB:

Static Public Member Functions

static const Server & getServer ()
 Get server.
 
static void setServer (const Server &server)
 Set server.
 
static JDBget ()
 Get connection to database.
 
static void reset ()
 Reset connection to database.
 
static void reset (const std::string &usr, const std::string &pwd)
 Reset connection to database.
 
static void reset (const std::string &cookie)
 Reset connection to database.
 
static void reset (const std::string &usr, const std::string &pwd, const std::string &cookie)
 Reset connection to database.
 

Private Member Functions

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

Static Private Member Functions

static Server & get_server ()
 Get server.
 

Detailed Description

Auxiliary class for connection to data base.

Definition at line 191 of file JDB.hh.

Constructor & Destructor Documentation

◆ JDB() [1/2]

JDATABASE::JDB::JDB ( )
inlineprivate

Default constructor.

Definition at line 339 of file JDB.hh.

340 {}

◆ JDB() [2/2]

JDATABASE::JDB::JDB ( const JDB & )
private

Member Function Documentation

◆ get_server()

static Server & JDATABASE::JDB::get_server ( )
inlinestaticprivate

Get server.

Returns
server

Definition at line 200 of file JDB.hh.

201 {
202 static Server server = JDATABASE::getServer();
203
204 return server;
205 }
const Server & getServer()
Get default server.
Definition JDB.hh:138

◆ getServer()

static const Server & JDATABASE::JDB::getServer ( )
inlinestatic

Get server.

Returns
server

Definition at line 213 of file JDB.hh.

214 {
215 return get_server();
216 }
static Server & get_server()
Get server.
Definition JDB.hh:200

◆ setServer()

static void JDATABASE::JDB::setServer ( const Server & server)
inlinestatic

Set server.

Parameters
serverserver

Definition at line 224 of file JDB.hh.

225 {
226 get_server() = server;
227 }

◆ get()

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

Get connection to database.

Returns
database connection

Definition at line 235 of file JDB.hh.

236 {
237 static JDB db;
238
239 return db;
240 }

◆ reset() [1/4]

static void JDATABASE::JDB::reset ( )
inlinestatic

Reset connection to database.

Definition at line 246 of file JDB.hh.

247 {
248 JDB& db = JDB::get();
249
250 if (db.get() != NULL) {
251 db->Close();
252 static_cast<std::shared_ptr<Client>&>(db).reset();
253 }
254 }
static void reset()
Reset connection to database.
Definition JDB.hh:246
static JDB & get()
Get connection to database.
Definition JDB.hh:235

◆ reset() [2/4]

static void JDATABASE::JDB::reset ( const std::string & usr,
const std::string & pwd )
inlinestatic

Reset connection to database.

Parameters
usruser name
pwdpass word

Definition at line 263 of file JDB.hh.

265 {
266 static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(getServer(), usr.c_str(), pwd.c_str());
267 }
static const Server & getServer()
Get server.
Definition JDB.hh:213

◆ reset() [3/4]

static void JDATABASE::JDB::reset ( const std::string & cookie)
inlinestatic

Reset connection to database.

Parameters
cookiepersistent cookie

Definition at line 275 of file JDB.hh.

276 {
277 using namespace std;
278 using namespace JPP;
279
280 string buffer = cookie;
281
282 if (getFileStatus(cookie.c_str())) {
283
284 ifstream in(cookie.c_str());
285
286 getline(in, buffer);
287
288 in.close();
289 }
290
291 const string::size_type pos = buffer.find(PREFIX_COOKIE);
292
293 if (pos != string::npos) {
294 buffer.erase(0, pos);
295 }
296
297 static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(getServer(), buffer.c_str());
298 }
static const char PREFIX_COOKIE
Cookie prefix.
Definition JDB.hh:178
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).

◆ reset() [4/4]

static void JDATABASE::JDB::reset ( const std::string & usr,
const std::string & pwd,
const std::string & cookie )
inlinestatic

Reset connection to database.

An attempt to make a connection to the database is made in the following order, using:

  1. user name and password, if neither empty;
  2. given cookie, if not empty;
  3. private cookie file (created with JCookie.sh);
  4. public cookie (defined by environment variable DBCOOKIE);
Parameters
usruser name
pwdpassword
cookiepersistent cookie

Definition at line 315 of file JDB.hh.

318 {
319 using namespace std;
320 using namespace JPP;
321
322 if (usr != "" && pwd != "")
323 JDB::reset(usr, pwd);
324 else if (cookie != "")
325 JDB::reset(cookie);
326 else if (getFileStatus(getPrivateCookie()))
328 else if (getPublicCookie() != NULL)
330 else
331 THROW(JDatabaseException, "Missing user name / password or cookie file.");
332 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Database exception.
const char * getPrivateCookie()
Get private cookie.
Definition JDB.hh:156
const char * getPublicCookie()
Get public cookie.
Definition JDB.hh:169

◆ operator=()

JDB & JDATABASE::JDB::operator= ( const JDB & )
private

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