]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/store/firebird/firebird_store.cpp
Remove const qualifier from function definitions
[stg.git] / projects / stargazer / plugins / store / firebird / firebird_store.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
19  */
20
21 /*
22  *  This file contains a realization of a base firebird-storage plugin class
23  *
24  *  $Revision: 1.18 $
25  *  $Date: 2010/01/08 16:00:45 $
26  *
27  */
28
29 #include <string>
30 #include <vector>
31 #include <algorithm>
32
33 using namespace std;
34
35 #include "firebird_store.h"
36 #include "stg/ibpp.h"
37
38 class FIREBIRD_STORE_CREATOR
39 {
40 public:
41     FIREBIRD_STORE_CREATOR()
42         : frb(new FIREBIRD_STORE())
43         {
44         };
45     ~FIREBIRD_STORE_CREATOR()
46         {
47         delete frb;
48         };
49     FIREBIRD_STORE * GetStore() { return frb; };
50 private:
51     FIREBIRD_STORE * frb;
52 } frsc;
53
54 //-----------------------------------------------------------------------------
55 STORE * GetStore()
56 {
57 return frsc.GetStore();
58 }
59 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
62 FIREBIRD_STORE::FIREBIRD_STORE()
63 {
64 db_server = "localhost";
65 db_database = "/var/stg/stargazer.fdb";
66 db_user = "stg";
67 db_password = "123456";
68 version = "firebird_store v.1.4";
69 pthread_mutex_init(&mutex, NULL);
70
71 // Advanced settings defaults
72
73 til = IBPP::ilConcurrency;
74 tlr = IBPP::lrWait;
75 }
76 //-----------------------------------------------------------------------------
77 FIREBIRD_STORE::~FIREBIRD_STORE()
78 {
79 db->Disconnect();
80 }
81 //-----------------------------------------------------------------------------
82 int FIREBIRD_STORE::ParseSettings()
83 {
84 vector<PARAM_VALUE>::iterator i;
85 string s;
86
87 for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i)
88     {
89     s = i->param;
90     transform(s.begin(), s.end(), s.begin(), ToLower());
91     if (s == "server")
92         {
93         db_server = *(i->value.begin());
94         }
95     if (s == "database")
96         {
97         db_database = *(i->value.begin());
98         }
99     if (s == "user")
100         {
101         db_user = *(i->value.begin());
102         }
103     if (s == "password")
104         {
105         db_password = *(i->value.begin());
106         }
107
108     // Advanced settings block
109
110     if (s == "isolationLevel")
111         {
112         if (*(i->value.begin()) == "Concurrency")
113             {
114             til = IBPP::ilConcurrency;
115             }
116         else if (*(i->value.begin()) == "DirtyRead")
117             {
118             til = IBPP::ilReadDirty;
119             }
120         else if (*(i->value.begin()) == "ReadCommitted")
121             {
122             til = IBPP::ilReadCommitted;
123             }
124         else if (*(i->value.begin()) == "Consistency")
125             {
126             til = IBPP::ilConsistency;
127             }
128         }
129     if (s == "lockResolution")
130         {
131         if (*(i->value.begin()) == "Wait")
132             {
133             tlr = IBPP::lrWait;
134             }
135         else if (*(i->value.begin()) == "NoWait")
136             {
137             tlr = IBPP::lrNoWait;
138             }
139         }
140     }
141
142 try
143     {
144     db = IBPP::DatabaseFactory(db_server, db_database, db_user, db_password, "", "KOI8U", "");
145     db->Connect();
146     }
147 catch (IBPP::Exception & ex)
148     {
149     strError = "IBPP exception";
150     printfd(__FILE__, ex.what());
151     return -1;
152     }
153
154 return 0;
155 }
156 //-----------------------------------------------------------------------------