$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 // SOCI 00007 #if defined(SOCI_HEADERS_BURIED) 00008 #include <soci/core/soci.h> 00009 #include <soci/backends/mysql/soci-mysql.h> 00010 #else // SOCI_HEADERS_BURIED 00011 #include <soci/soci.h> 00012 #include <soci/mysql/soci-mysql.h> 00013 #endif // SOCI_HEADERS_BURIED 00014 // StdAir 00015 #include <stdair/bom/AirlineStruct.hpp> 00016 #include <stdair/service/Logger.hpp> 00017 // TraDemGen 00018 #include <trademgen/command/DBManager.hpp> 00019 00020 namespace TRADEMGEN { 00021 00022 // ////////////////////////////////////////////////////////////////////// 00023 void DBManager:: 00024 prepareSelectStatement (stdair::DBSession_T& ioSociSession, 00025 stdair::DBRequestStatement_T& ioSelectStatement, 00026 stdair::AirlineStruct& ioAirline) { 00027 00028 try { 00029 00030 // Instanciate a SQL statement (no request is performed at that stage) 00044 } catch (std::exception const& lException) { 00045 STDAIR_LOG_ERROR ("Error: " << lException.what()); 00046 throw stdair::SQLDatabaseException (lException.what()); 00047 } 00048 } 00049 00050 // ////////////////////////////////////////////////////////////////////// 00051 void DBManager:: 00052 prepareSelectOnAirlineCodeStatement (stdair::DBSession_T& ioSociSession, 00053 stdair::DBRequestStatement_T& ioSelectStatement, 00054 const stdair::AirlineCode_T& iAirlineCode, 00055 stdair::AirlineStruct& ioAirline) { 00056 00057 try { 00058 00059 // Instanciate a SQL statement (no request is performed at that stage) 00090 } catch (std::exception const& lException) { 00091 STDAIR_LOG_ERROR ("Error: " << lException.what()); 00092 throw stdair::SQLDatabaseException (lException.what()); 00093 } 00094 } 00095 00096 // ////////////////////////////////////////////////////////////////////// 00097 bool DBManager::iterateOnStatement (stdair::DBRequestStatement_T& ioStatement, 00098 stdair::AirlineStruct& ioAirline, 00099 const bool iShouldDoReset) { 00100 bool hasStillData = false; 00101 00102 try { 00103 00104 // Reset the list of names of the given Airline object 00105 if (iShouldDoReset == true) { 00106 // ioAirline.resetMatrix(); 00107 } 00108 00109 // Retrieve the next row of Airline object 00110 hasStillData = ioStatement.fetch(); 00111 00112 } catch (std::exception const& lException) { 00113 STDAIR_LOG_ERROR ("Error: " << lException.what()); 00114 throw stdair::SQLDatabaseException (lException.what()); 00115 } 00116 00117 return hasStillData; 00118 } 00119 00120 // ////////////////////////////////////////////////////////////////////// 00121 void DBManager::updateAirlineInDB (stdair::DBSession_T& ioSociSession, 00122 const stdair::AirlineStruct& iAirline) { 00123 00124 try { 00125 00126 // Begin a transaction on the database 00127 ioSociSession.begin(); 00128 00129 // Instanciate a SQL statement (no request is performed at that stage) 00130 std::string lAirlineCode; 00131 /* 00132 stdair::DBRequestStatement_T lUpdateStatement = 00133 (ioSociSession.prepare 00134 << "update ref_airline_details " 00135 << "set xapian_docid = :xapian_docid " 00136 << "where code = :code", soci::use (lDocID), soci::use (lAirlineCode)); 00137 00138 // Execute the SQL query 00139 lDocID = iAirline.getDocID(); 00140 lAirlineCode = iAirline.getAirlineCode(); 00141 lUpdateStatement.execute (true); 00142 */ 00143 00144 // Commit the transaction on the database 00145 ioSociSession.commit(); 00146 00147 // Debug 00148 // TRADEMGEN_LOG_DEBUG ("[" << lDocID << "] " << iAirline); 00149 00150 } catch (std::exception const& lException) { 00151 STDAIR_LOG_ERROR ("Error: " << lException.what()); 00152 throw stdair::SQLDatabaseException (lException.what()); 00153 } 00154 } 00155 00156 // ////////////////////////////////////////////////////////////////////// 00157 bool DBManager::retrieveAirline (stdair::DBSession_T& ioSociSession, 00158 const stdair::AirlineCode_T& iAirlineCode, 00159 stdair::AirlineStruct& ioAirline) { 00160 bool oHasRetrievedAirline = false; 00161 00162 try { 00163 00164 // Prepare the SQL request corresponding to the select statement 00165 stdair::DBRequestStatement_T lSelectStatement (ioSociSession); 00166 DBManager::prepareSelectOnAirlineCodeStatement (ioSociSession, 00167 lSelectStatement, 00168 iAirlineCode, ioAirline); 00169 const bool shouldDoReset = true; 00170 bool hasStillData = iterateOnStatement (lSelectStatement, ioAirline, 00171 shouldDoReset); 00172 if (hasStillData == true) { 00173 oHasRetrievedAirline = true; 00174 } 00175 00176 // Sanity check 00177 const bool shouldNotDoReset = false; 00178 hasStillData = iterateOnStatement (lSelectStatement, ioAirline, 00179 shouldNotDoReset); 00180 // Debug 00181 // STDAIR_LOG_DEBUG ("[" << iDocID << "] " << ioAirline); 00182 00183 } catch (std::exception const& lException) { 00184 STDAIR_LOG_ERROR ("Error: " << lException.what()); 00185 throw stdair::SQLDatabaseException (lException.what()); 00186 } 00187 00188 return oHasRetrievedAirline; 00189 } 00190 00191 }