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