StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbServer.cc
1 /***************************************************************************
2  *
3  * $Id: StDbServer.cc,v 1.14 2001/01/22 18:37:58 porter Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Server class for DB-access
9  *
10  ***************************************************************************
11  *
12  * $Log: StDbServer.cc,v $
13  * Revision 1.14 2001/01/22 18:37:58 porter
14  * Update of code needed in next year running. This update has little
15  * effect on the interface (only 1 method has been changed in the interface).
16  * Code also preserves backwards compatibility so that old versions of
17  * StDbLib can read new table structures.
18  * -Important features:
19  * a. more efficient low-level table structure (see StDbSql.cc)
20  * b. more flexible indexing for new systems (see StDbElememtIndex.cc)
21  * c. environment variable override KEYS for each database
22  * d. StMessage support & clock-time logging diagnostics
23  * -Cosmetic features
24  * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access
25  * f. removed codes that have been obsolete for awhile (e.g. db factories)
26  * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI
27  * and mysqlAccessor became StDbSql)
28  *
29  * Revision 1.13 2000/08/15 22:51:52 porter
30  * Added Root2DB class from Masashi Kaneta
31  * + made code more robust against requesting data from non-existent databases
32  *
33  * Revision 1.12 2000/03/01 20:56:16 porter
34  * 3 items:
35  * 1. activated reConnect for server timeouts
36  * 2. activated connection sharing; better resource utilization but poorer
37  * logging
38  * 3. made rollback method in mysqlAccessor more robust (affects writes only)
39  *
40  * Revision 1.11 2000/02/24 20:30:47 porter
41  * fixed padding for uchar; beginTime in mysqlAccessor;
42  * added rollback safety checkes in StDbManger
43  *
44  * Revision 1.10 2000/02/15 20:27:44 porter
45  * Some updates to writing to the database(s) via an ensemble (should
46  * not affect read methods & haven't in my tests.
47  * - closeAllConnections(node) & closeConnection(table) method to mgr.
48  * - 'NullEntry' version to write, with setStoreMode in table;
49  * - updated both StDbTable's & StDbTableDescriptor's copy-constructor
50  *
51  * Revision 1.9 2000/01/27 05:54:34 porter
52  * Updated for compiling on CC5 + HPUX-aCC + KCC (when flags are reset)
53  * Fixed reConnect()+transaction model mismatch
54  * added some in-code comments
55  *
56  * Revision 1.8 2000/01/19 20:20:06 porter
57  * - finished transaction model needed by online
58  * - fixed CC5 compile problem in StDbNodeInfo.cc
59  * - replace TableIter class by StDbTableIter to prevent name problems
60  *
61  * Revision 1.7 2000/01/10 20:37:54 porter
62  * expanded functionality based on planned additions or feedback from Online work.
63  * update includes:
64  * 1. basis for real transaction model with roll-back
65  * 2. limited SQL access via the manager for run-log & tagDb
66  * 3. balance obtained between enumerated & string access to databases
67  * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose
68  * 5. restructured Node model for better XML support
69  *
70  * Revision 1.6 1999/12/03 22:24:01 porter
71  * expanded functionality used by online, fixed bug in
72  * mysqlAccessor::getElementID(char*), & update StDbDataSet to
73  * conform to changes in Xml reader & writer
74  *
75  * Revision 1.5 1999/09/30 02:06:08 porter
76  * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor)
77  * allow multiple rows (StDbTable), & Added the comment sections at top of
78  * each header and src file
79  *
80  **************************************************************************/
81 #include "StDbServer.hh"
82 #include "StDbTable.h"
83 #include "StDbConfigNode.hh"
84 #include <string.h>
85 
86 #define __CLASS__ "StDbServer"
87 
89 
90 StDbServer::StDbServer(): mserverName(0),mhostName(0), munixSocket(0), muserName(0), mpword(0), misDefault(false){};
91 
92 StDbServer::StDbServer(const char* name, const char* host, const char* sock, int port) : mserverName(0),mhostName(0), munixSocket(0), muserName(0), mpword(0), mportNumber(port), misDefault(false) {
93 
94  setServerName(name);
95  setHostName(host);
96  setUnixSocket(sock);
97 };
98 
99 StDbServer::StDbServer(StDbServer& server) : mserverName(0), mhostName(0), munixSocket(0) , muserName(0), mpword(0), misDefault(false) {
100 
101  setServerName(server.printServerName());
102  setHostName(server.printHostName());
103  setUnixSocket(server.printUnixSocket());
104  setPortNumber(server.getPortNumber());
105 }
107 
108 StDbServer::~StDbServer(){
109  if(mserverName)delete [] mserverName;
110  if(mhostName) delete [] mhostName;
111  if(munixSocket)delete [] munixSocket;
112  if(muserName) delete [] muserName;
113  if(mpword) delete [] mpword;
114 }
116 
117 void StDbServer::setHostName(const char* name) {mhostName=mstringDup(name); }
118 void StDbServer::setUnixSocket(const char* name){munixSocket=mstringDup(name);}
119 void StDbServer::setServerName(const char* name){mserverName=mstringDup(name);}
120 
122 
123 void
124 StDbServer::setUser(const char* name, const char* pword){
125  muserName=mstringDup(name);
126  mpword=mstringDup(pword);
127 }
128 
130 
131 char* StDbServer::getHostName() const { return mstringDup(mhostName); };
132 char* StDbServer::getUnixSocket() const { return mstringDup(munixSocket); }
133 char* StDbServer::getServerName() const { return mstringDup(mserverName); }
134 
136 
137 char* StDbServer::mstringDup(const char* str) const {
138 
139 char* retString=0;
140 if(!str)return retString;
141 retString = new char[strlen(str)+1];
142 strcpy(retString,str);
143 return retString;
144 }
145 
146 #undef __CLASS__