StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDataBaseI.cc
1 /***************************************************************************
2  *
3  * $Id: StDataBaseI.cc,v 1.2 2001/10/26 20:59:45 porter Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Abstract class for Star specific SQL queries
9  *
10  ***************************************************************************
11  *
12  * $Log: StDataBaseI.cc,v $
13  * Revision 1.2 2001/10/26 20:59:45 porter
14  * fixed new endtime flag from previous checkin. made StDataBaseI available
15  * at root-cli.
16  *
17  * Revision 1.1 2001/01/22 18:37:50 porter
18  * Update of code needed in next year running. This update has little
19  * effect on the interface (only 1 method has been changed in the interface).
20  * Code also preserves backwards compatibility so that old versions of
21  * StDbLib can read new table structures.
22  * -Important features:
23  * a. more efficient low-level table structure (see StDbSql.cc)
24  * b. more flexible indexing for new systems (see StDbElememtIndex.cc)
25  * c. environment variable override KEYS for each database
26  * d. StMessage support & clock-time logging diagnostics
27  * -Cosmetic features
28  * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access
29  * f. removed codes that have been obsolete for awhile (e.g. db factories)
30  * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI
31  * and mysqlAccessor became StDbSql)
32  *
33  *
34  **************************************************************************/
35 #include "StDataBaseI.hh"
36 #include "StDbManager.hh"
37 #include <string.h>
38 
39 #ifdef __ROOT__
40 ClassImp(StDataBaseI)
41 #endif
42 
44 StDataBaseI::StDataBaseI() : mdbType(dbStDb), mdbDomain(dbDomainUnknown), mdbName(0), mtypeName(0), mdomainName(0), mdbStore(dbV00) { };
45 
46 StDataBaseI::StDataBaseI(StDbType type, StDbDomain domain) : mdbName(0), mtypeName(0), mdomainName(0), mdbStore(dbV00) { setDataBase(type,domain); }
47 
48 StDataBaseI::StDataBaseI(const char* typeName, const char* domainName) : mdbName(0), mtypeName(0), mdomainName(0), mdbStore(dbV00) { setDataBase(typeName,domainName); }
49 
51 StDataBaseI::~StDataBaseI(){
52  if(mdbName) delete [] mdbName;
53  if(mtypeName) delete [] mtypeName;
54  if(mdomainName) delete [] mdomainName;
55 }
56 
58 void
59 StDataBaseI::setDataBase(StDbType type, StDbDomain domain){
60  setDbType(type);
61  setDbDomain(domain);
62  char* name= StDbManager::Instance()->getDbTypeName(type);
63  setTypeName(name); if(name) delete [] name;
64  name= StDbManager::Instance()->getDbDomainName(domain);
65  setDomainName(name); if(name) delete [] name;
66  name=StDbManager::Instance()->getDbName(mtypeName,mdomainName);
67  setDbName(name); if(name) delete [] name;
68 }
69 
71 void
72 StDataBaseI::setDataBase(const char* typeName, const char* domainName){
73  setTypeName(typeName);
74  setDomainName(domainName);
75  char* name = StDbManager::Instance()->getDbName(mtypeName,mdomainName);
76  setDbName(name); if(name) delete [] name;
77  setDbType(StDbManager::Instance()->getDbType(typeName));
78  setDbDomain(StDbManager::Instance()->getDbDomain(domainName));
79 }
80 
82 void
83 StDataBaseI::setDataBase(const char* dbName){
84  setDbName(dbName);
85  StDbManager::Instance()->getDataBaseInfo(dbName,mtypeName,mdomainName);
86  setDbType(StDbManager::Instance()->getDbType(mtypeName));
87  setDbDomain(StDbManager::Instance()->getDbDomain(mdomainName));
88 }
89 
91 void
92 StDataBaseI::setDbName(const char* dbName) {
93 
94  if(dbName){
95  if(mdbName) delete [] mdbName;
96  mdbName = new char[strlen(dbName)+1];
97  strcpy(mdbName,dbName);
98  }
99 }
100 
102 void
103 StDataBaseI::setTypeName(const char* typeName) {
104 
105  if(typeName){
106  if(mtypeName) delete [] mtypeName;
107  mtypeName = new char[strlen(typeName)+1];
108  strcpy(mtypeName,typeName);
109  }
110 }
111 
113 void
114 StDataBaseI::setDomainName(const char* domainName) {
115 
116  if(domainName){
117  if(mdomainName) delete [] mdomainName;
118  mdomainName = new char[strlen(domainName)+1];
119  strcpy(mdomainName,domainName);
120  }
121 }
122 
124 char*
125 StDataBaseI::getDbName() const {
126 
127  char* retVal=0;
128  if(mdbName) {
129  retVal = new char[strlen(mdbName)+1];
130  strcpy(retVal,mdbName);
131  }
132 return retVal;
133 }
134 
136 char*
137 StDataBaseI::getTypeName() const {
138 
139  char* retVal=0;
140  if(mtypeName) {
141  retVal = new char[strlen(mtypeName)+1];
142  strcpy(retVal,mtypeName);
143  }
144 return retVal;
145 }
146 
148 char*
149 StDataBaseI::getDomainName() const {
150 
151  char* retVal=0;
152  if(mdomainName) {
153  retVal = new char[strlen(mdomainName)+1];
154  strcpy(retVal,mdomainName);
155  }
156 return retVal;
157 }
158 
160 
161 char* StDataBaseI::printDbName() { return mdbName; }
162 char* StDataBaseI::printTypeName() { return mtypeName; }
163 char* StDataBaseI::printDomainName() { return mdomainName; }
164 bool StDataBaseI::checkDbName(const char* name) {
165  return (strcmp(name,mdbName)==0) ? true : false;
166 }
167 bool StDataBaseI::checkDbType(const char* name) {
168  return (strcmp(name,mtypeName)==0) ? true : false;
169 }
170 bool StDataBaseI::checkDbDomain(const char* name) {
171  return (strcmp(name,mdomainName)==0) ? true : false;
172 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155