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) {
37 if(connection == NULL) {
38 std::string msg(ssaa->asString());
41 msg += " | Cannot execute this method with dbms::Connection == NULL";
42 throw RuntimeException(msg, ANNA_FILE_LOCATION);
45 dbms::Statement* statement(getStatement());
47 if(statement == NULL) {
48 std::string msg(ssaa->asString());
51 msg += " | Has no SQL sentence associated";
52 throw RuntimeException(msg, ANNA_FILE_LOCATION);
56 string msg("dbos::Accesor::load | ");
57 msg += ssaa->asString();
60 Logger::debug(msg, ANNA_FILE_LOCATION);
62 dbms::ResultCode resultCode = connection->execute(statement); // (1)
64 if(resultCode.notFound() == true) {
65 if(a_emodeIsNull == true) {
66 if(ssaa->getErrorCode() != StorageArea::NoExceptionWhenNotFound) {
67 std::string msg(ssaa->asString());
70 msg += " | Register not found";
71 RuntimeException ex(msg, ANNA_FILE_LOCATION);
72 ex.setErrorCode(ssaa->getErrorCode());
77 std::string msg(ssaa->asString());
80 msg += " | Register not found";
82 if(a_exceptionMode == Exception::Mode::Ignore) {
83 Logger::debug(msg, ANNA_FILE_LOCATION);
87 if(a_exceptionMode == Exception::Mode::Throw) {
88 RuntimeException ex(msg, ANNA_FILE_LOCATION);
89 ex.setErrorCode(ssaa->getErrorCode());
91 } else if(Logger::isActive(Logger::Warning)) {
92 Logger::warning(msg, ANNA_FILE_LOCATION);
97 if(resultCode.successful() == false) {
98 string msg(ssaa->getName());
101 throw dbms::DatabaseException(msg, resultCode, ANNA_FILE_LOCATION);
104 return statement->fetch();