00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbBdbWrapper/CdbBdbWCdb.hh"
00012
00013 #include "CdbBase/CdbEnvironment.hh"
00014 #include "CdbBase/CdbDatabase.hh"
00015 #include "CdbBase/CdbDebugStream.hh"
00016
00017 #include "CdbBdb/CdbBdbTransaction.hh"
00018
00019 #include "CdbBdbWrapper/CdbBdbWrapper.hh"
00020 #include "CdbBdbWrapper/CdbBdbWDatabase.hh"
00021 #include "CdbBdbWrapper/CdbBdbWDatabaseItr.hh"
00022
00023 #include "BdbCond/BdbConditions.hh"
00024
00025 #include "ErrLogger/ErrLog.hh"
00026
00027 #include <string.h>
00028 #include <assert.h>
00029 using std::endl;
00030
00031 CdbBdbWCdb::CdbBdbWCdb( ) :
00032 Cdb( ),
00033 _isInitialized(false)
00034 {
00035 CDB_DEBUG_STREAM << "Condition/DB API instantiated for"
00036 << " TECHNOLOGY=\"" << CdbBdbWrapper::technology( ) << "\""
00037 << " IMPLEMENTATION=\"" << CdbBdbWrapper::implementation( ) << "\""
00038 << endl;
00039
00040
00041
00042
00043
00044
00045
00046
00047 CdbPtr myPtr = this;
00048
00049 if( CdbStatus::Success != set( myPtr ))
00050 ErrMsg(fatal) << "failed to register the top level API component in the dictionary." << endmsg;
00051 }
00052
00053 CdbBdbWCdb::~CdbBdbWCdb( )
00054 { }
00055
00056 const char*
00057 CdbBdbWCdb::technologyName( ) const
00058 {
00059 return CdbBdbWrapper::technology( );
00060 }
00061
00062 const char*
00063 CdbBdbWCdb::implementationName( ) const
00064 {
00065 return CdbBdbWrapper::implementation( );
00066 }
00067
00068 void
00069 CdbBdbWCdb::initialize( )
00070 {
00071 if( !_isInitialized ) {
00072
00073
00074
00075 _isInitialized = true;
00076 }
00077 }
00078
00079 bool
00080 CdbBdbWCdb::isInitialized( )
00081 {
00082 return _isInitialized;
00083 }
00084
00085 CdbStatus
00086 CdbBdbWCdb::getDefaultDatabase( std::string& theDatabase )
00087 {
00088 assert( isInitialized( ));
00089
00090 theDatabase = BdbConditions::instance( )->bootName( );
00091
00092 return CdbStatus::Success;
00093 }
00094
00095 CdbStatus
00096 CdbBdbWCdb::getDefaultView( std::string& theView,
00097 const char* theDatabaseName )
00098 {
00099 assert( isInitialized( ));
00100
00101 CdbStatus result = CdbStatus::NotFound;
00102 do {
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 if( 0 == theDatabaseName ) break;
00115
00116 if( ! (( 0 == strcmp( theDatabaseName, "<default>" )) ||
00117 ( 0 == strcmp( theDatabaseName, BdbConditions::instance( )->bootName( ))))) break;
00118
00119
00120
00121
00122 theView = "<local>::<recent>";
00123
00124
00125
00126 result = CdbStatus::Success;
00127
00128 } while( false );
00129
00130 return result;
00131 }
00132
00133 CdbStatus
00134 CdbBdbWCdb::setDefaultDatabase( const char* theDatabaseName )
00135 {
00136 assert( isInitialized( ));
00137
00138
00139
00140
00141 CdbStatus result = CdbStatus::NotFound;
00142 do {
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 if( 0 == theDatabaseName ) break;
00155
00156 if( ! (( 0 == strcmp( theDatabaseName, "<default>" )) ||
00157 ( 0 == strcmp( theDatabaseName, BdbConditions::instance( )->bootName( ))))) break;
00158
00159
00160
00161 result = CdbStatus::Success;
00162
00163 } while( false );
00164
00165 return result;
00166 }
00167
00168 CdbStatus
00169 CdbBdbWCdb::setDefaultView( const char* theViewName,
00170 const char* theDatabaseName )
00171 {
00172 assert( isInitialized( ));
00173
00174
00175
00176
00177 CdbStatus result = CdbStatus::NotFound;
00178 do {
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 if( 0 == theDatabaseName ) break;
00191
00192 if( ! (( 0 == strcmp( theDatabaseName, "<default>" )) ||
00193 ( 0 == strcmp( theDatabaseName, BdbConditions::instance( )->bootName( ))))) break;
00194
00195
00196
00197
00198
00199
00200
00201 if( 0 == theViewName ) break;
00202
00203 if( 0 != strcmp( theViewName, "<local>::<recent>" )) break;
00204
00205
00206
00207 result = CdbStatus::Success;
00208
00209 } while( false );
00210
00211 return result;
00212 }
00213
00214 CdbStatus
00215 CdbBdbWCdb::findDatabase( CdbDatabasePtr& thePtr,
00216 const char* theName )
00217 {
00218 assert( isInitialized( ));
00219
00220 CdbStatus result = CdbStatus::Error;
00221
00222 thePtr = 0;
00223
00224 do {
00225
00226
00227
00228
00229
00230 std::string defaultDatabaseName;
00231 if( CdbStatus::Success != getDefaultDatabase( defaultDatabaseName )) break;
00232
00233 std::string databaseName = defaultDatabaseName;
00234 if( 0 != theName ) {
00235 if( 0 != strcmp( "<default>", theName )) {
00236
00237
00238
00239
00240 ;
00241
00242 } else {
00243 databaseName = theName;
00244 }
00245 }
00246 if( databaseName != defaultDatabaseName ) {
00247
00248 ErrMsg(error) << "no such database in this implementation: \"" << databaseName << "\"" << endl
00249 << "The only name allowed is the default one: \"" << defaultDatabaseName << "\"" << endmsg;
00250
00251 break;
00252 }
00253
00254
00255
00256
00257 CdbPtr selfPtr;
00258 if( CdbStatus::Success != get( selfPtr,
00259 technologyName( ),
00260 implementationName( ))) {
00261
00262 ErrMsg(fatal) << "failed to recover its own instance of the CDB API." << endl
00263 << " TECHNOLOGY : \"" << technologyName( ) << "\"" << endl
00264 << " IMPLEMENTATION : \"" << implementationName( ) << "\"" << endmsg;
00265 }
00266 thePtr = new CdbBdbWDatabase( selfPtr,
00267 databaseName.c_str( ));
00268 result = CdbStatus::Success;
00269
00270 } while( false );
00271
00272 return result;
00273 }
00274
00275 CdbStatus
00276 CdbBdbWCdb::databaseIterator( CdbDatabaseItr& theItr )
00277 {
00278 assert( isInitialized( ));
00279
00280
00281
00282
00283
00284
00285 CdbPtr selfPtr;
00286 if( CdbStatus::Success != get( selfPtr,
00287 technologyName( ),
00288 implementationName( ))) {
00289
00290 ErrMsg(fatal) << "failed to recover its own instance of the CDB API." << endl
00291 << " TECHNOLOGY : \"" << technologyName( ) << "\"" << endl
00292 << " IMPLEMENTATION : \"" << implementationName( ) << "\"" << endmsg;
00293 }
00294 theItr = CdbDatabaseItr( new CdbBdbWDatabaseItr( selfPtr ));
00295
00296 return CdbStatus::Success;
00297 }
00298
00299 CdbTransactionBase*
00300 CdbBdbWCdb::transaction( CdbTransaction::Mode theMode ) const
00301 {
00302
00303
00304
00305 switch( theMode ) {
00306 case CdbTransaction::Read: return new CdbBdbTransaction( BdbcRead );
00307 case CdbTransaction::Update: return new CdbBdbTransaction( BdbcUpdate );
00308 };
00309
00310
00311
00312
00313 ErrMsg(fatal) << "CdbBdbWCdb::transaction( ) -- FATAL ERROR" << endl
00314 << " Unssuported transaction mode: " << theMode << endl
00315 << " The implementation of the current method doesn't seem to follow changes" << endl
00316 << " in the technology-neutral CDB API." << endmsg;
00317 return 0;
00318 }
00319
00320
00321
00322