Updated license
[anna.git] / source / dbms.mysql / Database.cpp
1 // ANNA - Anna is Not Nothingness Anymore
2 //
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
4 //
5 // https://bitbucket.org/testillano/anna
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 //     * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //     * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 //     * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Authors: eduardo.ramos.testillano@gmail.com
34 //          cisco.tierra@gmail.com
35
36
37 #include <string.h>
38
39 #include <anna/core/tracing/Logger.hpp>
40 #include <anna/core/tracing/TraceMethod.hpp>
41
42 #include <anna/dbms.mysql/mysql.hpp>
43 #include <anna/dbms.mysql/internal/sccs.hpp>
44
45 using namespace std;
46 using namespace anna;
47 using namespace anna::dbms;
48
49 mysql::Database::Database(const char* dbmsName, const char* host) :
50   dbms::Database(getClassName(), dbmsName) {
51   a_host = (host == NULL) ? NULL : strdup(host);
52   mysql::sccs::activate();
53 }
54
55 mysql::Database::Database(const char* componentName, const char* dbmsName, const char* host) :
56   dbms::Database(componentName, dbmsName) {
57   a_host = (host == NULL) ? NULL : strdup(host);
58   mysql::sccs::activate();
59 }
60
61 void mysql::Database::do_initialize()
62 throw(RuntimeException) {
63   LOGMETHOD(TraceMethod tm("anna::dbms::mysql::Database", "do_initialize", ANNA_FILE_LOCATION));
64   dbms::Database::do_initialize();
65 }
66
67 //----------------------------------------------------------------------------------
68 // Libera todos los manejadores asociados a este entorno.
69 //----------------------------------------------------------------------------------
70 mysql::Database::~Database() {
71   LOGMETHOD(TraceMethod tm("anna::dbms::mysql::Database", "~Database", ANNA_FILE_LOCATION));
72
73   if(a_host != NULL)
74     free(a_host);
75 }
76
77 dbms::Connection* mysql::Database::allocateConnection(const std::string& name, const char* user, const char* password)
78 throw(RuntimeException) {
79   return new Connection(*this, name, user, password);
80 }
81
82 dbms::Statement* mysql::Database::allocateStatement(const char* name, const std::string& expression, const bool isCritical)
83 throw(RuntimeException) {
84   return new Statement(*this, name, expression, isCritical);
85 }
86
87 dbms::InputBind* mysql::Database::allocateInputBind(const char* name, Data& data)
88 throw(RuntimeException) {
89   return new InputBind(name, data);
90 }
91
92 void mysql::Database::deallocate(dbms::InputBind* inputBind)
93 throw() {
94   delete(InputBind*) inputBind;
95 }
96
97 dbms::OutputBind* mysql::Database::allocateOutputBind(const char* name, Data& data)
98 throw(RuntimeException) {
99   return new OutputBind(name, data);
100 }
101
102 void mysql::Database::deallocate(dbms::OutputBind* outputBind)
103 throw() {
104   delete(OutputBind*) outputBind;
105 }