Jpp
Static Public Member Functions | Private Member Functions | List of all members
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 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...
 
static void reset (const std::string &usr, const std::string &pwd, 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 87 of file JDB.hh.

Constructor & Destructor Documentation

◆ JDB() [1/2]

JDATABASE::JDB::JDB ( )
inlineprivate

Default constructor.

Definition at line 200 of file JDB.hh.

201  {}

◆ JDB() [2/2]

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

Member Function Documentation

◆ get()

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

Get connection to database.

Returns
database connection

Definition at line 96 of file JDB.hh.

97  {
98  static JDB db;
99 
100  return db;
101  }

◆ reset() [1/4]

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

Reset connection to database.

Definition at line 107 of file JDB.hh.

108  {
109  JDB& db = JDB::get();
110 
111  if (db.get() != NULL) {
112  db->Close();
113  static_cast<std::shared_ptr<Client>&>(db).reset();
114  }
115  }

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

126  {
127  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(Server::Default, usr.c_str(), pwd.c_str());
128  }

◆ reset() [3/4]

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

Reset connection to database.

Parameters
cookiepersistent cookie

Definition at line 136 of file JDB.hh.

137  {
138  using namespace std;
139  using namespace JPP;
140 
141  string buffer = cookie;
142 
143  if (getFileStatus(cookie.c_str())) {
144 
145  ifstream in(cookie.c_str());
146 
147  getline(in, buffer);
148 
149  in.close();
150  }
151 
152  const string::size_type pos = buffer.find(PREFIX_COOKIE);
153 
154  if (pos != string::npos) {
155  buffer.erase(0, pos);
156  }
157 
158  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(Server::Default, buffer.c_str());
159  }

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

179  {
180  using namespace std;
181  using namespace JPP;
182 
183  if (usr != "" && pwd != "")
184  JDB::reset(usr, pwd);
185  else if (cookie != "")
186  JDB::reset(cookie);
187  else if (getFileStatus(getPrivateCookie()))
189  else if (getPublicCookie() != NULL)
191  else
192  THROW(JDatabaseException, "Missing user name / password or cookie file.");
193  }

◆ operator=()

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

The documentation for this class was generated from the following file:
JDATABASE::JDB::get
static JDB & get()
Get connection to database.
Definition: JDB.hh:96
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDATABASE::JDB::reset
static void reset()
Reset connection to database.
Definition: JDB.hh:107
JDATABASE::getPrivateCookie
const char * getPrivateCookie()
Get private cookie.
Definition: JDB.hh:46
JSYSTEM::getFileStatus
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:669
std
Definition: jaanetDictionary.h:36
JDATABASE::PREFIX_COOKIE
static const char PREFIX_COOKIE
Cookie prefix.
Definition: JDB.hh:68
JDATABASE::getPublicCookie
const char * getPublicCookie()
Get public cookie.
Definition: JDB.hh:59
JDATABASE::JDB
Auxiliary class for connection to data base.
Definition: JDB.hh:87
JLANG::getline
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468