Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 72 of file JDB.hh.

Constructor & Destructor Documentation

JDATABASE::JDB::JDB ( )
inlineprivate

Default constructor.

Definition at line 185 of file JDB.hh.

186  {}
JDATABASE::JDB::JDB ( const JDB )
private

Member Function Documentation

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

Get connection to database.

Returns
database connection

Definition at line 81 of file JDB.hh.

82  {
83  static JDB db;
84 
85  return db;
86  }
Auxiliary class for connection to data base.
Definition: JDB.hh:72
static void JDATABASE::JDB::reset ( )
inlinestatic

Reset connection to database.

Definition at line 92 of file JDB.hh.

93  {
94  JDB& db = JDB::get();
95 
96  if (db.get() != NULL) {
97  db->Close();
98  static_cast<std::shared_ptr<Client>&>(db).reset();
99  }
100  }
static void reset()
Reset connection to database.
Definition: JDB.hh:92
Auxiliary class for connection to data base.
Definition: JDB.hh:72
static JDB & get()
Get connection to database.
Definition: JDB.hh:81
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 109 of file JDB.hh.

111  {
112  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(Server::Default, usr.c_str(), pwd.c_str());
113  }
static JDB & get()
Get connection to database.
Definition: JDB.hh:81
static void JDATABASE::JDB::reset ( const std::string &  cookie)
inlinestatic

Reset connection to database.

Parameters
cookiepersistent cookie

Definition at line 121 of file JDB.hh.

122  {
123  using namespace std;
124  using namespace JPP;
125 
126  string buffer = cookie;
127 
128  if (getFileStatus(cookie.c_str())) {
129 
130  ifstream in(cookie.c_str());
131 
132  getline(in, buffer);
133 
134  in.close();
135  }
136 
137  const string::size_type pos = buffer.find(PREFIX_COOKIE);
138 
139  if (pos != string::npos) {
140  buffer.erase(0, pos);
141  }
142 
143  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(Server::Default, buffer.c_str());
144  }
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
static const char PREFIX_COOKIE
Cookie prefix.
Definition: JDB.hh:59
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
static JDB & get()
Get connection to database.
Definition: JDB.hh:81
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 161 of file JDB.hh.

164  {
165  using namespace std;
166  using namespace JPP;
167 
168  if (usr != "" && pwd != "")
169  JDB::reset(usr, pwd);
170  else if (cookie != "")
171  JDB::reset(cookie);
172  else if (getFileStatus(getPrivateCookie()))
174  else if (getPublicCookie() != NULL)
176  else
177  THROW(JDatabaseException, "Missing user name / password or cookie file.");
178  }
static void reset()
Reset connection to database.
Definition: JDB.hh:92
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
const char * getPrivateCookie()
Get private cookie.
Definition: JDB.hh:37
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
const char * getPublicCookie()
Get public cookie.
Definition: JDB.hh:50
JDB& JDATABASE::JDB::operator= ( const JDB )
private

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