OpenTREP Logo  0.07.18
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
OPENTREP::DBManager Class Reference

Class wrapping the access to an underlying SQL database. More...

#include <opentrep/command/DBManager.hpp>

Static Public Member Functions

static bool createSQLDBUser (const DBType &, const SQLDBConnectionString_T &, const DeploymentNumber_T &)
 
static soci::session * initSQLDBSession (const DBType &, const SQLDBConnectionString_T &)
 
static void terminateSQLDBSession (const DBType &, const SQLDBConnectionString_T &, soci::session &)
 
static void createSQLDBTables (soci::session &)
 
static void createSQLDBIndexes (soci::session &)
 
static NbOfDBEntries_T displayCount (soci::session &)
 
static NbOfDBEntries_T displayAll (soci::session &)
 
static NbOfDBEntries_T getPORByIATACode (soci::session &, const IATACode_T &, LocationList_T &, const bool iUniqueEntry)
 
static NbOfDBEntries_T getPORByICAOCode (soci::session &, const ICAOCode_T &, LocationList_T &)
 
static NbOfDBEntries_T getPORByFAACode (soci::session &, const FAACode_T &, LocationList_T &)
 
static NbOfDBEntries_T getPORByUNLOCode (soci::session &, const UNLOCode_T &, LocationList_T &, const bool iUniqueEntry)
 
static NbOfDBEntries_T getPORByUICCode (soci::session &, const UICCode_T &, LocationList_T &)
 
static NbOfDBEntries_T getPORByGeonameID (soci::session &, const GeonamesID_T &, LocationList_T &)
 
static void insertPlaceInDB (soci::session &, const Place &)
 
static void updatePlaceInDB (soci::session &, const Place &)
 
static std::string prepareSelectAllBlobStatement (soci::session &, soci::statement &)
 
static void prepareSelectFromCoordStatement (soci::session &, soci::statement &, const double &iLatitude, const double &iLongitude)
 
static bool iterateOnStatement (soci::statement &, const std::string &)
 

Detailed Description

Class wrapping the access to an underlying SQL database.

The SQL database may be one of none, SQLite3, MySQL, PostgreSQL. That latter is not supported yet. However, patches are welcome on http://github.com/trep/opentrep/issues.

The methods are assumed to be used in the following order:

  1. DBManager::createSQLDBUser (iDBType, iSQLDBConnStr);
  2. soci::session* lSociSession_ptr = DBManager::initSQLDBSession (iSQLDBType, iSQLDBConnStr);
  3. DBManager::createSQLDBTables (*lSociSession_ptr);
  4. DBManager::terminateSQLDBSession (iSQLDBType, iSQLDBConnStr, *lSociSession_ptr);

Definition at line 42 of file DBManager.hpp.

Member Function Documentation

◆ createSQLDBUser()

bool OPENTREP::DBManager::createSQLDBUser ( const DBType & iDBType,
const SQLDBConnectionString_T & iSQLDBConnStr,
const DeploymentNumber_T & iDeploymentNumber )
static

Destroy and re-create the database.

On SQLite, delete and re-create the content of the directory hosting the database. !!!!!Please be careful to not store anything else in that directory, as it would otherwise be deleted as well!!!!!

On MySQL, create the 'trep' database user and 'trep_trep' database. If tables were previously existing, they are deleted and re-created.

Parameters
constDBType& The SQL database type (e.g., SQLite3, MySQL).
constSQLDBConnectionString_T& Connection string for the SQL database.
constconst DeploymentNumber_T& Deployment number
Returns
bool Whether or not the creation of the SQL database user and DB was successful.

Definition at line 34 of file DBManager.cpp.

References OPENTREP::DEFAULT_OPENTREP_MYSQL_DB_DBNAME, OPENTREP::DEFAULT_OPENTREP_MYSQL_DB_HOST, OPENTREP::DEFAULT_OPENTREP_MYSQL_DB_PASSWD, OPENTREP::DEFAULT_OPENTREP_MYSQL_DB_USER, initSQLDBSession(), OPENTREP::DBType::MYSQL, OPENTREP::DBType::NODB, OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, and OPENTREP::DBType::SQLITE3.

Referenced by OPENTREP::OPENTREP_Service::createSQLDBUser().

◆ initSQLDBSession()

