Jpp  17.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Static Public Member Functions | Private Member Functions | Static 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 const Server & getServer ()
 Get server. More...
 
static void setServer (const Server &server)
 Set server. More...
 
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 &)
 

Static Private Member Functions

static Server & get_server ()
 Get server. More...
 

Detailed Description

Auxiliary class for connection to data base.

Definition at line 184 of file JDB.hh.

Constructor & Destructor Documentation

JDATABASE::JDB::JDB ( )
inlineprivate

Default constructor.

Definition at line 332 of file JDB.hh.

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

Member Function Documentation

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

Get server.

Returns
server

Definition at line 193 of file JDB.hh.

194  {
195  static Server server = JDATABASE::getServer();
196 
197  return server;
198  }
const Server & getServer(const std::string &server)
Get server by name.
Definition: JDB.hh:84
static const Server& JDATABASE::JDB::getServer ( )
inlinestatic

Get server.

Returns
server

Definition at line 206 of file JDB.hh.

207  {
208  return get_server();
209  }
static Server & get_server()
Get server.
Definition: JDB.hh:193
static void JDATABASE::JDB::setServer ( const Server &  server)
inlinestatic

Set server.

Parameters
serverserver

Definition at line 217 of file JDB.hh.

218  {
219  get_server() = server;
220  }
static Server & get_server()
Get server.
Definition: JDB.hh:193
static JDB& JDATABASE::JDB::get ( )
inlinestatic

Get connection to database.

Returns
database connection

Definition at line 228 of file JDB.hh.

229  {
230  static JDB db;
231 
232  return db;
233  }
Auxiliary class for connection to data base.
Definition: JDB.hh:184
static void JDATABASE::JDB::reset ( )
inlinestatic

Reset connection to database.

Definition at line 239 of file JDB.hh.

240  {
241  JDB& db = JDB::get();
242 
243  if (db.get() != NULL) {
244  db->Close();
245  static_cast<std::shared_ptr<Client>&>(db).reset();
246  }
247  }
static void reset()
Reset connection to database.
Definition: JDB.hh:239
Auxiliary class for connection to data base.
Definition: JDB.hh:184
static JDB & get()
Get connection to database.
Definition: JDB.hh:228
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 256 of file JDB.hh.

258  {
259  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(getServer(), usr.c_str(), pwd.c_str());
260  }
static const Server & getServer()
Get server.
Definition: JDB.hh:206
static JDB & get()
Get connection to database.
Definition: JDB.hh:228
static void JDATABASE::JDB::reset ( const std::string cookie)
inlinestatic

Reset connection to database.

Parameters
cookiepersistent cookie

Definition at line 268 of file JDB.hh.

269  {
270  using namespace std;
271  using namespace JPP;
272 
273  string buffer = cookie;
274 
275  if (getFileStatus(cookie.c_str())) {
276 
277  ifstream in(cookie.c_str());
278 
279  getline(in, buffer);
280 
281  in.close();
282  }
283 
284  const string::size_type pos = buffer.find(PREFIX_COOKIE);
285 
286  if (pos != string::npos) {
287  buffer.erase(0, pos);
288  }
289 
290  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(getServer(), buffer.c_str());
291  }
static const Server & getServer()
Get server.
Definition: JDB.hh:206
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:171
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
static JDB & get()
Get connection to database.
Definition: JDB.hh:228
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 308 of file JDB.hh.

311  {
312  using namespace std;
313  using namespace JPP;
314 
315  if (usr != "" && pwd != "")
316  JDB::reset(usr, pwd);
317  else if (cookie != "")
318  JDB::reset(cookie);
319  else if (getFileStatus(getPrivateCookie()))
321  else if (getPublicCookie() != NULL)
323  else
324  THROW(JDatabaseException, "Missing user name / password or cookie file.");
325  }
static void reset()
Reset connection to database.
Definition: JDB.hh:239
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
const char * getPrivateCookie()
Get private cookie.
Definition: JDB.hh:149
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
const char * getPublicCookie()
Get public cookie.
Definition: JDB.hh:162
JDB& JDATABASE::JDB::operator= ( const JDB )
private

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