]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/store/firebird/firebird_store.cpp
e5c7b0b16343ee2655b39f2a670bda0063f88a8a
[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 #include "stg/ibpp.h"
34 #include "stg/plugin_creator.h"
35 #include "firebird_store.h"
36
37 using namespace std;
38
39 PLUGIN_CREATOR<FIREBIRD_STORE> frsc;
40 //-----------------------------------------------------------------------------
41 STORE * GetStore()
42 {
43 return frsc.GetPlugin();
44 }
45 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 FIREBIRD_STORE::FIREBIRD_STORE()
49     : version("firebird_store v.1.4"),
50       strError(),
51       db_server("localhost"),
52       db_database("/var/stg/stargazer.fdb"),
53       db_user("stg"),
54       db_password("123456"),
55       settings(),
56       db(),
57       mutex(),
58       til(IBPP::ilConcurrency),
59       tlr(IBPP::lrWait),
60       logger(GetPluginLogger(GetStgLogger(), "store_firebird"))
61 {
62 pthread_mutex_init(&mutex, NULL);
63 }
64 //-----------------------------------------------------------------------------
65 FIREBIRD_STORE::~FIREBIRD_STORE()
66 {
67 db->Disconnect();
68 }
69 //-----------------------------------------------------------------------------
70 int FIREBIRD_STORE::ParseSettings()
71 {
72 vector<PARAM_VALUE>::iterator i;
73 string s;
74
75 for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i)
76     {
77     s = i->param;
78     transform(s.begin(), s.end(), s.begin(), ToLower());
79     if (s == "server")
80         {
81         db_server = *(i->value.begin());
82         }
83     if (s == "database")
84         {
85         db_database = *(i->value.begin());
86         }
87     if (s == "user")
88         {
89         db_user = *(i->value.begin());
90         }
91     if (s == "password")
92         {
93         db_password = *(i->value.begin());
94         }
95
96     // Advanced settings block
97
98     if (s == "isolationLevel")
99         {
100         if (*(i->value.begin()) == "Concurrency")
101             {
102             til = IBPP::ilConcurrency;
103             }
104         else if (*(i->value.begin()) == "DirtyRead")
105             {
106             til = IBPP::ilReadDirty;
107             }
108         else if (*(i->value.begin()) == "ReadCommitted")
109             {
110             til = IBPP::ilReadCommitted;
111             }
112         else if (*(i->value.begin()) == "Consistency")
113             {
114             til = IBPP::ilConsistency;
115             }
116         }
117     if (s == "lockResolution")
118         {
119         if (*(i->value.begin()) == "Wait")
120             {
121             tlr = IBPP::lrWait;
122             }
123         else if (*(i->value.begin()) == "NoWait")
124             {
125             tlr = IBPP::lrNoWait;
126             }
127         }
128     }
129
130 try
131     {
132     db = IBPP::DatabaseFactory(db_server, db_database, db_user, db_password, "", "KOI8U", "");
133     db->Connect();
134     }
135 catch (IBPP::Exception & ex)
136     {
137     strError = "IBPP exception";
138     printfd(__FILE__, ex.what());
139     return -1;
140     }
141
142 return 0;
143 }
144 //-----------------------------------------------------------------------------