Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006
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
00015 #include <stdair/bom/AirlineStruct.hpp>
00016 #include <stdair/service/Logger.hpp>
00017
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
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
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
00105 if (iShouldDoReset == true) {
00106
00107 }
00108
00109
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
00127 ioSociSession.begin();
00128
00129
00130 std::string lAirlineCode;
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 ioSociSession.commit();
00146
00147
00148
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
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
00177 const bool shouldNotDoReset = false;
00178 hasStillData = iterateOnStatement (lSelectStatement, ioAirline,
00179 shouldNotDoReset);
00180
00181
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 }