00001 #ifndef CDB_ENVIRONMENT_HH 00002 #define CDB_ENVIRONMENT_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbEnvironment.hh,v 1.9 2005/11/03 02:49:26 gapon Exp $ 00006 00007 #include "CdbBase/CdbPtrFwd.hh" 00008 00009 #include <string> 00010 00011 class CdbStateId; 00012 class BdbTime; 00013 class CdbEnvironmentImpl; 00014 00015 template< class T > class CdbAnyTypeDict; 00016 00017 /// The configuration options of the Conditions/DB API. 00018 /** 00019 * This utility class provides global control options in the scope of 00020 * an application process. 00021 * 00022 * NOTE: Most of the operations provided by this class may involve interraction 00023 * with a persistent store(s). 00024 * 00025 * DESIGN NOTE: The design of this class is based on the 'PIMPL' idiom to introduce 00026 * the compilation firewall between clients of this utility class and 00027 * its actual "back-end" implementation 00028 */ 00029 class CdbEnvironment { 00030 00031 private: 00032 00033 /// The default constructor (NOT IMPLEMENTED) 00034 /** 00035 * Is disabled... 00036 */ 00037 CdbEnvironment( ); 00038 00039 /// The destructor (NOT IMPLEMENTED) 00040 /** 00041 * Is disabled... 00042 */ 00043 virtual ~CdbEnvironment( ); 00044 00045 /// The copy constructor (NOT IMPLEMENTED) 00046 /** 00047 * Is disabled... 00048 */ 00049 CdbEnvironment( const CdbEnvironment& theEnv ); 00050 00051 /// The assignment operator (NOT IMPLEMENTED) 00052 /** 00053 * Is disabled... 00054 */ 00055 CdbEnvironment& operator=( const CdbEnvironment& theEnv ); 00056 00057 public: 00058 00059 /// Set the current value of the "DEBUG LEVEL" 00060 /** 00061 * If 0 value is passed into the method then it means no debug output. 00062 * Interpretations for other values are not defined yet. The current behaviour 00063 * is "print as much as the corresponding component wants to". 00064 * 00065 * @return the previous value of the mode 00066 */ 00067 static int setDebugMode( int newMode = 0 ); 00068 00069 /// Get the current value of the "DEBUG LEVEL" 00070 /** 00071 * @see CdbEnvironment::setDebugMode() 00072 */ 00073 static int getDebugMode( ); 00074 00075 /// Get default value of the state identifier 00076 /** 00077 * The method delivers a value of the identifier calculated in the scope of 00078 * he current default environment. The only explicit parameter of the method 00079 * is a point of time in the validity dimension, in which the identifier is requested. 00080 * 00081 * The returned identifier will be "invalid" should any problem occures to construct 00082 * (calculate) the identifier. 00083 * 00084 * @see CdbStateId 00085 * 00086 * @return a value of the identifier. 00087 */ 00088 static CdbStateId defaultStateId( const BdbTime& theValidityTime ); 00089 00090 /// Get the current value of the "truncate" time 00091 /** 00092 * The "truncate" time if set will restrict the end time of stored objects 00093 * in the validity dimension. This restriction applies to any kinds of conditions 00094 * stored through CDB API. 00095 * 00096 * The default value of this time is "+Infinity", which means there is no restriction. 00097 * The value of this parameter can be set at any time during an application 00098 * execution. Should this happen the subsequent storing attempt would be affected. 00099 * 00100 * @see CdbEnvironment::setTruncateTime() 00101 * 00102 * @return a value of the truncate time. 00103 */ 00104 static BdbTime getTruncateTime( ); 00105 00106 /// Set the new value of the "truncate" time 00107 /** 00108 * @see CdbEnvironment::getTruncateTime() 00109 * 00110 * @return a previous value of the truncate time. 00111 */ 00112 static BdbTime setTruncateTime( const BdbTime& theNewTruncateTime ); 00113 00114 //////////////////////// 00115 // OBSOLETE INTERFACE // 00116 //////////////////////// 00117 // 00118 // The following interface is currently the obsolete one. It's replaced 00119 // by the new one (see it rigth after the end of this 'OBSOLETE INTERFACE' 00120 // section below. 00121 00122 /// Get default technology name 00123 /** 00124 * NOTE: This is an obsolete method to be removed soon. 00125 */ 00126 static std::string defaultTechnology( ); 00127 00128 /// Get default implementation name 00129 /** 00130 * Returns an empty string if there is no information for specified 00131 * combination of parameters values. 00132 * 00133 * NOTE: This is an obsolete method to be removed soon. 00134 */ 00135 static std::string defaultImplementation( const char* theTechnologyName ); 00136 00137 /// Get default database name 00138 /** 00139 * Returns an empty string if there is no information for specified 00140 * combination of parameters values. 00141 */ 00142 static std::string defaultDatabase( const char* theTechnologyName, 00143 const char* theImplementationName ); 00144 00145 /// Get default view name 00146 /** 00147 * Returns an empty string if there is no information for specified 00148 * combination of parameters values. 00149 * 00150 * NOTE: This is an obsolete method to be removed soon. 00151 */ 00152 static std::string defaultView( const char* theTechnologyName, 00153 const char* theImplementationName, 00154 const char* theDatabaseName ); 00155 00156 /// Set a combination of default parameters 00157 /** 00158 * 00159 * NOTE: This is an obsolete method to be removed soon. 00160 */ 00161 static void setDefault( const char* theTechnologyName, 00162 const char* theImplementationName, 00163 const char* theDatabaseName, 00164 const char* theViewName ); 00165 00166 /////////////////// 00167 // NEW INTERFACE // 00168 /////////////////// 00169 // 00170 // This interface replaces the above defined 'OBSOLETE INTERFACE'. 00171 // 00172 // NOTES: 00173 // 00174 // (1) The basic difference of this interface from the old one is in following areas: 00175 // 00176 // o the order of parameters is reversed. Therefore the inner scope 00177 // componentalways comes first. 00178 // 00179 // o certain _input-only_ parameters may get default 0 pointer to tell: 00180 // 00181 // "...use the default (whatever it is) in my (depending on 00182 // the context) upper scope(s)..." 00183 // 00184 // o passing the "<default>" string as a value of optional parameters 00185 // is equivalent to passing teh 0 pointer. 00186 // 00187 // o all methods now will return status. The reason of this is that 00188 // these methods are now the _active_ ones. Which means that (depending 00189 // on a context and actual values of parameters passed) they may cause 00190 // actual interaction with the corresponding CDB API implementations. 00191 // 00192 // (2) The actual implementation supporting the new interface expects 00193 // a "true" tree-like structure of defaults. 00194 00195 /// Get default technology name 00196 /** 00197 * The technology name is the top-level scope of the CDB API. Names returned 00198 * by this method are associated with particular persistent technologies used 00199 * in a specific way (which means that the same persistent technology may be 00200 * used in different ways. If thsi is going to be the case then different "technology" 00201 * names must be returned for each specific use by the current method). 00202 * 00203 * The method will return CdbStatus::NotFound in case if there is no one 00204 * specific technology known beneath CDB API. 00205 */ 00206 static CdbStatus getDefaultTechnology( std::string& theTechnologyName ); 00207 00208 /// Get default implementation name 00209 /** 00210 * The implementation name corresponds to specific implementation of the full CDB API 00211 * based on certain technology. Don't mix this "specific implementation" with 00212 * the various used of the same persistent technology. 00213 * 00214 * Omitting the technology name when calling this method whould imply that 00215 * the current default technology (as defined by the previous method) is going 00216 * to be used. 00217 */ 00218 static CdbStatus getDefaultImplementation( std::string& theImplementationName, 00219 const char* theTechnologyName = 0 ); 00220 00221 /// Get default database name 00222 /** 00223 * The database is defined as a set of self-consistent (persistent, but not limited to) 00224 * datasets with CDB metadata and actual user defined payload. 00225 */ 00226 static CdbStatus getDefaultDatabase( std::string& theDatabaseName, 00227 const char* theImplementationName = 0, 00228 const char* theTechnologyName = 0 ); 00229 00230 /// Get default view name 00231 /** 00232 * The view defines which slice of an actual database is available to an application. 00233 * Views in fact are providing mapping from a virtual namespace available to client 00234 * applications onto the actual data sets stored in databases. 00235 */ 00236 static CdbStatus getDefaultView( std::string& theViewName, 00237 const char* theDatabaseName = 0, 00238 const char* theImplementationName = 0, 00239 const char* theTechnologyName = 0 ); 00240 00241 /// Get all defaults 00242 /** 00243 * This method will return the current path in the tree of defaults. 00244 */ 00245 static CdbStatus getDefaultPath( std::string& theViewName, 00246 std::string& theDatabaseName, 00247 std::string& theImplementationName, 00248 std::string& theTechnologyName ); 00249 00250 /// Set default technology 00251 /** 00252 * The technology must already be instantiated by current application, 00253 * and it must be known to CDB API. 00254 * 00255 * NOTE: Passing 0 pointer as a technology name is _not_ allowed by this method. 00256 * The method will return CdbStatus::Error in this case. 00257 */ 00258 static CdbStatus setDefaultTechnology( const char* theTechnologyName ); 00259 00260 /// Set default implementation 00261 /** 00262 * The implementation implementing given (or default) technology must already 00263 * be instantiated by current application, and it must be known to CDB API. 00264 * 00265 * NOTE: Passing 0 pointer as an implementation name is _not_ allowed by this method. 00266 * The method will return CdbStatus::Error in this case. 00267 */ 00268 static CdbStatus setDefaultImplementation( const char* theImplementationName, 00269 const char* theTechnologyName = 0 ); 00270 00271 /// Set default database 00272 /** 00273 * The database must be available to the specified (or default) implementation. 00274 * 00275 * NOTE: Passing 0 pointer as a database name is _not_ allowed by this method. 00276 * The method will return CdbStatus::Error in this case. 00277 */ 00278 static CdbStatus setDefaultDatabase( const char* theDatabaseName, 00279 const char* theImplementationName = 0, 00280 const char* theTechnologyName = 0 ); 00281 00282 /// Set default view 00283 /** 00284 * The view must already exist in the scope of the specified (or default) database. 00285 * 00286 * NOTE: Passing 0 pointer as a view name is _not_ allowed by this method. 00287 * The method will return CdbStatus::Error in this case. 00288 */ 00289 static CdbStatus setDefaultView( const char* theViewName, 00290 const char* theDatabaseName = 0, 00291 const char* theImplementationName = 0, 00292 const char* theTechnologyName = 0 ); 00293 00294 /// Set all defaults to specified path 00295 /** 00296 * This method will set new path in the tree of defaults. 00297 * 00298 * The method will check the presense and availability of specified 00299 * components passed to this command. 00300 * 00301 * NOTE: Passing 0 pointers for any of the method's parameters is _not_ allowed 00302 * by this method. The method will return CdbStatus::Error in this case. 00303 */ 00304 static CdbStatus setDefaultPath( const char* theViewName, 00305 const char* theDatabaseName, 00306 const char* theImplementationName, 00307 const char* theTechnologyName ); 00308 00309 /// Access a dictionary of extra parameters 00310 /** 00311 * The dictionary is meant to be used to pass optional parameters to 00312 * technology specific implementations of the CDB API. The "environment" makes 00313 * no separation between the API's implementations. 00314 * 00315 * Here is a suggested format for technology-specific parameters: 00316 * 00317 * <technology>/<implementation>/<parameter> 00318 * 00319 * For example, if we had a hypothetical implementation of the CDB API storing plain text 00320 * strings in a relational database then we could control a client size cache by mean of 00321 * this parameter: 00322 * 00323 * "Text/SQL/max_cache_size" 00324 * 00325 * @see class CdbAnyTypeDict 00326 */ 00327 static CdbAnyTypeDict<std::string>& extra( ); 00328 00329 private: 00330 00331 00332 // The following two methods are only available to the Cdb "frined" class 00333 // and all its subclasses. 00334 00335 friend class Cdb; 00336 00337 /// Add a new entry to the registry. 00338 /** 00339 * If the registry already has an entry with given combination of keys 00340 * then CdbStatus::Error will be returned. 00341 */ 00342 static CdbStatus set( CdbPtr& thePtr /**< a pointer to be inserted */ 00343 ); 00344 00345 /// Find an entry matching specified keys in the registry. 00346 /** 00347 * This method will look up specified object in the registry and set up 00348 * the reference to it if found. 00349 * 00350 * @return CdbStatus::NotFound if there is no object matching specified keys. 00351 */ 00352 static CdbStatus get( CdbPtr& thePtr, /**< the pointer to be set up */ 00353 const char* theTechnologyName, /**< the 1-st key of an object to be found */ 00354 const char* theImplementationName /**< the 2-d key of an object to be found */ 00355 ); 00356 00357 private: 00358 00359 /// Get access to the actual implementation of the "environment" 00360 /** 00361 * The actual implementation is defined somewhere else to enforce 00362 * the compilation dependency firewall. 00363 * 00364 * @see CdbEnvironmentImpl 00365 */ 00366 static CdbEnvironmentImpl* impl( ); 00367 }; 00368 00369 #endif // CDB_ENVIRONMENT_HH
1.3-rc3