X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Fdbms%2FDelivery.cpp;fp=source%2Fdbms%2FDelivery.cpp;h=8ae88e4bdd0515c1a5928a9bdd52132eda172ace;hb=78be86969d2f26a9084b0c4af6ce43d5fa4ed3fd;hp=0000000000000000000000000000000000000000;hpb=a3b95648bd76140ef55e0b5941d423eee6c3856f;p=anna.git diff --git a/source/dbms/Delivery.cpp b/source/dbms/Delivery.cpp new file mode 100644 index 0000000..8ae88e4 --- /dev/null +++ b/source/dbms/Delivery.cpp @@ -0,0 +1,66 @@ +// 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 + +using namespace std; +using namespace anna; + +void dbms::Delivery::createConnections(dbms::Database& database, const char* prefixName, const char* user, const char* password, const int n) +throw(RuntimeException, dbms::DatabaseException) { + string name; + + for(int i = 0; i < n; i ++) { + name = prefixName; + name += functions::asString("%04d", i); + this->add(database.createConnection(name.c_str(), user, password)); + } + + a_iiConnection = this->begin(); +} + +dbms::Connection& dbms::Delivery::getConnection() +throw(RuntimeException) { + return *(static_cast (comm::Delivery::apply())); +} + +//-------------------------------------------------------------------------------------------------- +// Se invoca desde la seccion critica establecida en comm::Delivery::apply. +// +// (0) Si no hay registrada ninguna conexion +//-------------------------------------------------------------------------------------------------- +comm::Resource* dbms::Delivery::do_apply() +throw(RuntimeException) { + iterator maxii = end(); + + if(a_iiConnection == maxii) // (0) + return NULL; + + iterator init = a_iiConnection; + Connection* result = NULL; + Connection* w; + + do { + w = connection(a_iiConnection); + + if(a_iiConnection == maxii) + a_iiConnection = begin(); + + if(w->isAvailable() == true && w->isEnabled() == true) { + result = w; + break; + } + } while(a_iiConnection != init); + + return result; +}