--- /dev/null
+// 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 <anna/core/tracing/TraceMethod.hpp>
+#include <anna/core/functions.hpp>
+
+#include <anna/dbms/Database.hpp>
+#include <anna/dbms/Delivery.hpp>
+#include <anna/dbms/Connection.hpp>
+
+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 <dbms::Connection*>(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;
+}