rasdaman complete source
rasmgr_dbm.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
34 #ifndef RASMGR_DBM_HH
35 #define RASMGR_DBM_HH
36 
37 #include "rasmgr.hh"
38 #include "rasmgr_config.hh"
39 //#include "rasmgr_srv.hh"
40 
44 class DatabaseHost
45 {
46 public:
47  DatabaseHost();
48  ~DatabaseHost();
49 
50  void init(const char* hostName,const char *connectString,const char* userString,const char* passwdString);
51 
52  const char* getName();
53  const char* getConnectionString();
54  const char* getUser();
55  const char* getPasswd();
56  void changeConnectionString(const char *connectString);
57  void changeName(const char *newName);
58  void regStartServer();
59  void regDownServer();
60  //void incrConnServers();
61  //void decrConnServers();
62  //void incrConnDatabases();
63  //void decrConnDatabases();
64  bool prepareToBeRemoved();
65  bool isBusy();
66  bool isValid();
67 private:
68  char hostName[100];
69  char connectString[100];
70  char userString[100];
71  char passwdString[100];
72  int activServers;
73  //int connServers;
74  //int connDatabases;
75  bool valid;
76 };
77 
81 class DatabaseHostManager
82 {
83 public:
84  DatabaseHostManager();
85  ~DatabaseHostManager();
86  bool insertNewHost(const char* hostName,const char* connectString,const char* userString,const char* passwdString);
87  bool removeHost(const char* hostName);
88  int countHosts();
89  DatabaseHost& operator[](int);
90  DatabaseHost& operator[](const char* hostName);
91  bool reset();
92  bool acceptChangeName(const char *oldName,const char *newName);
93 private:
94  bool testUniqueness(const char* hostName);
95  list<DatabaseHost> hostList;
96  DatabaseHost protElem;
97 };
98 
99 extern DatabaseHostManager dbHostManager;
100 
101 
102 //*****************************************************
103 
104 class RasServer;
105 
109 class Database
110 {
111 public:
112  Database();
113  ~Database();
114 
115  void init(const char* databaseName);
116  const char* getName();
117  void changeName(const char* databaseName);
118 
119  static const char* getDescriptionHeader(char *destBuffer);
120  const char* getDescription(char *destBuffer);
121 
122  bool connectToDBHost(const char* hostName);
123  bool disconnectFromDBHost(const char* hostName);
124  bool isConnectedToDBHost(const char* hostName);
125  int countConnectionsToDBHosts();
126  const char* getDBHostName(int);
127 
128  bool connectToRasServer(const char *serverName);
129  bool disconnectFromRasServer(const char *serverName);
130  bool isConnectedToRasServer(const char *serverName);
131  int countConnectionsToRasServers();
132  const char* getRasServerName(int);
133 
134  void disconnectForRemove();
135 
136  void startWriteTransaction();
137  void endWriteTransaction();
138  void startReadTransaction();
139  void endReadTransaction();
140 
141  int getWriteTransactionCount();
142  int getReadTransactionCount();
143  bool isBusy();
144 
145  void setTraceWriteTrans(bool);
146 
147  bool isValid();
148 private:
149  bool checkConnection(DatabaseHost &);
150  bool checkConnection(RasServer &);
151  char databaseName[100];
152  list<DatabaseHost*> hostPtrList;
153  list<RasServer*> rasPtrList;
154 
155  bool traceWT;
156  int countWriteTransactions;
157  int countReadTransactions;
158 
159  bool valid;
160 };
161 
165 class DatabaseManager
166 {
167 public:
168  DatabaseManager();
169  ~DatabaseManager();
170  bool insertNewDatabase(const char* databaseName);
171  bool removeDatabase(const char* databaseName);
172  int countDatabases();
173  Database& operator[](int);
174  Database& operator[](const char*);
175  void disconnectAllDatabasesFromDBH(const char* dbhName);
176  bool reset();
177  bool acceptChangeName(const char *oldName,const char *newName);
178 private:
179  bool testUniqueness(const char* dbName);
180  list<Database> dtbList;
181  Database protElem;
182 };
183 
184 extern DatabaseManager dbManager;
185 
186 
187 #endif