X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fdbos%2FAccesor.cpp;fp=source%2Fdbos%2FAccesor.cpp;h=f77d2aaf3ff60b4ba80bfdade64d22e3c906476b;hb=78be86969d2f26a9084b0c4af6ce43d5fa4ed3fd;hp=0000000000000000000000000000000000000000;hpb=a3b95648bd76140ef55e0b5941d423eee6c3856f;p=anna.git diff --git a/source/dbos/Accesor.cpp b/source/dbos/Accesor.cpp new file mode 100644 index 0000000..f77d2aa --- /dev/null +++ b/source/dbos/Accesor.cpp @@ -0,0 +1,105 @@ +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // + + +#include + +#include +#include +#include +#include + +#include +#include + +using namespace std; +using namespace anna; + +/*virtual*/ +dbos::Accesor::~Accesor() { + if(a_statement != NULL && a_database != NULL) + a_database->releaseStatement(a_statement); +} + +//------------------------------------------------------------------------------------------ +// Transfiere la informacion del medio fisico al 'Loader' concreto. +// +// (1) Ojo!! Ejecuta la sentencia SQL y carga el primer registro en el area de intercambio +// Slo habr�que invocar al 'fetch' para coger los siguientes registros' +//------------------------------------------------------------------------------------------ +bool dbos::Accesor::load(dbms::Connection* connection, const dbos::StorageArea* ssaa) +throw(RuntimeException, dbms::DatabaseException) { + + if(connection == NULL) { + std::string msg(ssaa->asString()); + msg += " | "; + msg += asString(); + msg += " | Cannot execute this method with dbms::Connection == NULL"; + throw RuntimeException(msg, ANNA_FILE_LOCATION); + } + + dbms::Statement* statement(getStatement()); + + if(statement == NULL) { + std::string msg(ssaa->asString()); + msg += " | "; + msg += asString(); + msg += " | Has no SQL sentence associated"; + throw RuntimeException(msg, ANNA_FILE_LOCATION); + } + + LOGDEBUG( + string msg("dbos::Accesor::load | "); + msg += ssaa->asString(); + msg += " | "; + msg += asString(); + Logger::debug(msg, ANNA_FILE_LOCATION); + ); + dbms::ResultCode resultCode = connection->execute(statement); // (1) + + if(resultCode.notFound() == true) { + if(a_emodeIsNull == true) { + if(ssaa->getErrorCode() != StorageArea::NoExceptionWhenNotFound) { + std::string msg(ssaa->asString()); + msg += " | "; + msg += asString(); + msg += " | Register not found"; + RuntimeException ex(msg, ANNA_FILE_LOCATION); + ex.setErrorCode(ssaa->getErrorCode()); + throw ex; + } else + return false; + } else { + std::string msg(ssaa->asString()); + msg += " | "; + msg += asString(); + msg += " | Register not found"; + + if(a_exceptionMode == Exception::Mode::Ignore) { + Logger::debug(msg, ANNA_FILE_LOCATION); + return false; + } + + if(a_exceptionMode == Exception::Mode::Throw) { + RuntimeException ex(msg, ANNA_FILE_LOCATION); + ex.setErrorCode(ssaa->getErrorCode()); + throw ex; + } else if(Logger::isActive(Logger::Warning)) { + Logger::warning(msg, ANNA_FILE_LOCATION); + } + } + } + + if(resultCode.successful() == false) { + string msg(ssaa->getName()); + msg += " | "; + msg += asString(); + throw dbms::DatabaseException(msg, resultCode, ANNA_FILE_LOCATION); + } + + return statement->fetch(); +}