OpenTREP Logo  0.08.01
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
OPENTREP_ServiceContext.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6#include <string>
7#include <istream>
8#include <ostream>
9#include <sstream>
10// OpenTrep
15
16namespace OPENTREP {
17
41 // //////////////////////////////////////////////////////////////////////
42 void OPENTREP_ServiceContext::
43 updateXapianAndSQLDBConnectionWithDeploymentNumber() {
47 if (_sqlDBType == DBType::NODB) {
48 // Nothing more to be done here
49
50 } else if (_sqlDBType == DBType::SQLITE3) {
51 std::ostringstream oStr;
52 oStr << _sqlDBConnectionStringWPfxDBName;
53 oStr << _deploymentNumber;
54 _sqlDBConnectionString = SQLDBConnectionString_T (oStr.str());
55
56 } else if (_sqlDBType == DBType::MYSQL) {
65 const StringMap_T& lStrMap =
66 parseMySQLConnectionString (_sqlDBConnectionStringWPfxDBName);
67
72 const SQLDBConnectionString_T& lSQLDBConnStr =
73 buildMySQLConnectionString (lStrMap, _deploymentNumber);
74
75 // Store the newly formed SQL connection string
76 _sqlDBConnectionString = lSQLDBConnStr;
77
78 } else if (_sqlDBType == DBType::PG) {
84 const StringMap_T& lStrMap =
85 parsePGConnectionString (_sqlDBConnectionStringWPfxDBName);
86
91 const SQLDBConnectionString_T& lSQLDBConnStr =
92 buildPGConnectionString (lStrMap, _deploymentNumber);
93
94 // Store the newly formed SQL connection string
95 _sqlDBConnectionString = lSQLDBConnStr;
96 }
97
101 std::ostringstream oStr;
102 oStr << _travelDBFilePathPrefix;
103 oStr << _deploymentNumber;
104 _travelDBFilePath = TravelDBFilePath_T (oStr.str());
105 }
106
107 // //////////////////////////////////////////////////////////////////////
108 OPENTREP_ServiceContext::OPENTREP_ServiceContext()
109 : _world (NULL),
110 _porFilePath (DEFAULT_OPENTREP_POR_FILEPATH),
111 _deploymentNumber (DEFAULT_OPENTREP_DEPLOYMENT_NUMBER),
112 _travelDBFilePathPrefix (DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH),
113 _travelDBFilePath (DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH),
114 _sqlDBType (DEFAULT_OPENTREP_SQL_DB_TYPE),
115 _sqlDBConnectionStringWPfxDBName (DEFAULT_OPENTREP_SQLITE_DB_FILEPATH),
116 _sqlDBConnectionString (DEFAULT_OPENTREP_SQLITE_DB_FILEPATH),
117 _shouldIndexNonIATAPOR (DEFAULT_OPENTREP_INCLUDE_NONIATA_POR),
118 _shouldIndexPORInXapian (DEFAULT_OPENTREP_INDEX_IN_XAPIAN),
119 _shouldAddPORInSQLDB (DEFAULT_OPENTREP_ADD_IN_DB) {
120 assert (false);
121 }
122
123 // //////////////////////////////////////////////////////////////////////
124 OPENTREP_ServiceContext::
125 OPENTREP_ServiceContext (const TravelDBFilePath_T& iTravelDBFilePath,
126 const DBType& iSQLDBType,
127 const SQLDBConnectionString_T& iSQLDBConnStr,
128 const DeploymentNumber_T& iDeploymentNumber)
129 : _world (NULL),
130 _porFilePath (DEFAULT_OPENTREP_POR_FILEPATH),
131 _deploymentNumber (iDeploymentNumber),
132 _travelDBFilePathPrefix (iTravelDBFilePath),
133 _travelDBFilePath (iTravelDBFilePath), _sqlDBType (iSQLDBType),
134 _sqlDBConnectionStringWPfxDBName (iSQLDBConnStr),
135 _sqlDBConnectionString (iSQLDBConnStr),
136 _shouldIndexNonIATAPOR (DEFAULT_OPENTREP_INCLUDE_NONIATA_POR),
137 _shouldIndexPORInXapian (DEFAULT_OPENTREP_INDEX_IN_XAPIAN),
138 _shouldAddPORInSQLDB (DEFAULT_OPENTREP_ADD_IN_DB) {
139 updateXapianAndSQLDBConnectionWithDeploymentNumber();
140 }
141
142 // //////////////////////////////////////////////////////////////////////
143 OPENTREP_ServiceContext::
144 OPENTREP_ServiceContext (const PORFilePath_T& iPORFilePath,
145 const TravelDBFilePath_T& iTravelDBFilePath,
146 const DBType& iSQLDBType,
147 const SQLDBConnectionString_T& iSQLDBConnStr,
148 const DeploymentNumber_T& iDeploymentNumber,
149 const shouldIndexNonIATAPOR_T& iShouldIndexNonIATAPOR,
150 const shouldIndexPORInXapian_T& iShouldIdxPORInXapian,
151 const shouldAddPORInSQLDB_T& iShouldAddPORInSQLDB)
152 : _world (NULL), _porFilePath (iPORFilePath),
153 _deploymentNumber (iDeploymentNumber),
154 _travelDBFilePathPrefix (iTravelDBFilePath),
155 _travelDBFilePath (iTravelDBFilePath), _sqlDBType (iSQLDBType),
156 _sqlDBConnectionStringWPfxDBName (iSQLDBConnStr),
157 _sqlDBConnectionString (iSQLDBConnStr),
158 _shouldIndexNonIATAPOR (iShouldIndexNonIATAPOR),
159 _shouldIndexPORInXapian (iShouldIdxPORInXapian),
160 _shouldAddPORInSQLDB (iShouldAddPORInSQLDB) {
161 updateXapianAndSQLDBConnectionWithDeploymentNumber();
162 }
163
164 // //////////////////////////////////////////////////////////////////////
165 OPENTREP_ServiceContext::~OPENTREP_ServiceContext() {
166 }
167
168 // //////////////////////////////////////////////////////////////////////
170 assert (_world != NULL);
171 return *_world;
172 }
173
174 // //////////////////////////////////////////////////////////////////////
175 const std::string OPENTREP_ServiceContext::shortDisplay() const {
176 std::ostringstream oStr;
177 oStr << "OPENTREP_ServiceContext: "
178 << "file-path of the POR file: " << _porFilePath
179 << "; deployment number/version: " << _deploymentNumber
180 << "; Directory prefix of Xapian index/database: "
181 << _travelDBFilePathPrefix
182 << "; Actual directory of Xapian index/database: " << _travelDBFilePath
183 << "; SQL database (" << _sqlDBType.describe()
184 << ") connection string with DB name prefix: "
185 << _sqlDBConnectionStringWPfxDBName
186 << "); Connection string with actual DB name: "
187 << _sqlDBConnectionString
188 << "; should include non-IATA POR: " << _shouldIndexNonIATAPOR
189 << "; should index POR in Xapian: " << _shouldIndexPORInXapian
190 << "; should insert POR into the SQL DB: " << _shouldAddPORInSQLDB
191 << std::endl;
192 return oStr.str();
193 }
194
195 // //////////////////////////////////////////////////////////////////////
196 const std::string OPENTREP_ServiceContext::display() const {
197 std::ostringstream oStr;
198 oStr << shortDisplay();
199 if (_world != NULL) {
200 oStr << _world->display();
201 }
202 return oStr.str();
203 }
204
205}
const std::string DEFAULT_OPENTREP_SQLITE_DB_FILEPATH
SQLDBConnectionString_T buildMySQLConnectionString(const StringMap_T &iStringMap, const DeploymentNumber_T &iDeploymentNumber)
SQLDBConnectionString_T buildPGConnectionString(const StringMap_T &iStringMap, const DeploymentNumber_T &iDeploymentNumber)
const bool DEFAULT_OPENTREP_INCLUDE_NONIATA_POR
const std::string DEFAULT_OPENTREP_SQL_DB_TYPE
StringMap_T parseMySQLConnectionString(const SQLDBConnectionString_T &iSQLDBConnStr)
const bool DEFAULT_OPENTREP_INDEX_IN_XAPIAN
const unsigned short DEFAULT_OPENTREP_DEPLOYMENT_NUMBER
const std::string DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH
StringMap_T parsePGConnectionString(const SQLDBConnectionString_T &iSQLDBConnStr)
const bool DEFAULT_OPENTREP_ADD_IN_DB
const std::string DEFAULT_OPENTREP_POR_FILEPATH
std::map< const std::string, std::string > StringMap_T
Definition Utilities.hpp:43