00001 #ifndef CDB_HH 00002 #define CDB_HH 00003 00004 // File and Version Information: 00005 // $Id: Cdb.hh,v 1.8 2005/05/03 20:59:50 gapon Exp $ 00006 00007 #include "CdbBase/CdbCPtrBase.hh" 00008 #include "CdbBase/CdbPtrFwd.hh" 00009 #include "CdbBase/CdbDatabasePtrFwd.hh" 00010 #include "CdbBase/CdbDatabaseItr.hh" 00011 #include "CdbBase/CdbTransaction.hh" 00012 #include "CdbBase/CdbObjectTranslator.hh" 00013 00014 #include <string> 00015 00016 class CdbTranslatorsDictBase; 00017 00018 /// The starting point for the public API of the Conditions/DB. 00019 /** 00020 * This is an abstract class also providing a factory interface. Its main function 00021 * is to locate the right instance of the Conditions/DB API. 00022 * 00023 * The second group of functionality is location of persistent databases in the store. 00024 */ 00025 class Cdb { 00026 00027 friend class CdbCPtrBase< Cdb >; // Who destroys me. 00028 00029 public: 00030 00031 /// The API locator. 00032 /** 00033 * Its only parameter is meant to specify which concrete instance 00034 * is to be returned. If it's ommited then the default value will be used 00035 * This default is a subject of the job's run-time configuration. 00036 * 00037 * @see Cdb::technologyName() 00038 * @see Cdb::implementationName() 00039 * @see Cdb::defaultTechnologyName() 00040 * @see Cdb::defaultImplementationName() 00041 * 00042 * @return a smart pointer to the interface. The 0 is returned in case of errors. 00043 */ 00044 static CdbPtr instance( const char* theTechnologyName = 0, /**< a value of the 1-st key */ 00045 const char* theImplementationName = 0 /**< a value of the 2-d key */ 00046 ); 00047 00048 private: 00049 00050 /// The copy constructor (NOT IMPLEMENTED) 00051 /** 00052 * Is disabled... 00053 */ 00054 Cdb( const Cdb& theCdb ); 00055 00056 /// The assignment operator (NOT IMPLEMENTED) 00057 /** 00058 * Is disabled... 00059 */ 00060 Cdb& operator=( const Cdb& theCdb ); 00061 00062 protected: 00063 00064 /// The default constructor. 00065 /** 00066 * More details... 00067 */ 00068 Cdb( ); 00069 00070 /// The destructor 00071 /** 00072 * The destructor is protected to prevent clients from deleting 00073 * objects which may be shared with others. 00074 */ 00075 virtual ~Cdb( ); 00076 00077 /// Add a new entry to the registry. 00078 /** 00079 * This _proxy_ method is meant to be used by subclasses to register themselves 00080 * in the dictionary through the dictionary's protected interface. 00081 * 00082 * @see CdbEnvironment::set() 00083 */ 00084 CdbStatus set( CdbPtr& thePtr ); 00085 00086 /// Find an entry matching specified keys in the registry. 00087 /** 00088 * This _proxy_ method is meant to be used by subclasses to find themselves 00089 * in the dictionary through the dictionary's protected interface. 00090 * 00091 * @see CdbEnvironment::get() 00092 */ 00093 CdbStatus get( CdbPtr& thePtr, 00094 const char* theTechnologyName, 00095 const char* theImplementationName ); 00096 00097 public: 00098 00099 /// Return the technology name 00100 /** 00101 * This method has to be implemented by subclasses. 00102 */ 00103 virtual const char* technologyName( ) const = 0; 00104 00105 /// Return the implementation name 00106 /** 00107 * This method has to be implemented by subclasses. 00108 */ 00109 virtual const char* implementationName( ) const = 0; 00110 00111 /// Initialize the API 00112 /** 00113 * This method needs to be called at least once during the lifetime 00114 * of the API's implementation to have it properly functioning. The main reason 00115 * to do this initialization explicitly is to avoid "initialization upon construction", 00116 * which is not welcome by certain clients of CDB API. 00117 * 00118 * @see Cdb::isInitialized() 00119 * 00120 * This method has to be implemented by subclasses. 00121 */ 00122 virtual void initialize( ) = 0; 00123 00124 /// Check if the API is initialized 00125 /** 00126 * This method can be used to check the current status of an API implementation. 00127 * 00128 * @see Cdb::initialize() 00129 * 00130 * This method has to be implemented by subclasses. 00131 */ 00132 virtual bool isInitialized( ) = 0; 00133 00134 /// Get default database name 00135 /** 00136 * This method is supposed to be implemented by subclasses. 00137 */ 00138 virtual CdbStatus getDefaultDatabase( std::string& theDatabaseName /**< the database name to be returned */ 00139 ) = 0; 00140 00141 /// Get default view name 00142 /** 00143 * This method is supposed to be implemented by subclasses. 00144 * 00145 * NOTE: 0 pointer is NOT allowed where the database name is expected. 00146 */ 00147 virtual CdbStatus getDefaultView( std::string& theViewName, /**< the view name to be returned */ 00148 const char* theDatabaseName /**< the scope of the operation */ 00149 ) = 0; 00150 00151 /// Set default database name 00152 /** 00153 * NOTE: 0 pointers or empty strings ("") are NOT allowed as values of parameters. 00154 * 00155 * This method is supposed to be implemented by subclasses. 00156 */ 00157 virtual CdbStatus setDefaultDatabase( const char* theDatabaseName /**< the database name to be set */ 00158 ) = 0; 00159 00160 /// Set default view name 00161 /** 00162 * NOTE: 0 pointers or empty strings ("") are NOT allowed as values of parameters. 00163 * 00164 * This method is supposed to be implemented by subclasses. 00165 */ 00166 virtual CdbStatus setDefaultView( const char* theViewName, /**< the view name to be returned */ 00167 const char* theDatabaseName /**< the scope of the operation */ 00168 ) = 0; 00169 00170 /// Find the specified Database 00171 /** 00172 * This method is supposed to be implemented by subclasses. 00173 * 00174 * This method initializes a smart pointer to a transient object of 00175 * the CdbDatabase class representing the found database. It will initialize the smart 00176 * pointer to point onto 0 and return the corresponding error status 00177 * when specified object is not found or is not awailable for some 00178 * other reason. 00179 * 00180 * The database is specified through its name. If the name is not specified then 00181 * the default database will be found and open. 00182 * 00183 * @see CdbDatabase 00184 * @see CdbDatabasePtr 00185 * @see CdbStatus 00186 * 00187 * @return a completion status of the operation 00188 */ 00189 virtual CdbStatus findDatabase( CdbDatabasePtr& thePtr, /**< a smart pointer to set up */ 00190 const char* theDatabaseName = 0 /**< the database name */ 00191 ) = 0; 00192 00193 /// Initialize an instance of an iterator for the known databases names 00194 /** 00195 * This method is supposed to be implemented by subclasses. 00196 * 00197 * The iterator will be set into a "valid" state upon successfull completion. 00198 * 00199 * @see CdbIItr::isValid() 00200 * @see CdbDatabase 00201 * @see CdbDatabaseItr 00202 * @see CdbStatus 00203 * 00204 * @return completion status 00205 */ 00206 virtual CdbStatus databaseIterator( CdbDatabaseItr& theItr ) = 0; 00207 00208 /// Register a user defined "persistent-to-transient" translator 00209 /** 00210 * A non-zero pointer is expected as a value of the method's parameter. 00211 * Also, note that the method will take an ownership of the passed object. 00212 * 00213 * @see class CdbObjectTranslator 00214 */ 00215 virtual CdbStatus registerTranslator( CdbObjectTranslator* theTranslatorPtr ); 00216 00217 /// Find a user defined "persistent-to-transient" translator 00218 /** 00219 * The method will look for the translator matching the specified transient 00220 * type identifier and the persistent type. The translator is supposed to be 00221 * registered for the current technology/implementation of the CDB API using 00222 * the Cdb::registerTranslator() method. 00223 * 00224 * @see class CdbType2Id 00225 * @see Cdb::registerTranslator() 00226 */ 00227 virtual CdbStatus findTranslator( CdbCPtr<CdbObjectTranslator>& theTranslatorPtr, 00228 unsigned int theTransientTypeId, 00229 const std::string& thePersistentTypeName ) const; 00230 00231 protected: 00232 00233 friend class CdbTransaction; // the one who's allowed to use the method defined below. 00234 00235 /// Get the transaction manager and start new transaction if needed 00236 /** 00237 * This method is used by the CdbTransaction class in implementing the technology-neutral 00238 * transaction management. Calling this method and returning a non-zero object will ensure 00239 * an existince of transaction of the specified more. The object's ownership is also returned 00240 * along with the object. When the object gets destroyed then the transaction should return 00241 * to its previous state (the one before calling this method). 00242 * 00243 * The method is supposed to be implemented by technology-specific implementations of 00244 * the current class. Any errors during the method's execution should be reported 00245 * in a form of the 0 pointer. 00246 * 00247 * @see class CdbTransactionBase 00248 * @see class CdbTransaction 00249 */ 00250 virtual CdbTransactionBase* transaction( CdbTransaction::Mode theMode ) const = 0; 00251 00252 private: 00253 00254 // A dictionary of translators 00255 00256 CdbCPtr< CdbTranslatorsDictBase > _myTranslatorsDict; 00257 }; 00258 00259 #endif // CDB_HH
1.3-rc3