Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbBdbObjectFactory.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbBdbObjectFactory.cc,v 1.1 2005/09/15 05:06:26 gapon Exp $
00003 
00004 /// The implementation of the CdbBdbObjectFactory class.
00005 /**
00006   * @see CdbBdbObjectFactory
00007   */
00008 #include "BaBar/BaBar.hh"
00009 
00010 #include "CdbBdb/CdbBdbObjectFactory.hh"
00011 #include "CdbBdb/CdbBdbObjectCreator.hh"
00012 #include "CdbBdb/CdbBdb.hh"
00013 
00014 #include "CdbBase/Cdb.hh"
00015 #include "CdbBase/CdbDatabase.hh"
00016 #include "CdbBase/CdbCondition.hh"
00017 #include "CdbBase/CdbObject.hh"
00018 
00019 #include "BdbTime/BdbTime.hh"
00020 
00021 #include "ErrLogger/ErrLog.hh"
00022 
00023 #include <string>
00024 
00025 CdbBdbObjectFactory::CdbBdbObjectFactory( bool verifyFlag ) :
00026     _verifyFlag(verifyFlag)
00027 { }
00028 
00029 CdbBdbObjectFactory::~CdbBdbObjectFactory( )
00030 { }
00031 
00032 CdbStatus
00033 CdbBdbObjectFactory::create( CdbObjectPtr&          thePtr,
00034                              const CdbConditionPtr& theConditionPtr,
00035                              const BdbTime&         theBegin,
00036                              const BdbTime&         theEnd )
00037 {
00038     CdbStatus status = CdbStatus::Error;
00039 
00040     const char* errorStr = "CdbBdbObjectFactory::create() -- ERROR.";
00041 
00042   // Initialize result
00043 
00044  //   thePtr = 0;
00045 
00046     if( theConditionPtr.isNull( )) return CdbStatus::IllegalParameters;
00047 
00048   // Verify if the technology of the API in the specified (by CdbConditionPtr)
00049   // context is correct.
00050 
00051     const std::string apiTechnologyName = theConditionPtr->parentDatabase( )->parent( )->technologyName( );
00052 
00053     if( apiTechnologyName != CdbBdb::technology( )) {
00054         ErrMsg(error) << errorStr << "\n"
00055                       << "    The factory is being used in a wrong CDB API context. The condition's technology\n"
00056                       << "    doesn't match the expected one.\n"
00057                       << "        CONDITION API OBJECT 'TECHNOLOGY' : \"" << apiTechnologyName << "\"\n"
00058                       << "        EXPECTED             'TECHNOLOGY' : \"" << CdbBdb::technology( ) << "\"" << endmsg;
00059         return CdbStatus::ConflictOfParameters;
00060     }
00061 
00062   // Construct the clustering hint to be passed as a parameter
00063   // to the next method. We'll use the "containerPtr" and specified
00064   // validity interval ("begin" and "end") to calculate
00065   // the hint value.
00066 
00067     BdbRefAny hint;
00068 
00069     status = CdbBdbObjectCreator::hint( hint,
00070                                         theConditionPtr,
00071                                         theBegin,
00072                                         theEnd );
00073     if( CdbStatus::Success != status ) return status;
00074 
00075   // Call a method supplied by a developer
00076 
00077     BdbHandle(BdbObject) product;
00078 
00079     status = doCreate( product,
00080                        hint );
00081     if( CdbStatus::Success != status ) return status;
00082 
00083   // Check out that our client created an object in the right place.
00084 
00085     if( _verifyFlag ) {
00086         status = CdbBdbObjectCreator::verify( hint,
00087                                               product,
00088                                               theConditionPtr );
00089         if( CdbStatus::Success != status ) return status;
00090     }
00091 
00092   // And finally - turn the created persistent product into an
00093   // internal object of the Condition/DB API.
00094   //
00095   // NOTE: We're using the special constructor of BdbTime to get
00096   //       the maximum precision time.
00097 
00098     BdbTime insertionTime( BdbTime::now( ));
00099 
00100     status = CdbBdbObjectCreator::object( thePtr,
00101                                           theConditionPtr,
00102                                           theBegin,                 // begin of 'original' validity interval
00103                                           theEnd,                   // end   of 'original' validity interval
00104                                           theBegin,
00105                                           theEnd,
00106                                           insertionTime,            // begin of 'duration'
00107                                           BdbTime::plusInfinity,    // end   of 'duration'
00108                                           insertionTime,
00109                                           product );
00110     if( CdbStatus::Success != status ) return status;
00111 
00112     return CdbStatus::Success;
00113 }
00114 
00115 /////////////////
00116 // End Of File //
00117 /////////////////

Generated on Mon Dec 5 18:22:00 2005 for CDB by doxygen1.3-rc3