00001 #ifndef CDB_TRANSACTION_HH 00002 #define CDB_TRANSACTION_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbTransaction.hh,v 1.1 2005/02/02 13:54:56 gapon Exp $ 00006 00007 #include "CdbBase/CdbTransactionBase.hh" 00008 #include "CdbBase/CdbPtrFwd.hh" 00009 00010 /// The transaction management front-end 00011 /** 00012 * This is a technology neutral front-end class to technology specific 00013 * implementations of the transaction management based on the 00014 * "resource-acquisition-is-initialization" paradigm. 00015 * 00016 * The transaction is started when a constructor of the class 00017 * is invoked, and is commited when the destructor is executed. 00018 * The desired transaction mode can be passed as an optional parameter 00019 * of the class's constructor. 00020 * 00021 * This paradigme lets us to implement the following code pattern: 00022 * 00023 * // Begin a block of code (can be a function, a method, etc.) 00024 * 00025 * { 00026 * CdbTransaction trans; // begin a transaction in default mode, 00027 * // which is CdbTransaction::Read. 00028 * ... 00029 * } 00030 * 00031 * // It's guaranteed that the transaction is always returned into the same 00032 * // state it was before entering the block when the execution leaves 00033 * // the block, no matter what happens to the control flow. 00034 * 00035 * The main benefit of this approach is that a user should not warry about 00036 * explicit matching each "start transaction" with the corresponding "end transaction", 00037 * which in some cases may introduce an extra "noise" into the logic of the code. 00038 * So the only extra action to be made is to provide a block and to declare a variable 00039 * of this class in an appropriate place of the block (usually at its very beginninig). 00040 * 00041 * Here is another example, requering the names of specific CDB API "technology" and 00042 * "implementation" be specified: 00043 * 00044 * // Begin a block of code (can be a function, a method, etc.) 00045 * 00046 * { 00047 * CdbTransaction trans( "SomeTechnology", 00048 * "SomeImplementation", 00049 * CdbTransaction::Update ); 00050 * ... 00051 * } 00052 * 00053 * @see class CdbTransactionBase 00054 */ 00055 class CdbTransaction : public CdbTransactionBase { 00056 00057 public: 00058 00059 /// Modes of transactions 00060 00061 enum Mode { Read, Update }; 00062 00063 private: 00064 00065 /// Copy constructor (NOT IMPLEMENTED) 00066 00067 CdbTransaction( const CdbTransaction& ); 00068 00069 /// Assignment operator (NOT IMPLEMENTED) 00070 00071 CdbTransaction& operator=( const CdbTransaction& ); 00072 00073 public: 00074 00075 /// The constructor 00076 /** 00077 * Make sure that there is a transaction started in the specified mode. 00078 * 00079 * The operation is performed in a scope of the default CDB API implementation 00080 * fetched through the top-level CDB API class: Cdb.If the default implementation 00081 * won't be found then the crash in the constructor will take place. 00082 * 00083 * @see CdbTransactionBase::CdbTransactionBase() 00084 * @see class Cdb 00085 */ 00086 explicit CdbTransaction( CdbTransaction::Mode theMode = CdbTransaction::Read ); 00087 00088 /// The constructor 00089 /** 00090 * Make sure that there is a transaction started in the specified mode. 00091 * 00092 * The operation is performed in a scope of an explicitly specified CDB API implementation. 00093 * A non-zero pointer is expected. If not then the crash in the constructor will take place. 00094 * 00095 * @see CdbTransactionBase::CdbTransactionBase() 00096 * @see class Cdb 00097 */ 00098 explicit CdbTransaction( const CdbPtr& thePtr, 00099 CdbTransaction::Mode theMode = CdbTransaction::Read ); 00100 00101 /// The constructor 00102 /** 00103 * Make sure that there is a transaction started in the specified mode. 00104 * 00105 * The operation is performed in a scope of an explicitly specified CDB API implementation. 00106 * If the desired implementation won't be found then the crash in the constructor will 00107 * take place. 00108 * 00109 * NOTE ON PARAMETERS: 00110 * 00111 * - zero (0) pointer(s) passed where the "technology" and/or "implementation" names are expected 00112 * would imply the default value(s) of the parameter(s). 00113 * 00114 * @see CdbTransactionBase::CdbTransactionBase() 00115 * @see class Cdb 00116 */ 00117 CdbTransaction( const char* theTechnologyName, 00118 const char* theImplementationName, 00119 CdbTransaction::Mode theMode = CdbTransaction::Read ); 00120 00121 /// The destructor 00122 /** 00123 * Return current transaction into the same state if was before instantiating 00124 * an object of the class. 00125 * 00126 * @see CdbTransactionBase::~CdbTransactionBase() 00127 */ 00128 ~CdbTransaction( ); 00129 00130 /// Flush modifications made within the current transaction and keep going 00131 /** 00132 * Implements the corresponding method defined in a base class or an interface. 00133 * 00134 * @see CdbTransactionBase::commitAndHold() 00135 */ 00136 void commitAndHold( ); 00137 00138 private: 00139 00140 // The actual implementation of the transaction manager 00141 00142 CdbTransactionBase* _myImplPtr; 00143 }; 00144 00145 #endif // CDB_TRANSACTION_HH
1.3-rc3