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.
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.
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
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
22 * This file contains a realization of a base firebird-storage plugin class
25 * $Date: 2010/01/08 16:00:45 $
29 #include "firebird_store.h"
31 #include "stg/common.h"
36 extern "C" STG::Store* GetStore()
38 static FIREBIRD_STORE plugin;
41 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 FIREBIRD_STORE::FIREBIRD_STORE()
45 : version("firebird_store v.1.4"),
46 db_server("localhost"),
47 db_database("/var/stg/stargazer.fdb"),
49 db_password("123456"),
50 til(IBPP::ilConcurrency),
53 logger(STG::PluginLogger::get("store_firebird"))
55 pthread_mutex_init(&mutex, NULL);
57 //-----------------------------------------------------------------------------
58 FIREBIRD_STORE::~FIREBIRD_STORE()
62 //-----------------------------------------------------------------------------
63 int FIREBIRD_STORE::ParseSettings()
65 std::vector<STG::ParamValue>::iterator i;
68 for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i)
72 s = ToLower(i->param);
75 db_server = i->value.front();
78 db_database = i->value.front();
81 db_user = i->value.front();
84 db_password = i->value.front();
86 // Advanced settings block
88 if (s == "isolationLevel")
90 if (i->value.front() == "Concurrency")
91 til = IBPP::ilConcurrency;
92 else if (i->value.front() == "DirtyRead")
93 til = IBPP::ilReadDirty;
94 else if (i->value.front() == "ReadCommitted")
95 til = IBPP::ilReadCommitted;
96 else if (i->value.front() == "Consistency")
97 til = IBPP::ilConsistency;
100 if (s == "lockResolution")
102 if (i->value.front() == "Wait")
104 else if (i->value.front() == "NoWait")
105 tlr = IBPP::lrNoWait;
111 db = IBPP::DatabaseFactory(db_server, db_database, db_user, db_password, "", "KOI8U", "");
113 return CheckVersion();
115 catch (IBPP::Exception & ex)
117 strError = "IBPP exception";
118 printfd(__FILE__, ex.what());
124 //-----------------------------------------------------------------------------
125 int FIREBIRD_STORE::CheckVersion()
127 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
128 IBPP::Statement st = IBPP::StatementFactory(db, tr);
133 st->Execute("SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$RELATION_NAME = 'TB_INFO'");
140 st->Execute("SELECT version FROM tb_info");
142 st->Get(1, schemaVersion);
145 logger("FIREBIRD_STORE: Current DB schema version: %d", schemaVersion);
148 catch (IBPP::Exception & ex)
151 strError = "IBPP exception";
152 printfd(__FILE__, ex.what());
158 //-----------------------------------------------------------------------------