Jpp  17.1.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 181 of file JDB.hh.

Constructor & Destructor Documentation

JDATABASE::JDB::JDB ( )
inlineprivate

Default constructor.

Definition at line 329 of file JDB.hh.

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

Member Function Documentation

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

Get server.

Returns
server

Definition at line 190 of file JDB.hh.

191  {
192  static Server server = JDATABASE::getServer();
193 
194  return server;
195  }
const Server & getServer(const std::string &server)
Get server by name.
Definition: JDB.hh:81
static const Server& JDATABASE::JDB::getServer ( )
inlinestatic

Get server.

Returns
server

Definition at line 203 of file JDB.hh.

204  {
205  return get_server();
206  }
static Server & get_server()
Get server.
Definition: JDB.hh:190
static void JDATABASE::JDB::setServer ( const Server &  server)
inlinestatic

Set server.

Parameters
serverserver

Definition at line 214 of file JDB.hh.

215  {
216  get_server() = server;
217  }
static Server & get_server()
Get server.
Definition: JDB.hh:190
static JDB& JDATABASE::JDB::get ( )
inlinestatic

Get connection to database.

Returns
database connection

Definition at line 225 of file JDB.hh.

226  {
227  static JDB db;
228 
229  return db;
230  }
Auxiliary class for connection to data base.
Definition: JDB.hh:181
static void JDATABASE::JDB::reset ( )
inlinestatic

Reset connection to database.

Definition at line 236 of file JDB.hh.

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

255  {
256  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(getServer(), usr.c_str(), pwd.c_str());
257  }
static const Server & getServer()
Get server.
Definition: JDB.hh:203
static JDB & get()
Get connection to database.
Definition: JDB.hh:225
static void JDATABASE::JDB::reset ( const std::string &  cookie)
inlinestatic

Reset connection to database.

Parameters
cookiepersistent cookie

Definition at line 265 of file JDB.hh.

266  {
267  using namespace std;
268  using namespace JPP;
269 
270  string buffer = cookie;
271 
272  if (getFileStatus(cookie.c_str())) {
273 
274  ifstream in(cookie.c_str());
275 
276  getline(in, buffer);
277 
278  in.close();
279  }
280 
281  const string::size_type pos = buffer.find(PREFIX_COOKIE);
282 
283  if (pos != string::npos) {
284  buffer.erase(0, pos);
285  }
286 
287  static_cast<std::shared_ptr<Client>&>(JDB::get()) = Client::Create(getServer(), buffer.c_str());
288  }
static const Server & getServer()
Get server.
Definition: JDB.hh:203
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:168
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:225
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 305 of file JDB.hh.

308  {
309  using namespace std;
310  using namespace JPP;
311 
312  if (usr != "" && pwd != "")
313  JDB::reset(usr, pwd);
314  else if (cookie != "")
315  JDB::reset(cookie);
316  else if (getFileStatus(getPrivateCookie()))
318  else if (getPublicCookie() != NULL)
320  else
321  THROW(JDatabaseException, "Missing user name / password or cookie file.");
322  }
static void reset()
Reset connection to database.
Definition: JDB.hh:236
#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:146
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
const char * getPublicCookie()
Get public cookie.
Definition: JDB.hh:159
JDB& JDATABASE::JDB::operator= ( const JDB )
private

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