Jpp master_rocky-44-g75b7c4f75
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 190 of file JDB.hh.

Constructor & Destructor Documentation

◆ JDB() [1/2]

JDATABASE::JDB::JDB ( )
inlineprivate

Default constructor.

Definition at line 338 of file JDB.hh.

339 {}

◆ 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 199 of file JDB.hh.

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

◆ getServer()

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

Get server.

Returns
server

Definition at line 212 of file JDB.hh.

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

◆ setServer()

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

Set server.

Parameters
serverserver

Definition at line 223 of file JDB.hh.

224 {
225 get_server() = server;
226 }

◆ get()

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

Get connection to database.

Returns
database connection

Definition at line 234 of file JDB.hh.

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

◆ reset() [1/4]

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

Reset connection to database.

Definition at line 245 of file JDB.hh.

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

◆ 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 262 of file JDB.hh.

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

◆ reset() [3/4]

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

Reset connection to database.

Parameters
cookiepersistent cookie

Definition at line 274 of file JDB.hh.

275 {
276 using namespace std;
277 using namespace JPP;
278
279 string buffer = cookie;
280
281 if (getFileStatus(cookie.c_str())) {
282
283 ifstream in(cookie.c_str());
284
285 getline(in, buffer);
286
287 in.close();
288 }
289
290 const string::size_type pos = buffer.find(PREFIX_COOKIE);
291
292 if (pos != string::npos) {
293 buffer.erase(0, pos);
294 }
295
296 static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(getServer(), buffer.c_str());
297 }
static const char PREFIX_COOKIE
Cookie prefix.
Definition JDB.hh:177
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 314 of file JDB.hh.

317 {
318 using namespace std;
319 using namespace JPP;
320
321 if (usr != "" && pwd != "")
322 JDB::reset(usr, pwd);
323 else if (cookie != "")
324 JDB::reset(cookie);
325 else if (getFileStatus(getPrivateCookie()))
327 else if (getPublicCookie() != NULL)
329 else
330 THROW(JDatabaseException, "Missing user name / password or cookie file.");
331 }
#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:155
const char * getPublicCookie()
Get public cookie.
Definition JDB.hh:168

◆ operator=()

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

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