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

CdbCommandBase.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbCommandBase.cc,v 1.2 2004/08/06 05:54:44 bartoldu Exp $
00003 
00004 /// Implementation file for the CdbCommandBase class
00005 /**
00006   * @see CdbCommandBase
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       // Verify if the object context is valid.
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       // Start a transaction.
00062 
00063         if( CdbStatus::Success != _myTransaction->start( ) ) {
00064             cout << errorString << endl
00065                  << "    Failed to start the transaction." << endl;
00066             break;
00067         }
00068 
00069       // Execute operation.
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       // Commit a transaction.
00080 
00081         if( CdbStatus::Success != _myTransaction->commit( )) {
00082             cout << errorString << endl
00083                  << "    Failed to commit the transaction." << endl;
00084             break;
00085         }
00086 
00087       // Done
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       // Choose a specified method of checkpointing
00105 
00106         if( commitAndHold ) {
00107 
00108           // Commit the current transaction and hold existing locks.
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           // Commit the current transaction.
00119 
00120             if( CdbStatus::Success != _myTransaction->commit( )) {
00121                 cout << errorString << endl
00122                      << "    Failed to commit the current transaction." << endl;
00123                 break;
00124             }
00125 
00126           // Start a new transaction.
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       // Done
00136 
00137         result = CdbStatus::Success;
00138 
00139     } while( false );
00140 
00141     return result;
00142 }
00143 
00144 /////////////////
00145 // End Of File //
00146 /////////////////

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