StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbManager.hh
1 /***************************************************************************
2  *
3  * $Id: StDbManager.hh,v 1.24 2011/02/10 17:30:42 dmitry Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Manages access to Servers and passes Query-by-Table to db
9  * --> Now a pure virtual interface
10  *
11  ***************************************************************************
12  *
13  * $Log: StDbManager.hh,v $
14  * Revision 1.24 2011/02/10 17:30:42 dmitry
15  * added an option to blacklist domains
16  *
17  * Revision 1.23 2004/01/15 00:02:25 fisyak
18  * Replace ostringstream => StString, add option for alpha
19  *
20  * Revision 1.22 2003/09/16 22:44:17 porter
21  * got rid of all ostrstream objects; replaced with ostringstream+string.
22  * modified rules.make and added file stdb_streams.h for standalone compilation
23  *
24  * Revision 1.21 2003/09/02 17:57:49 perev
25  * gcc 3.2 updates + WarnOff
26  *
27  * Revision 1.20 2001/02/09 23:06:24 porter
28  * replaced ostrstream into a buffer with ostrstream creating the
29  * buffer. The former somehow clashed on Solaris with CC5 iostream (current .dev)
30  *
31  * Revision 1.19 2001/01/22 18:37:55 porter
32  * Update of code needed in next year running. This update has little
33  * effect on the interface (only 1 method has been changed in the interface).
34  * Code also preserves backwards compatibility so that old versions of
35  * StDbLib can read new table structures.
36  * -Important features:
37  * a. more efficient low-level table structure (see StDbSql.cc)
38  * b. more flexible indexing for new systems (see StDbElememtIndex.cc)
39  * c. environment variable override KEYS for each database
40  * d. StMessage support & clock-time logging diagnostics
41  * -Cosmetic features
42  * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access
43  * f. removed codes that have been obsolete for awhile (e.g. db factories)
44  * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI
45  * and mysqlAccessor became StDbSql)
46  *
47  * Revision 1.18 2000/06/02 13:37:37 porter
48  * built up list of minor changes:
49  * - made buffer more robust for certain null inputs
50  * - fixed small leak in StDbTables & restructure call to createMemory
51  * - added dbRhic as a database domain in StDbDefs
52  * - added setUser() in StDbManager
53  * - added more diagnostic printouts in mysqlAccessor.cc
54  *
55  * Revision 1.17 2000/03/28 17:03:19 porter
56  * Several upgrades:
57  * 1. configuration by timestamp for Conditions
58  * 2. query by whereClause made more systematic
59  * 3. conflict between db-stored comments & number lists resolved
60  * 4. ensure endtime is correct for certain query falures
61  * 5. dbstl.h->handles ObjectSpace & RogueWave difference (Online vs Offline)
62  *
63  * Revision 1.16 2000/03/01 20:56:16 porter
64  * 3 items:
65  * 1. activated reConnect for server timeouts
66  * 2. activated connection sharing; better resource utilization but poorer
67  * logging
68  * 3. made rollback method in mysqlAccessor more robust (affects writes only)
69  *
70  * Revision 1.15 2000/02/24 20:30:46 porter
71  * fixed padding for uchar; beginTime in mysqlAccessor;
72  * added rollback safety checkes in StDbManger
73  *
74  * Revision 1.14 2000/02/18 16:58:09 porter
75  * optimization of table-query, + whereClause gets timeStamp if indexed
76  * + fix to write multiple rows algorithm
77  *
78  * Revision 1.13 2000/02/15 20:27:44 porter
79  * Some updates to writing to the database(s) via an ensemble (should
80  * not affect read methods & haven't in my tests.
81  * - closeAllConnections(node) & closeConnection(table) method to mgr.
82  * - 'NullEntry' version to write, with setStoreMode in table;
83  * - updated both StDbTable's & StDbTableDescriptor's copy-constructor
84  *
85  * Revision 1.12 2000/01/27 05:54:34 porter
86  * Updated for compiling on CC5 + HPUX-aCC + KCC (when flags are reset)
87  * Fixed reConnect()+transaction model mismatch
88  * added some in-code comments
89  *
90  * Revision 1.11 2000/01/19 20:20:05 porter
91  * - finished transaction model needed by online
92  * - fixed CC5 compile problem in StDbNodeInfo.cc
93  * - replace TableIter class by StDbTableIter to prevent name problems
94  *
95  * Revision 1.10 2000/01/10 20:37:54 porter
96  * expanded functionality based on planned additions or feedback from Online work.
97  * update includes:
98  * 1. basis for real transaction model with roll-back
99  * 2. limited SQL access via the manager for run-log & tagDb
100  * 3. balance obtained between enumerated & string access to databases
101  * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose
102  * 5. restructured Node model for better XML support
103  *
104  * Revision 1.9 1999/12/28 21:31:42 porter
105  * added 'using std::vector' and 'using std::list' for Solaris CC5 compilation.
106  * Also fixed some warnings arising from the CC5 compiles
107  *
108  * Revision 1.8 1999/12/03 22:24:01 porter
109  * expanded functionality used by online, fixed bug in
110  * mysqlAccessor::getElementID(char*), & update StDbDataSet to
111  * conform to changes in Xml reader & writer
112  *
113  * Revision 1.7 1999/10/19 14:30:39 porter
114  * modifications relevant to use with StDbBroker and future merging with
115  * "params" database structure + some docs + suppressing diagnostics messages
116  *
117  * Revision 1.6 1999/09/30 02:06:07 porter
118  * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor)
119  * allow multiple rows (StDbTable), & Added the comment sections at top of
120  * each header and src file
121  *
122  **************************************************************************/
123 #ifndef STDBMANAGER_HH
124 #define STDBMANAGER_HH
125 
126 #include <string.h>
127 #include "StString.h"
128 
129 #include "stdb_streams.h"
130 
131 // real basic definitions
132 #include "StDbDefs.hh"
133 // pure virtual classes
134 #include "StDbMessService.hh"
135 
136 // other classes
137 class StDbServer;
138 class StDataBaseI;
139 class dbEnvList;
140 class StDbNode;
141 class StDbConfigNode;
142 class StDbTable;
143 
144 #ifdef __ROOT__
145 #include "TROOT.h"
146 #endif
147 
148 class StDbManager {
149 
150 protected:
151 
152  bool misVerbose;
153  bool misQuiet;
155  char* muserName;
156  char* mpWord;
157 
158  bool misTimeLogged;
159 
160  StDbManager();
161  static StDbManager* mInstance;
162 
163  char* mstringDup(const char* str);
164 
165 public:
166 
167  // access to this singleton object
168  static StDbManager* Instance();
169  virtual ~StDbManager();
170 
171  // Act as Factory object for StDbConfigNodess
172  // --> get dbHandle & Container of StDbTables..
173  virtual StDbConfigNode* initConfig(const char* dbName) =0;
174  virtual StDbConfigNode* initConfig(const char* dbName,
175  const char* configName, int opt=0) =0;
176  virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain) =0;
177  virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain,
178  const char* configName, int opt=0) =0;
179  virtual StDbConfigNode* initConfig(StDbType type, StDbDomain domain,
180  unsigned int requestTime, int opt=0) =0;
181  virtual StDbConfigNode* initConfig(const char* dbName,
182  unsigned int requestTime, int opt=0) =0;
183 
184  virtual char* getConfigNodeName(StDbType t, StDbDomain d) =0;
185  virtual char* getExternalVersion(StDbType t,StDbDomain d) =0;
186  virtual dbEnvList* getEnvList(const char* name) =0;
187 
188  // act as a Factory object for StDbTables
189  virtual StDbTable* newDbTable(const char* dbName,const char* tName)=0;
190  virtual StDbTable* newDbTable(StDbNode* node) =0;
191 
192  // Retreive DbLib owned database & server poointers by various methods
193  virtual StDataBaseI* findDb(StDbType type, StDbDomain domain) =0;
194  virtual StDataBaseI* findDb(const char* dbType, const char* dbDomain) =0;
195  virtual StDataBaseI* findDb(const char* databaseName) =0;
196  virtual StDbServer* findServer(StDbType type, StDbDomain domain) =0;
197  virtual StDbServer* findServer(StDbNode* node) =0;
198  virtual StDbServer* findServer(const char* type, const char* domain) =0;
199  virtual StDbServer* findServer(const char* databaseName) =0;
200  virtual StDbServer* findDefaultServer() =0;
201 
202  // helper functions using mapped enumeration to dbType & dbDomain
203  virtual char* getDbTypeName(StDbType type) =0;
204  virtual char* getDbDomainName(StDbDomain domain) =0;
205  virtual StDbType getDbType(const char* typeName) =0;
206  virtual StDbDomain getDbDomain(const char* domainName) =0;
207  virtual char* getDbName(const char* typeName, const char* domName)=0;
208  virtual char* printDbName(StDbType type, StDbDomain domain) =0;
209 
210  virtual void blacklistDbDomain(const char* domainName) =0;
211 
212  // time stamp methods
213  virtual void setRequestTime(unsigned int time) =0;
214  virtual void setRequestTime(const char* time) =0;
215  virtual unsigned int getUnixRequestTime() =0;
216  virtual char* getDateRequestTime() =0;
217  virtual unsigned int getUnixCheckTime() =0;
218  virtual char* getDateCheckTime() =0;
219  virtual void setStoreTime(unsigned int time) =0;
220  virtual void setStoreTime(const char* time) =0;
221  virtual unsigned int getUnixStoreTime() =0;
222  virtual char* getDateStoreTime() =0;
223 
224  // find the dbType & dbDomain for a database=>dbname
225  virtual bool getDataBaseInfo(const char* dbname,
226  char*& type, char*& domain) =0;
227  virtual bool getDataBaseInfo(const char* dbname,
228  StDbType& type, StDbDomain& domain) =0;
229 
230  // fetch & store methods for data
231  virtual bool IsValid(StDbTable* table) =0;
232  virtual bool fetchDbTable(StDbTable* table) =0;
233  virtual bool fetchDbTable(StDbTable* table, char* whereClause) =0;
234  virtual bool fetchAllTables(StDbConfigNode* node) =0;
235  virtual bool storeDbTable(StDbTable* table, bool commitWhenDone=true) =0;
236  virtual bool storeAllTables(StDbConfigNode* node,
237  bool commitWhenDone=true) =0;
238  virtual int storeConfig(StDbConfigNode* node, int currentID,
239  int& configID, bool commitWhenDone=true) =0;
240 
241  // transaction methods
242  virtual bool rollBackAllTables(StDbConfigNode* node) =0;
243  virtual bool rollBackAllNodes(StDbConfigNode* node) =0;
244  virtual bool rollBack(StDbNode* node) =0;
245  virtual bool rollBack(StDbTable* table) =0;
246  virtual bool commitAllTables(StDbConfigNode* node) =0;
247  virtual bool commitAllNodes(StDbConfigNode* node) =0;
248 
249  // close connection methods
250  virtual void closeAllConnections() =0;
251  virtual void closeAllConnections(StDbConfigNode* node) =0;
252  virtual void closeConnection(StDbNode* node) =0;
253 
254  virtual void printTimeStats() =0;
255 
256  // messaging service directions *** These are real functions ***
257  virtual bool IsVerbose() const;
258  virtual void setVerbose(bool isVerbose);
259  virtual bool IsQuiet() const ;
260  virtual void setQuiet(bool isQuiet);
261  virtual void turnOffTimeLogging();
262  virtual void updateMessLevel();
263  virtual void setMessenger(StDbMessService* service);
264  virtual StDbMessService* getMessenger();
265  virtual int printInfo(const char* m1, StDbMessLevel ml,
266  int lineNumber=0, const char* className=" ",
267  const char* methodName=" ") ;
268  virtual int printInfo(const char* m1, const char* m2,
269  StDbMessLevel ml, int lineNumber=0,
270  const char* className=" ",
271  const char* methodName=" ");
272 
273  virtual char* userName();
274  virtual char* pWord();
275  virtual void setUser(const char* userName, const char* pWord);
276 
277  // make ROOT-CLI via star-ofl "makefiles"
278 #ifdef __ROOT__
279  ClassDef(StDbManager,0)
280 #endif
281 
282 };
283 
284 inline bool StDbManager::IsVerbose() const { return misVerbose;};
285 inline void StDbManager::setVerbose(bool isVerbose){
286  misVerbose=isVerbose;
287  if(isVerbose)misQuiet=false;
288  updateMessLevel();
289 };
290 inline bool StDbManager::IsQuiet() const { return misQuiet;};
291 inline void StDbManager::setQuiet(bool isQuiet){
292  misQuiet=isQuiet;
293  if(isQuiet) misVerbose=false;
294  updateMessLevel();
295 }
296 inline void StDbManager::updateMessLevel(){
297  Messenger->setMessLevel(dbMWarn);
298  if(misQuiet)Messenger->setMessLevel(dbMErr);
299  if(misVerbose)Messenger->setMessLevel(dbMDebug);
300 }
301 inline void StDbManager::setMessenger(StDbMessService* service){
302  delete Messenger;
303  Messenger=service;
304  updateMessLevel();
305 }
306 inline StDbMessService* StDbManager::getMessenger(){ return Messenger; }
307 inline char* StDbManager::userName() { return muserName; }
308 inline char* StDbManager::pWord() { return mpWord; }
309 
310 #endif
311 
312 
313 
314 
315 
316 
317 
318 
319 
bool misQuiet
3 levels of verbosity: verbose, normal, quiet.
Definition: StDbManager.hh:153
StDbManager()
flag for logging timing
Definition: StDbManager.cc:160
StDbMessService * Messenger
where normal=!misVerbose &amp;&amp; !misQuiet
Definition: StDbManager.hh:154
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155