Add no-deprecated to warnings due to dynamic exceptions.
[anna.git] / source / dbms / Delivery.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #include <anna/core/tracing/TraceMethod.hpp>
10 #include <anna/core/functions.hpp>
11
12 #include <anna/dbms/Database.hpp>
13 #include <anna/dbms/Delivery.hpp>
14 #include <anna/dbms/Connection.hpp>
15
16 using namespace std;
17 using namespace anna;
18
19 void  dbms::Delivery::createConnections(dbms::Database& database, const char* prefixName, const char* user, const char* password, const int n)
20 throw(RuntimeException, dbms::DatabaseException) {
21   string name;
22
23   for(int i = 0; i < n;  i ++) {
24     name = prefixName;
25     name += functions::asString("%04d", i);
26     this->add(database.createConnection(name.c_str(), user, password));
27   }
28
29   a_iiConnection = this->begin();
30 }
31
32 dbms::Connection& dbms::Delivery::getConnection()
33 throw(RuntimeException) {
34   return *(static_cast <dbms::Connection*>(comm::Delivery::apply()));
35 }
36
37 //--------------------------------------------------------------------------------------------------
38 // Se invoca desde la seccion critica establecida en comm::Delivery::apply.
39 //
40 // (0) Si no hay registrada ninguna conexion
41 //--------------------------------------------------------------------------------------------------
42 comm::Resource* dbms::Delivery::do_apply()
43 throw(RuntimeException) {
44   iterator maxii = end();
45
46   if(a_iiConnection == maxii)                                          // (0)
47     return NULL;
48
49   iterator init = a_iiConnection;
50   Connection* result = NULL;
51   Connection* w;
52
53   do {
54     w = connection(a_iiConnection);
55
56     if(a_iiConnection == maxii)
57       a_iiConnection = begin();
58
59     if(w->isAvailable() == true && w->isEnabled() == true) {
60       result = w;
61       break;
62     }
63   } while(a_iiConnection != init);
64
65   return result;
66 }