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

CdbBdbObjectTranslatorPT.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbBdbObjectTranslatorPT.cc,v 1.1 2005/05/03 21:15:14 gapon Exp $
00003 
00004 #include "BaBar/BaBar.hh"
00005 
00006 #include "CdbBdb/CdbBdbObjectTranslatorPT.hh"
00007 #include "CdbBdb/CdbBdbObjectConvertor.hh"
00008 #include "CdbBdb/CdbBdbSchemaUtils.hh"
00009 #include "CdbBdb/CdbBdb.hh"
00010  
00011 #include "CdbBase/CdbTransaction.hh"
00012 
00013 #include "BdbCond/BdbObject.hh"
00014 
00015 #include "ErrLogger/ErrLog.hh"
00016 
00017 #include <iostream>
00018 using std::endl;
00019 
00020 template< class P,
00021           class T >
00022 std::string 
00023 CdbBdbObjectTranslatorPT<P,T>::persistentType2Name( )
00024 {
00025     const char* fatalStr = "CdbBdbObjectTranslatorPT<P,T>::persistentType2Name( ) -- FATAL";
00026 
00027   // Get and verify the 'P' type name
00028 
00029     std::string pTypeName = "";
00030     {
00031       // To get types we need a transaction.
00032 
00033         CdbTransaction readOnlyTransaction;
00034 
00035       // ATTENTION: If 'P' is not a valid persistent type known to the current
00036       //            Objectivity/DB schema then the compilations will abort below.
00037 
00038         ooTypeNumber pTypeNumber = ooTypeN( P );
00039 
00040         if( !CdbBdbSchemaUtils::instance( ).typeNumberToClassName( pTypeNumber,
00041                                                                    pTypeName ))
00042             ErrMsg(fatal) << fatalStr << endl
00043                           << "    Failed to translate the Objectivity/DB type number " << pTypeNumber << " of the" << endl
00044                           << "    passed as a template parameter of the class into the corresponding type name." << endmsg;
00045 
00046         if( !CdbBdbSchemaUtils::instance( ).isA( pTypeNumber,
00047                                                  ooTypeN( BdbObject )))
00048             ErrMsg(fatal) << fatalStr << endl
00049                           << "    The passed as a parameter of the template Objectivity/DB type number " << pTypeNumber << endl
00050                           << "    doesn't correspond to a persistent class deriving from BdbObject, which is" << endl
00051                           << "    the very base class of payload objects. The type number for BdbObject is " << ooTypeN( BdbObject ) << endmsg;
00052     }
00053     return pTypeName;
00054 }
00055 
00056 template< class P,
00057           class T >
00058 CdbBdbObjectTranslatorPT<P,T>::CdbBdbObjectTranslatorPT( ) :
00059     CdbObjectTranslatorT<T>( persistentType2Name( ))
00060 { }
00061 
00062 template< class P,
00063           class T >
00064 CdbStatus
00065 CdbBdbObjectTranslatorPT<P,T>::toTransientT( T*&                 theTransientPtr,
00066                                              const CdbObjectPtr& theObjectPtr ) const
00067 {
00068     const char* errorStr = "CdbBdbObjectTranslatorPT<P,T>::toTransientT( ) -- ERROR";
00069 
00070   // Translate the metadata object pointer into a persistent handle
00071   // This will also check if the metadata pointer is of the correct technology.
00072 
00073     CdbStatus result = CdbStatus::Error;
00074 
00075     BdbHandle(P) persObjectH;
00076 
00077     if( CdbStatus::Success != ( result = CdbBdbObjectConvertor::typeSafeNarrow( persObjectH,
00078                                                                                 theObjectPtr ))) {
00079         ErrMsg(error) << errorStr << endl
00080                       << "    Failed to obtain a persistent handle out of the passed metadata object." << endl
00081                       << "        OBJECT ID: " <<theObjectPtr->id( ) << endmsg;
00082         return result;
00083     }
00084 
00085   // Proceed to a user defined translation method
00086 
00087     return toTransientPT( theTransientPtr,
00088                           persObjectH );
00089 }
00090 
00091 /////////////////
00092 // End Of File //
00093 /////////////////

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