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 &) |
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:
Definition at line 42 of file DBManager.hpp.
|
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.
const | DBType& The SQL database type (e.g., SQLite3, MySQL). |
const | SQLDBConnectionString_T& Connection string for the SQL database. |
const | const DeploymentNumber_T& Deployment number |
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().
|
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.
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. const | DBType& The SQL database type (e.g., SQLite3, MySQL). |
const | SQLDBConnectionString_T& Connection string for the SQL database. |
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().
|
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.
const | DBType& The SQL database type (e.g., SQLite3, MySQL). |
const | SQLDBConnectionString_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().
|
static |
Create the database tables (e.g., 'optd_por' table).
If tables were previously existing, they are deleted and re-created.
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().
|
static |
Create the database indexes.
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().
|
static |
Retrieve the number of POR (points of reference) within the SQL database.
Definition at line 1106 of file DBManager.cpp.
References OPENTREP_LOG_ERROR.
Referenced by OPENTREP::OPENTREP_Service::getNbOfPORFromDB().
|
static |
Dump all the POR (points of reference) of the SQL database.
Definition at line 1132 of file DBManager.cpp.
References iterateOnStatement(), OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, and prepareSelectAllBlobStatement().
|
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.
const | SQLDBConnectionString_T& Connection string to the SQL DB. |
const | IATACode_T& The IATA code (key) of the POR to be retrieved. |
LocationList_T& | List of (geographical) locations, if any, matching the given key. |
const | bool States whether a unique entry should be returned. |
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().
|
static |
Get the POR (point of reference), from the SQL database, corresponding to the given ICAO code.
const | SQLDBConnectionString_T& Connection string to the SQL DB. |
const | ICAOCode_T& The ICAO code (key) of the POR to be retrieved. |
LocationList_T& | List of (geographical) locations, if any, matching the given key. |
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().
|
static |
Get the POR (point of reference), from the SQL database, corresponding to the given FAA code.
const | SQLDBConnectionString_T& Connection string to the SQL DB. |
const | FAACode_T& The FAA code (key) of the POR to be retrieved. |
LocationList_T& | List of (geographical) locations, if any, matching the given key. |
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().
|
static |
Get the POR (point of reference), from the SQL database, corresponding to the given UN/LOCODE code.
const | SQLDBConnectionString_T& Connection string to the SQL DB. |
const | UNLOCode_T& The UN/LOCODE code (key) of the POR to be retrieved. |
LocationList_T& | List of (geographical) locations, if any, matching the given key. |
const | bool States whether a unique entry should be returned. |
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().
|
static |
Get the POR (point of reference), from the SQL database, corresponding to the given UIC code.
const | SQLDBConnectionString_T& Connection string to the SQL DB. |
const | UICCode_T& The UIC code (key) of the POR to be retrieved. |
LocationList_T& | List of (geographical) locations, if any, matching the given key. |
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().
|
static |
Get the POR (point of reference), from the SQL database, corresponding to the given IATA code.
const | SQLDBConnectionString_T& Connection string to the SQL DB. |
const | GeonamesID_T& The GeonameID (key) of the POR to be retrieved. |
LocationList_T& | List of (geographical) locations, if any, matching the given key. |
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().
|
static |
Insert into the SQL database the document corresponding to the given Place object.
soci::session& | SOCI session handler. |
const | Place& The place to be inserted. |
Definition at line 954 of file DBManager.cpp.
References OPENTREP::Place::getDateEnd(), OPENTREP::Place::getDateFrom(), OPENTREP::Place::getEnvelopeID(), OPENTREP::Place::getFaaCode(), OPENTREP::Place::getGeonamesID(), OPENTREP::Place::getIataCode(), OPENTREP::Place::getIataType(), OPENTREP::Place::getIcaoCode(), OPENTREP::Place::getKey(), OPENTREP::Place::getRawDataString(), OPENTREP::IATAType::getTypeAsString(), OPENTREP::Place::getUICCodeList(), OPENTREP::Place::getUNLOCodeList(), OPENTREP::Place::isGeonames(), OPENTREP_LOG_ERROR, OPENTREP::LocationKey::toString(), and OPENTREP::Place::toString().
|
static |
Update the Xapian document ID field of the database row corresponding to the given Place object.
soci::session& | SOCI session handler. |
const | Place& 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().
|
static |
Prepare (parse and put in cache) the SQL statement.
soci::session& | SOCI session handler. |
soci::statement& | SOCI SQL statement handler. |
Definition at line 708 of file DBManager.cpp.
References OPENTREP_LOG_ERROR.
Referenced by displayAll().
|
static |
Prepare (parse and put in cache) the SQL statement.
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. |
|
static |
Iterate on the SQL statement.
The SQL has to be already prepared.
soci::statement& | SOCI SQL statement handler. |
const | std::string& The current serialised place, for debugging purpose. |
Definition at line 933 of file DBManager.cpp.
References OPENTREP_LOG_ERROR.
Referenced by displayAll(), getPORByFAACode(), getPORByGeonameID(), getPORByIATACode(), getPORByICAOCode(), getPORByUICCode(), and getPORByUNLOCode().