StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbManager.cc
1 /***************************************************************************
2  *
3  * $Id: StDbManager.cc,v 1.32 2016/05/25 20:57:11 dmitry Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Manages access to Servers and passes Query-by-Table to db
9  *
10  ***************************************************************************
11  *
12  * $Log: StDbManager.cc,v $
13  * Revision 1.32 2016/05/25 20:57:11 dmitry
14  * coverity - resource leakage
15  *
16  * Revision 1.31 2004/01/15 00:02:25 fisyak
17  * Replace ostringstream => StString, add option for alpha
18  *
19  * Revision 1.30 2003/09/16 22:44:17 porter
20  * got rid of all ostrstream objects; replaced with StString+string.
21  * modified rules.make and added file stdb_streams.h for standalone compilation
22  *
23  * Revision 1.29 2003/09/02 17:57:49 perev
24  * gcc 3.2 updates + WarnOff
25  *
26  * Revision 1.28 2002/01/30 15:40:47 porter
27  * changed limits on flavor tag & made defaults retrieving more readable
28  *
29  * Revision 1.27 2001/01/22 18:37:55 porter
30  * Update of code needed in next year running. This update has little
31  * effect on the interface (only 1 method has been changed in the interface).
32  * Code also preserves backwards compatibility so that old versions of
33  * StDbLib can read new table structures.
34  * -Important features:
35  * a. more efficient low-level table structure (see StDbSql.cc)
36  * b. more flexible indexing for new systems (see StDbElememtIndex.cc)
37  * c. environment variable override KEYS for each database
38  * d. StMessage support & clock-time logging diagnostics
39  * -Cosmetic features
40  * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access
41  * f. removed codes that have been obsolete for awhile (e.g. db factories)
42  * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI
43  * and mysqlAccessor became StDbSql)
44  *
45  * Revision 1.26 2000/08/15 22:51:51 porter
46  * Added Root2DB class from Masashi Kaneta
47  * + made code more robust against requesting data from non-existent databases
48  *
49  * Revision 1.25 2000/06/30 01:57:02 porter
50  * fixed a delete bug & small memory leak found by Akio via Insure++ ,
51  * updated SetTable() method for containing idList, corrected enumeration
52  * map to rhic domain for Conditions_rhic database
53  *
54  * Revision 1.24 2000/06/02 13:37:36 porter
55  * built up list of minor changes:
56  * - made buffer more robust for certain null inputs
57  * - fixed small leak in StDbTables & restructure call to createMemory
58  * - added dbRhic as a database domain in StDbDefs
59  * - added setUser() in StDbManager
60  * - added more diagnostic printouts in mysqlAccessor.cc
61  *
62  * Revision 1.23 2000/05/04 15:13:11 porter
63  * added dbOnl, dbRich, dbMwc domains as standards
64  *
65  * Revision 1.22 2000/04/25 18:26:03 porter
66  * added flavor & production time as settable query fields in
67  * table &/or node. Associated SQL updated in mysqlAccessor.
68  * Flavor key supports "+" as an OR symbol.
69  *
70  * Revision 1.21 2000/03/28 17:03:18 porter
71  * Several upgrades:
72  * 1. configuration by timestamp for Conditions
73  * 2. query by whereClause made more systematic
74  * 3. conflict between db-stored comments & number lists resolved
75  * 4. ensure endtime is correct for certain query falures
76  * 5. dbstl.h->handles ObjectSpace & RogueWave difference (Online vs Offline)
77  *
78  * Revision 1.20 2000/03/01 20:56:16 porter
79  * 3 items:
80  * 1. activated reConnect for server timeouts
81  * 2. activated connection sharing; better resource utilization but poorer
82  * logging
83  * 3. made rollback method in mysqlAccessor more robust (affects writes only)
84  *
85  * Revision 1.19 2000/02/24 20:30:45 porter
86  * fixed padding for uchar; beginTime in mysqlAccessor;
87  * added rollback safety checkes in StDbManger
88  *
89  * Revision 1.18 2000/02/18 16:58:09 porter
90  * optimization of table-query, + whereClause gets timeStamp if indexed
91  * + fix to write multiple rows algorithm
92  *
93  * Revision 1.17 2000/02/15 20:27:44 porter
94  * Some updates to writing to the database(s) via an ensemble (should
95  * not affect read methods & haven't in my tests.
96  * - closeAllConnections(node) & closeConnection(table) method to mgr.
97  * - 'NullEntry' version to write, with setStoreMode in table;
98  * - updated both StDbTable's & StDbTableDescriptor's copy-constructor
99  *
100  * Revision 1.16 2000/01/27 20:27:17 porter
101  * fixed error logic for table, config, or table-list not-found
102  *
103  * Revision 1.15 2000/01/27 05:54:34 porter
104  * Updated for compiling on CC5 + HPUX-aCC + KCC (when flags are reset)
105  * Fixed reConnect()+transaction model mismatch
106  * added some in-code comments
107  *
108  * Revision 1.14 2000/01/19 20:20:05 porter
109  * - finished transaction model needed by online
110  * - fixed CC5 compile problem in StDbNodeInfo.cc
111  * - replace TableIter class by StDbTableIter to prevent name problems
112  *
113  * Revision 1.13 2000/01/14 14:50:52 porter
114  * expanded use of verbose mode & fixed inconsistency in
115  * StDbNodeInfo::getElementID
116  *
117  * Revision 1.12 2000/01/10 20:37:54 porter
118  * expanded functionality based on planned additions or feedback from Online work.
119  * update includes:
120  * 1. basis for real transaction model with roll-back
121  * 2. limited SQL access via the manager for run-log & tagDb
122  * 3. balance obtained between enumerated & string access to databases
123  * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose
124  * 5. restructured Node model for better XML support
125  *
126  * Revision 1.11 1999/12/28 21:31:42 porter
127  * added 'using std::vector' and 'using std::list' for Solaris CC5 compilation.
128  * Also fixed some warnings arising from the CC5 compiles
129  *
130  * Revision 1.10 1999/12/03 22:24:01 porter
131  * expanded functionality used by online, fixed bug in
132  * mysqlAccessor::getElementID(char*), & update StDbDataSet to
133  * conform to changes in Xml reader & writer
134  *
135  * Revision 1.9 1999/10/19 14:30:39 porter
136  * modifications relevant to use with StDbBroker and future merging with
137  * "params" database structure + some docs + suppressing diagnostics messages
138  *
139  * Revision 1.8 1999/09/30 02:06:07 porter
140  * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor)
141  * allow multiple rows (StDbTable), & Added the comment sections at top of
142  * each header and src file
143  *
144  **************************************************************************/
145 #include "StDbManager.hh"
146 #include "StDbManagerImpl.hh" // for new method only
147 #include "StDbMessenger.hh"
148 #include "stdb_streams.h"
149 #ifdef __ROOT__
150 ClassImp(StDbManager)
151 #endif
152 
153 StDbManager* StDbManager::mInstance=0;
156  if(!mInstance)mInstance=new StDbManagerImpl();
157  return mInstance;
158 }
159 
160 StDbManager::StDbManager(): misVerbose(false), misQuiet(false), muserName(0), mpWord(0), misTimeLogged(true ) {
161  Messenger=new StDbMessenger();
162  updateMessLevel();
163 };
164 StDbManager::~StDbManager(){
165  if (muserName) delete [] muserName;
166  if (mpWord) delete [] mpWord;
167  if (Messenger) delete Messenger;
168  mInstance=0;
169 }
170 
172 void
173 StDbManager::turnOffTimeLogging(){ misTimeLogged=false; }
174 
176 char*
177 StDbManager::mstringDup(const char* str){
178 
179 char* retString=0;
180 if(!str)return retString;
181 retString = new char[strlen(str)+1];
182 strcpy(retString,str);
183 
184 return retString;
185 }
186 
188 int
189 StDbManager::printInfo(const char* m1, StDbMessLevel ml, int lineNumber, const char* className, const char* methodName){
190 
191  Messenger->printMessage(m1,ml,lineNumber,className,methodName);
192  return 0;
193 }
194 
196 int
197 StDbManager::printInfo(const char* m1, const char* m2, StDbMessLevel ml, int lineNumber, const char* className, const char* methodName){
198 
199  StString ms;
200  ms<<m1<<" "<<m2;
201  printInfo((ms.str()).c_str(),ml,lineNumber,className,methodName);
202  return 0;
203 }
204 
205 
206 
208 void
209 StDbManager::setUser(const char* userName, const char* pWord){
210 
211  if(userName){
212  if(muserName) delete [] muserName;
213  muserName=mstringDup(userName);
214  }
215  if(pWord){
216  if(mpWord) delete [] mpWord;
217  mpWord = mstringDup(pWord);
218  }
219 }
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
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