00001
00002
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
00028
00029 std::string pTypeName = "";
00030 {
00031
00032
00033 CdbTransaction readOnlyTransaction;
00034
00035
00036
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
00071
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
00086
00087 return toTransientPT( theTransientPtr,
00088 persObjectH );
00089 }
00090
00091
00092
00093