1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #include <anna/core/tracing/Logger.hpp>
11 #include <anna/dbms/Database.hpp>
12 #include <anna/dbms/Connection.hpp>
13 #include <anna/dbms/Statement.hpp>
14 #include <anna/dbms/ResultCode.hpp>
16 #include <anna/dbos/Accesor.hpp>
17 #include <anna/dbos/StorageArea.hpp>
23 dbos::Accesor::~Accesor() {
24 if(a_statement != NULL && a_database != NULL)
25 a_database->releaseStatement(a_statement);
28 //------------------------------------------------------------------------------------------
29 // Transfiere la informacion del medio fisico al 'Loader' concreto.
31 // (1) Ojo!! Ejecuta la sentencia SQL y carga el primer registro en el area de intercambio
32 // Slo habr�que invocar al 'fetch' para coger los siguientes registros'
33 //------------------------------------------------------------------------------------------
34 bool dbos::Accesor::load(dbms::Connection* connection, const dbos::StorageArea* ssaa)
35 throw(RuntimeException, dbms::DatabaseException) {
38 if(connection == NULL) {
39 std::string msg(ssaa->asString());
42 msg += " | Cannot execute this method with dbms::Connection == NULL";
43 throw RuntimeException(msg, ANNA_FILE_LOCATION);
46 dbms::Statement* statement(getStatement());
48 if(statement == NULL) {
49 std::string msg(ssaa->asString());
52 msg += " | Has no SQL sentence associated";
53 throw RuntimeException(msg, ANNA_FILE_LOCATION);
57 string msg("dbos::Accesor::load | ");
58 msg += ssaa->asString();
61 Logger::debug(msg, ANNA_FILE_LOCATION);
63 dbms::ResultCode resultCode = connection->execute(statement); // (1)
65 if(resultCode.notFound() == true) {
66 if(a_emodeIsNull == true) {
67 if(ssaa->getErrorCode() != StorageArea::NoExceptionWhenNotFound) {
68 std::string msg(ssaa->asString());
71 msg += " | Register not found";
72 RuntimeException ex(msg, ANNA_FILE_LOCATION);
73 ex.setErrorCode(ssaa->getErrorCode());
78 std::string msg(ssaa->asString());
81 msg += " | Register not found";
83 if(a_exceptionMode == Exception::Mode::Ignore) {
84 Logger::debug(msg, ANNA_FILE_LOCATION);
88 if(a_exceptionMode == Exception::Mode::Throw) {
89 RuntimeException ex(msg, ANNA_FILE_LOCATION);
90 ex.setErrorCode(ssaa->getErrorCode());
92 } else if(Logger::isActive(Logger::Warning)) {
93 Logger::warning(msg, ANNA_FILE_LOCATION);
98 if(resultCode.successful() == false) {
99 string msg(ssaa->getName());
102 throw dbms::DatabaseException(msg, resultCode, ANNA_FILE_LOCATION);
105 return statement->fetch();