StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbNode.hh
1 /***************************************************************************
2  *
3  * $Id: StDbNode.hh,v 1.7 2016/05/25 20:17:51 dmitry Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Base-class database entities
9  *
10  ***************************************************************************
11  *
12  * $Log: StDbNode.hh,v $
13  * Revision 1.7 2016/05/25 20:17:51 dmitry
14  * coverity - uninit ctor
15  *
16  * Revision 1.6 2001/02/08 23:23:56 porter
17  * fixed initialization of schemaID in table & fixed some warnings when
18  * compiled with NODEBUG
19  *
20  * Revision 1.5 2001/01/22 18:37:58 porter
21  * Update of code needed in next year running. This update has little
22  * effect on the interface (only 1 method has been changed in the interface).
23  * Code also preserves backwards compatibility so that old versions of
24  * StDbLib can read new table structures.
25  * -Important features:
26  * a. more efficient low-level table structure (see StDbSql.cc)
27  * b. more flexible indexing for new systems (see StDbElememtIndex.cc)
28  * c. environment variable override KEYS for each database
29  * d. StMessage support & clock-time logging diagnostics
30  * -Cosmetic features
31  * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access
32  * f. removed codes that have been obsolete for awhile (e.g. db factories)
33  * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI
34  * and mysqlAccessor became StDbSql)
35  *
36  * Revision 1.4 2000/04/25 18:26:03 porter
37  * added flavor & production time as settable query fields in
38  * table &/or node. Associated SQL updated in mysqlAccessor.
39  * Flavor key supports "+" as an OR symbol.
40  *
41  * Revision 1.3 2000/02/15 20:27:44 porter
42  * Some updates to writing to the database(s) via an ensemble (should
43  * not affect read methods & haven't in my tests.
44  * - closeAllConnections(node) & closeConnection(table) method to mgr.
45  * - 'NullEntry' version to write, with setStoreMode in table;
46  * - updated both StDbTable's & StDbTableDescriptor's copy-constructor
47  *
48  * Revision 1.2 2000/01/19 20:20:06 porter
49  * - finished transaction model needed by online
50  * - fixed CC5 compile problem in StDbNodeInfo.cc
51  * - replace TableIter class by StDbTableIter to prevent name problems
52  *
53  * Revision 1.1 2000/01/10 20:37:54 porter
54  * expanded functionality based on planned additions or feedback from Online work.
55  * update includes:
56  * 1. basis for real transaction model with roll-back
57  * 2. limited SQL access via the manager for run-log & tagDb
58  * 3. balance obtained between enumerated & string access to databases
59  * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose
60  * 5. restructured Node model for better XML support
61  *
62  *
63  ***************************************************************************/
64 #ifndef STDBNODE_HH
65 #define STDBNODE_HH
66 
67 #include "StDbDefs.hh"
68 #include <string.h>
69 #ifdef __ROOT__
70 #include "TROOT.h"
71 #endif
72 
73 class StDbNode {
74 
75 protected:
76 
77  // unique node identfier
78  char * mname;
79  char * mversion;
80  char * mdbName;
81  StDbType mdbType = dbStDb;
82  StDbDomain mdbDomain = dbDomainUnknown;
83 
84  // from db
85  int mnodeID;
86  char* mnodeType;
87 
88  bool misConfigured;
89  bool mcanRollBack;
90 
91 public:
92 
93  StDbNode() : mname(0), mversion(0), mdbName(0), mnodeID(0), mnodeType(0), misConfigured(false), mcanRollBack(false) {};
94  StDbNode(const char* name, const char* versionKey);
95  StDbNode(const char* name);
96  StDbNode(StDbNode& node);
97 
98  virtual ~StDbNode();
99 
100  char* getName() ;
101  char* printName() ;
102  char* getMyName() ;
103  char* getVersion() ;
104  char* printVersion() ;
105  char* getDbName() ;
106  char* printDbName();
107  StDbType getDbType() const;
108  StDbDomain getDbDomain() const;
109  int getNodeID() const;
110  char* getNodeType() ;
111  char* printNodeType();
112 
113  void setName(const char* nodeName);
114  void setVersion(const char* nodeVersion);
115  void setDbName(const char* nodeDbName);
116  void setDbType(StDbType type);
117  void setDbDomain(StDbDomain domain);
118  void setNodeID(int id);
119  void setNodeType(const char* nodeType);
120 
121  // write transactions
122  bool canRollBack() const;
123  void addWrittenNode(int dataID);
124  void commit();
125 
126  // string comparisons
127  bool checkName(const char* nodeName) const;
128  bool checkVersion(const char* nodeVersion) const;
129  bool checkNode(const char* nodeName, const char* nodeVersion) const;
130  bool IsConfigured() const;
131  void setConfigured(bool isConfigured);
132  bool isNode(StDbType type, StDbDomain domain);
133  virtual bool IsTable() const;
134 
135  // helper functions
136  char* mstrDup(const char* s2) ; // strdup isn't ANSI
137  int* decodeElementID(const char* elementID, int& numRows) ;
138  char* getNextID(char*& currentElement) const;
139 #ifdef __ROOT__
140  ClassDef(StDbNode,0)
141 #endif
142 
143 };
144 inline char* StDbNode::printName() { return mname; };
145 inline char* StDbNode::printDbName() { return mdbName; };
146 inline char* StDbNode::printNodeType() { return mnodeType; };
147 inline char* StDbNode::printVersion() { return mversion; };
148 inline char* StDbNode::getMyName() { return printName(); }
149 inline StDbType StDbNode::getDbType() const { return mdbType;}
150 inline StDbDomain StDbNode::getDbDomain() const { return mdbDomain; }
151 inline void StDbNode::setDbType(StDbType type) { mdbType=type;}
152 inline void StDbNode::setDbDomain(StDbDomain domain) { mdbDomain=domain; }
153 inline int StDbNode::getNodeID() const { return mnodeID; }
154 inline void StDbNode::setNodeID(int id ) {mnodeID = id; }
155 inline void StDbNode::setConfigured(bool isC){ misConfigured=isC; }
156 inline bool StDbNode::IsConfigured() const { return misConfigured; }
157 inline bool StDbNode::isNode(StDbType type, StDbDomain domain){
158  return ( (type==mdbType) && (domain==mdbDomain) ) ? true : false;
159 }
160 inline bool StDbNode::canRollBack() const { return mcanRollBack; }
161 inline void StDbNode::addWrittenNode(int dataID){
162  mcanRollBack=true;
163  mnodeID=dataID;
164 }
165 inline void StDbNode::commit() { mcanRollBack = false; }
166 inline bool StDbNode::checkName(const char* nodeName) const {
167 return (mname && (strcmp(mname,nodeName)==0)) ? true : false;
168 }
169 inline bool StDbNode::checkVersion(const char* nodeVersion) const {
170 return (mversion && (strcmp(mversion,nodeVersion)==0)) ? true : false;
171 }
172 inline bool StDbNode::checkNode(const char* name, const char* version) const {
173 return (checkName(name) && checkVersion(version)) ? true : false;
174 }
175 inline bool StDbNode::IsTable() const { return false; }
176 #endif