soci::session * OPENTREP::DBManager::initSQLDBSession ( const DBType & iDBType,
const SQLDBConnectionString_T & iSQLDBConnStr )
static

Create a connection to a SQL database.

The method has to be called after a potential call to the createSQLDBUser() method described above, and that latter destroys and re-creates the database.

  • With SQLite3, a database is given by just a file-path. If the SQLite3 database file was previously existing, it is deleted and re-created, empty.
  • With MySQL, a database server needs to run and being accessible thanks to details, including credentials, you know. On that database, the rfd user must have been created before hand. You can use the opentrep_create_db_user.sh helper script (in the bin of the OpenTREP installation directory) for that.
Parameters
constDBType& The SQL database type (e.g., SQLite3, MySQL).
constSQLDBConnectionString_T& Connection string for the SQL database.
Returns
soci::session* A pointer on the just created SQL database connection.

Definition at line 317 of file DBManager.cpp.

References OPENTREP::FileManager::checkSQLiteDirectory(), OPENTREP::DBType::describe(), OPENTREP::DBType::MYSQL, OPENTREP::DBType::NODB, OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, and OPENTREP::DBType::SQLITE3.

Referenced by OPENTREP::OPENTREP_Service::createSQLDBIndexes(), OPENTREP::OPENTREP_Service::createSQLDBTables(), createSQLDBUser(), OPENTREP::getLocationList(), OPENTREP::OPENTREP_Service::getNbOfPORFromDB(), OPENTREP::OPENTREP_Service::listByFaaCode(), OPENTREP::OPENTREP_Service::listByGeonameID(), OPENTREP::OPENTREP_Service::listByIataCode(), OPENTREP::OPENTREP_Service::listByIcaoCode(), OPENTREP::OPENTREP_Service::listByUICCode(), and OPENTREP::OPENTREP_Service::listByUNLOCode().

◆ terminateSQLDBSession()

void OPENTREP::DBManager::terminateSQLDBSession ( const DBType & iDBType,
const SQLDBConnectionString_T & iSQLDBConnStr,
soci::session & ioSociSession )
static

Release/close the connection to a SQL database.

The parameters specifying the database type and connection string are for information only, so that a proper exception message be throwed, if ever.

Parameters
constDBType& The SQL database type (e.g., SQLite3, MySQL).
constSQLDBConnectionString_T& Connection string for the SQL database.
soci::session&A reference to the SQL database connection.

Definition at line 405 of file DBManager.cpp.

References OPENTREP::DBType::describe(), OPENTREP::DBType::MYSQL, OPENTREP::DBType::NODB, OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, and OPENTREP::DBType::SQLITE3.

Referenced by OPENTREP::OPENTREP_Service::createSQLDBIndexes(), OPENTREP::OPENTREP_Service::createSQLDBTables(), OPENTREP::OPENTREP_Service::getNbOfPORFromDB(), OPENTREP::OPENTREP_Service::listByFaaCode(), OPENTREP::OPENTREP_Service::listByGeonameID(), OPENTREP::OPENTREP_Service::listByIataCode(), OPENTREP::OPENTREP_Service::listByIcaoCode(), OPENTREP::OPENTREP_Service::listByUICCode(), and OPENTREP::OPENTREP_Service::listByUNLOCode().

◆ createSQLDBTables()

void OPENTREP::DBManager::createSQLDBTables ( soci::session & ioSociSession)
static

Create the database tables (e.g., 'optd_por' table).

If tables were previously existing, they are deleted and re-created.

Parameters
soci::session&A reference on the SQL database session.

Definition at line 460 of file DBManager.cpp.

References OPENTREP::DBType::describe(), OPENTREP::DBType::MYSQL, OPENTREP::DBType::NODB, OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, and OPENTREP::DBType::SQLITE3.

Referenced by OPENTREP::OPENTREP_Service::createSQLDBTables().

◆ createSQLDBIndexes()

void OPENTREP::DBManager::createSQLDBIndexes ( soci::session & ioSociSession)
static

Create the database indexes.

Parameters
soci::session&A reference on the SQLite3 database session.

Definition at line 595 of file DBManager.cpp.

References OPENTREP::DBType::describe(), OPENTREP::DBType::MYSQL, OPENTREP::DBType::NODB, OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, and OPENTREP::DBType::SQLITE3.

Referenced by OPENTREP::OPENTREP_Service::createSQLDBIndexes().

◆ displayCount()

