Jpp  18.0.0-rc.4
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 189 of file JDB.hh.

Constructor & Destructor Documentation

JDATABASE::JDB::JDB ( )
inlineprivate

Default constructor.

Definition at line 337 of file JDB.hh.

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

Member Function Documentation

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

Get server.

Returns
server

Definition at line 198 of file JDB.hh.

199  {
200  static Server server = JDATABASE::getServer();
201 
202  return server;
203  }
const Server & getServer(const std::string &server)
Get server by name.
Definition: JDB.hh:89
static const Server& JDATABASE::JDB::getServer ( )
inlinestatic

Get server.

Returns
server

Definition at line 211 of file JDB.hh.

212  {
213  return get_server();
214  }
static Server & get_server()
Get server.
Definition: JDB.hh:198
static void JDATABASE::JDB::setServer ( const Server &  server)
inlinestatic

Set server.

Parameters
serverserver

Definition at line 222 of file JDB.hh.

223  {
224  get_server() = server;
225  }
static Server & get_server()
Get server.
Definition: JDB.hh:198
static JDB& JDATABASE::JDB::get ( )
inlinestatic

Get connection to database.

Returns
database connection

Definition at line 233 of file JDB.hh.

234  {
235  static JDB db;
236 
237  return db;
238  }
Auxiliary class for connection to data base.
Definition: JDB.hh:189
static void JDATABASE::JDB::reset ( )
inlinestatic

Reset connection to database.

Definition at line 244 of file JDB.hh.

245  {
246  JDB& db = JDB::get();
247 
248  if (db.get() != NULL) {
249  db->Close();
250  static_cast<std::shared_ptr<Client>&>(db).reset();
251  }
252  }
static void reset()
Reset connection to database.
Definition: JDB.hh:244
Auxiliary class for connection to data base.
Definition: JDB.hh:189
static JDB & get()
Get connection to database.
Definition: JDB.hh:233
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 261 of file JDB.hh.

263  {
264  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(getServer(), usr.c_str(), pwd.c_str());
265  }
static const Server & getServer()
Get server.
Definition: JDB.hh:211
static JDB & get()
Get connection to database.
Definition: JDB.hh:233
static void JDATABASE::JDB::reset ( const std::string cookie)
inlinestatic

Reset connection to database.

Parameters
cookiepersistent cookie

Definition at line 273 of file JDB.hh.

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

316  {
317  using namespace std;
318  using namespace JPP;
319 
320  if (usr != "" && pwd != "")
321  JDB::reset(usr, pwd);
322  else if (cookie != "")
323  JDB::reset(cookie);
324  else if (getFileStatus(getPrivateCookie()))
326  else if (getPublicCookie() != NULL)
328  else
329  THROW(JDatabaseException, "Missing user name / password or cookie file.");
330  }
static void reset()
Reset connection to database.
Definition: JDB.hh:244
#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:154
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
const char * getPublicCookie()
Get public cookie.
Definition: JDB.hh:167
JDB& JDATABASE::JDB::operator= ( const JDB )
private

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