00001 /*************************************************************************** 00002 * 00003 * $Id: StDbServer.hh,v 1.12 2001/01/22 18:37:59 porter Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: Interface Base class of Server for DB-access 00009 * 00010 * A Server is specified in this base class by : 00011 * name, host, unix-socket, port-number 00012 * When the default server flag is set, all databases that 00013 * are not mapped to a specific server are accessed via 00014 * the default server. This is implemented in the manager. 00015 * 00016 * 00017 *************************************************************************** 00018 * 00019 * $Log: StDbServer.hh,v $ 00020 * Revision 1.12 2001/01/22 18:37:59 porter 00021 * Update of code needed in next year running. This update has little 00022 * effect on the interface (only 1 method has been changed in the interface). 00023 * Code also preserves backwards compatibility so that old versions of 00024 * StDbLib can read new table structures. 00025 * -Important features: 00026 * a. more efficient low-level table structure (see StDbSql.cc) 00027 * b. more flexible indexing for new systems (see StDbElememtIndex.cc) 00028 * c. environment variable override KEYS for each database 00029 * d. StMessage support & clock-time logging diagnostics 00030 * -Cosmetic features 00031 * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access 00032 * f. removed codes that have been obsolete for awhile (e.g. db factories) 00033 * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI 00034 * and mysqlAccessor became StDbSql) 00035 * 00036 * Revision 1.11 2000/08/15 22:51:52 porter 00037 * Added Root2DB class from Masashi Kaneta 00038 * + made code more robust against requesting data from non-existent databases 00039 * 00040 * Revision 1.10 2000/03/01 20:56:16 porter 00041 * 3 items: 00042 * 1. activated reConnect for server timeouts 00043 * 2. activated connection sharing; better resource utilization but poorer 00044 * logging 00045 * 3. made rollback method in mysqlAccessor more robust (affects writes only) 00046 * 00047 * Revision 1.9 2000/02/15 20:27:44 porter 00048 * Some updates to writing to the database(s) via an ensemble (should 00049 * not affect read methods & haven't in my tests. 00050 * - closeAllConnections(node) & closeConnection(table) method to mgr. 00051 * - 'NullEntry' version to write, with setStoreMode in table; 00052 * - updated both StDbTable's & StDbTableDescriptor's copy-constructor 00053 * 00054 * Revision 1.8 2000/01/27 05:54:34 porter 00055 * Updated for compiling on CC5 + HPUX-aCC + KCC (when flags are reset) 00056 * Fixed reConnect()+transaction model mismatch 00057 * added some in-code comments 00058 * 00059 * Revision 1.7 2000/01/19 20:20:07 porter 00060 * - finished transaction model needed by online 00061 * - fixed CC5 compile problem in StDbNodeInfo.cc 00062 * - replace TableIter class by StDbTableIter to prevent name problems 00063 * 00064 * Revision 1.6 2000/01/10 20:37:54 porter 00065 * expanded functionality based on planned additions or feedback from Online work. 00066 * update includes: 00067 * 1. basis for real transaction model with roll-back 00068 * 2. limited SQL access via the manager for run-log & tagDb 00069 * 3. balance obtained between enumerated & string access to databases 00070 * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose 00071 * 5. restructured Node model for better XML support 00072 * 00073 * Revision 1.5 1999/09/30 02:06:09 porter 00074 * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor) 00075 * allow multiple rows (StDbTable), & Added the comment sections at top of 00076 * each header and src file 00077 * 00078 **************************************************************************/ 00079 #ifndef STDBSERVER_HH 00080 #define STDBSERVER_HH 00081 00082 #include "StDbDefs.hh" // enumeration of type & domain 00083 #include "StDataBaseI.hh" 00084 00085 class StDbServer { 00086 00087 protected: 00088 00089 char* mserverName; 00090 char* mhostName; 00091 char* munixSocket; 00092 char* muserName; 00093 char* mpword; 00094 int mportNumber; 00095 bool misDefault; 00096 00097 char* mstringDup(const char * str) const; 00098 00099 public: 00100 00101 // constructors & dtor 00102 StDbServer(); 00103 StDbServer(const char* name, const char* host, const char* sock, int port); 00104 StDbServer(StDbServer& server); 00105 virtual ~StDbServer(); 00106 00107 virtual void setHostName(const char* name); 00108 virtual void setUnixSocket(const char* name); 00109 virtual void setPortNumber(int port); 00110 virtual void setServerName(const char* name); 00111 virtual void setUser(const char* name, const char* pword=0); 00112 00113 // get methods for identifiers 00114 virtual char* getServerName() const; 00115 virtual char* getHostName() const; 00116 virtual char* getUnixSocket() const; 00117 virtual int getPortNumber() const; 00118 virtual char* printServerName(); 00119 virtual char* printHostName(); 00120 virtual char* printUnixSocket(); 00121 virtual char* printUser(); 00122 virtual char* printPword(); 00123 00124 virtual void setIsDefaultServer(); 00125 virtual bool isDefault() const ; 00126 00127 // set methods for identifiers 00128 virtual void addDataBase(StDbType type, StDbDomain domain) =0; 00129 virtual void addDataBase(const char* typeName, const char* domName) =0; 00130 virtual StDataBaseI* useDb(StDbType type, StDbDomain domain) =0; 00131 virtual StDataBaseI* useDb(const char* typeName, const char* domName) =0; 00132 virtual StDataBaseI* useDb() =0; 00133 // connection & check connections 00134 virtual bool isConnected() =0; 00135 virtual void closeConnection() =0; 00136 virtual void setTimeLogging(bool isTimeLogged) =0; 00137 virtual double getQueryTimes() =0; 00138 virtual double getSocketTimes() =0; 00139 virtual double getConnectTimes() =0; 00140 00141 }; 00142 00143 inline void StDbServer::setPortNumber(int port){ mportNumber = port;} 00144 inline int StDbServer::getPortNumber() const { return mportNumber; } 00145 inline char* StDbServer::printServerName() { return mserverName; } 00146 inline char* StDbServer::printHostName() { return mhostName; } 00147 inline char* StDbServer::printUnixSocket() { return munixSocket; } 00148 inline char* StDbServer::printUser() { return muserName; } 00149 inline char* StDbServer::printPword() { return mpword; } 00150 inline void StDbServer::setIsDefaultServer() { misDefault=true; } 00151 inline bool StDbServer::isDefault() const { return misDefault; } 00152 00153 #endif