00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbTools/CdbCommandBase.hh"
00012 #include "CdbTools/CdbCommandTrans.hh"
00013
00014 #include <assert.h>
00015 #include <iostream>
00016 using std::cout;
00017 using std::endl;
00018
00019 CdbCommandBase::CdbCommandBase( CdbCommandTrans* theTransaction ) :
00020 _isValid(false),
00021 _myTransaction(theTransaction)
00022 {
00023 }
00024
00025 CdbCommandBase::~CdbCommandBase( )
00026 {
00027 delete _myTransaction;
00028 }
00029
00030 bool
00031 CdbCommandBase::setValid( bool theNewState )
00032 {
00033 bool oldState = _isValid;
00034 _isValid = theNewState;
00035 return oldState;
00036 }
00037
00038 bool
00039 CdbCommandBase::isValid( ) const
00040 {
00041 return _isValid;
00042 }
00043
00044 CdbStatus
00045 CdbCommandBase::execute( )
00046 {
00047 const char* errorString = "CdbCommandBase::execute() -- ERROR";
00048
00049 CdbStatus result = CdbStatus::Error;
00050 do {
00051
00052
00053
00054 if( !isValid( )) {
00055 cout << errorString << endl
00056 << " The object is not prepared for execution." << endl
00057 << " Perhaps the translation for the current command failed." << endl;
00058 break;
00059 }
00060
00061
00062
00063 if( CdbStatus::Success != _myTransaction->start( ) ) {
00064 cout << errorString << endl
00065 << " Failed to start the transaction." << endl;
00066 break;
00067 }
00068
00069
00070
00071 if( CdbStatus::Success != operation( )) {
00072 if( CdbStatus::Success != _myTransaction->abort( )) {
00073 cout << errorString << endl
00074 << " Failed to abort the current transaction." << endl;
00075 }
00076 break;
00077 }
00078
00079
00080
00081 if( CdbStatus::Success != _myTransaction->commit( )) {
00082 cout << errorString << endl
00083 << " Failed to commit the transaction." << endl;
00084 break;
00085 }
00086
00087
00088
00089 result = CdbStatus::Success;
00090
00091 } while( false );
00092
00093 return result;
00094 }
00095
00096 CdbStatus
00097 CdbCommandBase::checkpoint( bool commitAndHold )
00098 {
00099 const char* errorString = "CdbCommandBase::checkpoint() -- ERROR.";
00100
00101 CdbStatus result = CdbStatus::Error;
00102 do {
00103
00104
00105
00106 if( commitAndHold ) {
00107
00108
00109
00110 if( CdbStatus::Success != _myTransaction->commitAndHold( )) {
00111 cout << errorString << endl
00112 << " Failed to commit the current transaction and hold existing locks." << endl;
00113 break;
00114 }
00115
00116 } else {
00117
00118
00119
00120 if( CdbStatus::Success != _myTransaction->commit( )) {
00121 cout << errorString << endl
00122 << " Failed to commit the current transaction." << endl;
00123 break;
00124 }
00125
00126
00127
00128 if( CdbStatus::Success != _myTransaction->start( )) {
00129 cout << errorString << endl
00130 << " Failed to start a new transaction." << endl;
00131 break;
00132 }
00133 }
00134
00135
00136
00137 result = CdbStatus::Success;
00138
00139 } while( false );
00140
00141 return result;
00142 }
00143
00144
00145
00146