NbOfDBEntries_T OPENTREP::DBManager::displayCount ( soci::session & ioSociSession)
static

Retrieve the number of POR (points of reference) within the SQL database.

Returns
NbOfDBEntries_T Number of documents of the SQL database.

Definition at line 1106 of file DBManager.cpp.

References OPENTREP_LOG_ERROR.

Referenced by OPENTREP::OPENTREP_Service::getNbOfPORFromDB().

◆ displayAll()

NbOfDBEntries_T OPENTREP::DBManager::displayAll ( soci::session & ioSociSession)
static

Dump all the POR (points of reference) of the SQL database.

Returns
NbOfDBEntries_T Number of documents of the SQL database.

Definition at line 1132 of file DBManager.cpp.

References iterateOnStatement(), OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, and prepareSelectAllBlobStatement().

◆ getPORByIATACode()

NbOfDBEntries_T OPENTREP::DBManager::getPORByIATACode ( soci::session & ioSociSession,
const IATACode_T & iIataCode,
LocationList_T & ioLocationList,
const bool iUniqueEntry )
static

Get the POR (point of reference), from the SQL database, corresponding to the given IATA code.

Note that several entries may correspond to the given IATA code, for instance SFO would give both the airport and the city. If so required (by setting the corresponding parameter), the entry having the greatest Page Rank will be returned.

Parameters
constSQLDBConnectionString_T& Connection string to the SQL DB.
constIATACode_T& The IATA code (key) of the POR to be retrieved.
LocationList_T&List of (geographical) locations, if any, matching the given key.
constbool States whether a unique entry should be returned.
Returns
NbOfDBEntries_T Number of documents of the SQL database.

Definition at line 1172 of file DBManager.cpp.

References OPENTREP::Location::getKey(), OPENTREP::Location::getPageRank(), iterateOnStatement(), OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, OPENTREP::Result::retrieveLocation(), and OPENTREP::Location::setCorrectedKeywords().

Referenced by OPENTREP::getLocationList(), and OPENTREP::OPENTREP_Service::listByIataCode().

◆ getPORByICAOCode()

NbOfDBEntries_T OPENTREP::DBManager::getPORByICAOCode ( soci::session & ioSociSession,
const ICAOCode_T & iIcaoCode,
LocationList_T & ioLocationList )
static

Get the POR (point of reference), from the SQL database, corresponding to the given ICAO code.

Parameters
constSQLDBConnectionString_T& Connection string to the SQL DB.
constICAOCode_T& The ICAO code (key) of the POR to be retrieved.
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfDBEntries_T Number of documents of the SQL database.

Definition at line 1286 of file DBManager.cpp.

References iterateOnStatement(), OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, OPENTREP::Result::retrieveLocation(), and OPENTREP::Location::setCorrectedKeywords().

Referenced by OPENTREP::getLocationList(), and OPENTREP::OPENTREP_Service::listByIcaoCode().

◆ getPORByFAACode()

NbOfDBEntries_T OPENTREP::DBManager::getPORByFAACode ( soci::session & ioSociSession,
const FAACode_T & iFaaCode,
LocationList_T & ioLocationList )
static

Get the POR (point of reference), from the SQL database, corresponding to the given FAA code.

Parameters
constSQLDBConnectionString_T& Connection string to the SQL DB.
constFAACode_T& The FAA code (key) of the POR to be retrieved.
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfDBEntries_T Number of documents of the SQL database.

Definition at line 1352 of file DBManager.cpp.

References iterateOnStatement(), OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, OPENTREP::Result::retrieveLocation(), and OPENTREP::Location::setCorrectedKeywords().

Referenced by OPENTREP::OPENTREP_Service::listByFaaCode().

◆ getPORByUNLOCode()

NbOfDBEntries_T OPENTREP::DBManager::getPORByUNLOCode ( soci::session & ioSociSession,
const UNLOCode_T & iUNLOCode,
LocationList_T & ioLocationList,
const bool iUniqueEntry )
static

Get the POR (point of reference), from the SQL database, corresponding to the given UN/LOCODE code.

Parameters
constSQLDBConnectionString_T& Connection string to the SQL DB.
constUNLOCode_T& The UN/LOCODE code (key) of the POR to be retrieved.
LocationList_T&List of (geographical) locations, if any, matching the given key.
constbool States whether a unique entry should be returned.
Returns
NbOfDBEntries_T Number of documents of the SQL database.

