00001 /* 00002 // $Id: //open/dev/fennel/txn/LogicalTxn.h#12 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2005-2009 The Eigenbase Project 00005 // Copyright (C) 2005-2009 SQLstream, Inc. 00006 // Copyright (C) 2005-2009 LucidEra, Inc. 00007 // Portions Copyright (C) 1999-2009 John V. Sichi 00008 // 00009 // This program is free software; you can redistribute it and/or modify it 00010 // under the terms of the GNU General Public License as published by the Free 00011 // Software Foundation; either version 2 of the License, or (at your option) 00012 // any later version approved by The Eigenbase Project. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 #ifndef Fennel_LogicalTxn_Included 00025 #define Fennel_LogicalTxn_Included 00026 00027 #include <boost/utility.hpp> 00028 #include <boost/enable_shared_from_this.hpp> 00029 #include "fennel/txn/LogicalTxnStoredStructs.h" 00030 00031 #include <vector> 00032 00033 FENNEL_BEGIN_NAMESPACE 00034 00035 class LogicalTxnParticipant; 00036 00041 class FENNEL_TXN_EXPORT LogicalTxn 00042 : public boost::noncopyable, 00043 public boost::enable_shared_from_this<LogicalTxn> 00044 { 00045 friend class LogicalTxnLog; 00046 00050 enum State 00051 { 00052 STATE_LOGGING_TXN, 00053 00054 STATE_LOGGING_ACTION, 00055 00056 STATE_ROLLING_BACK, 00057 00058 STATE_ROLLED_BACK, 00059 00060 STATE_COMMITTED 00061 }; 00062 00067 TxnId txnId; 00068 00072 SharedLogicalTxnLog pLog; 00073 00077 SharedCacheAccessor pCacheAccessor; 00078 00082 SharedSpillOutputStream pOutputStream; 00083 00087 State state; 00088 00092 bool checkpointed; 00093 00097 LogicalTxnSavepoint svpt; 00098 00103 std::vector<LogicalTxnSavepoint> savepoints; 00104 00108 std::vector<SharedLogicalTxnParticipant> participants; 00109 00110 explicit LogicalTxn( 00111 TxnId txnId, 00112 SharedLogicalTxnLog pLog, 00113 SharedCacheAccessor pCacheAccessor); 00114 00115 void describeParticipant(SharedLogicalTxnParticipant); 00116 void describeAllParticipants(); 00117 void forgetAllParticipants(); 00118 00119 void rollbackToSavepoint(LogicalTxnSavepoint &oldSvpt); 00120 ByteOutputStream &beginLogicalAction( 00121 LogicalTxnParticipant *pParticipant, 00122 LogicalActionType actionType); 00123 00124 public: 00125 00126 virtual ~LogicalTxn(); 00127 00135 void addParticipant(SharedLogicalTxnParticipant pParticipant); 00136 00148 ByteOutputStream &beginLogicalAction( 00149 LogicalTxnParticipant &participant, 00150 LogicalActionType actionType); 00151 00156 void endLogicalAction(); 00157 00163 SavepointId createSavepoint(); 00164 00172 void commitSavepoint(SavepointId svptId); 00173 00180 void rollback(SavepointId const *pSvptId = NULL); 00181 00185 void commit(); 00186 00190 SharedLogicalTxnLog getLog(); 00191 00195 TxnId getTxnId() const; 00196 00200 bool isEnded() const; 00201 }; 00202 00203 FENNEL_END_NAMESPACE 00204 00205 #endif 00206 00207 // End LogicalTxn.h