Definition at line 1418 of file DBManager.cpp.

References OPENTREP::Location::getKey(), OPENTREP::Location::getPageRank(), iterateOnStatement(), OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, OPENTREP::Result::retrieveLocation(), and OPENTREP::Location::setCorrectedKeywords().

Referenced by OPENTREP::getLocationList(), and OPENTREP::OPENTREP_Service::listByUNLOCode().

◆ getPORByUICCode()

NbOfDBEntries_T OPENTREP::DBManager::getPORByUICCode ( soci::session & ioSociSession,
const UICCode_T & iUICCode,
LocationList_T & ioLocationList )
static

Get the POR (point of reference), from the SQL database, corresponding to the given UIC code.

Parameters
constSQLDBConnectionString_T& Connection string to the SQL DB.
constUICCode_T& The UIC code (key) of the POR to be retrieved.
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfDBEntries_T Number of documents of the SQL database.

Definition at line 1525 of file DBManager.cpp.

References iterateOnStatement(), OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, OPENTREP::Result::retrieveLocation(), and OPENTREP::Location::setCorrectedKeywords().

Referenced by OPENTREP::OPENTREP_Service::listByUICCode().

◆ getPORByGeonameID()

NbOfDBEntries_T OPENTREP::DBManager::getPORByGeonameID ( soci::session & ioSociSession,
const GeonamesID_T & iGeonameID,
LocationList_T & ioLocationList )
static

Get the POR (point of reference), from the SQL database, corresponding to the given IATA code.

Parameters
constSQLDBConnectionString_T& Connection string to the SQL DB.
constGeonamesID_T& The GeonameID (key) of the POR to be retrieved.
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfDBEntries_T Number of documents of the SQL database.

Definition at line 1588 of file DBManager.cpp.

References iterateOnStatement(), OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, OPENTREP::Result::retrieveLocation(), and OPENTREP::Location::setCorrectedKeywords().

Referenced by OPENTREP::getLocationList(), and OPENTREP::OPENTREP_Service::listByGeonameID().

◆ insertPlaceInDB()

◆ updatePlaceInDB()

void OPENTREP::DBManager::updatePlaceInDB ( soci::session & ioSociSession,
const Place & iPlace )
static

Update the Xapian document ID field of the database row corresponding to the given Place object.

Parameters
soci::session&SOCI session handler.
constPlace& The place to be updated.

Definition at line 1067 of file DBManager.cpp.

References OPENTREP::Place::getDocID(), OPENTREP::Place::getIataCode(), OPENTREP_LOG_ERROR, and OPENTREP::Place::toString().

◆ prepareSelectAllBlobStatement()

std::string OPENTREP::DBManager::prepareSelectAllBlobStatement ( soci::session & ioSociSession,
soci::statement & ioSelectStatement )
static

Prepare (parse and put in cache) the SQL statement.

Parameters
soci::session&SOCI session handler.
soci::statement&SOCI SQL statement handler.
Returns
std::string The serialised place to be retrieved.

Definition at line 708 of file DBManager.cpp.

References OPENTREP_LOG_ERROR.

Referenced by displayAll().

◆ prepareSelectFromCoordStatement()

static void OPENTREP::DBManager::prepareSelectFromCoordStatement ( soci::session & ,
soci::statement & ,
const double & iLatitude,
const double & iLongitude )
static

Prepare (parse and put in cache) the SQL statement.

Parameters
soci::session&SOCI session handler.
soci::statement&SOCI SQL statement handler.
Place&The object corresponding to the place to be retrieved. It has to be given empty, and is filled by the method.

◆ iterateOnStatement()

bool OPENTREP::DBManager::iterateOnStatement ( soci::statement & ioStatement,
const std::string & iSerialisedPlaceStr )
static

Iterate on the SQL statement.

The SQL has to be already prepared.

Parameters
soci::statement&SOCI SQL statement handler.
conststd::string& The current serialised place, for debugging purpose.
Returns
bool Whether or not there are more rows to be fetched.

Definition at line 933 of file DBManager.cpp.

References OPENTREP_LOG_ERROR.

Referenced by displayAll(), getPORByFAACode(), getPORByGeonameID(), getPORByIATACode(), getPORByICAOCode(), getPORByUICCode(), and getPORByUNLOCode().


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