1 21 22 package org.apache.derby.impl.store.raw.xact; 23 24 import org.apache.derby.iapi.services.io.FormatIdUtil; 25 import org.apache.derby.iapi.services.io.StoredFormatIds; 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 28 import org.apache.derby.iapi.store.raw.Transaction; 29 import org.apache.derby.iapi.store.raw.Loggable; 30 import org.apache.derby.iapi.store.raw.GlobalTransactionId; 31 32 import org.apache.derby.iapi.store.raw.log.LogInstant; 33 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 34 35 import org.apache.derby.iapi.services.io.CompressedNumber; 36 import org.apache.derby.iapi.util.ByteArray; 37 38 import java.io.OutputStream ; 39 import java.io.InputStream ; 40 import java.io.ObjectOutput ; 41 import java.io.ObjectInput ; 42 import java.io.IOException ; 43 import org.apache.derby.iapi.services.io.LimitObjectInput; 44 45 49 50 public class EndXact implements Loggable { 51 52 private int transactionStatus; 53 private GlobalTransactionId xactId; 54 55 public EndXact(GlobalTransactionId xid, int s) { 56 super(); 57 58 xactId = xid; 59 transactionStatus = s; 60 } 61 62 65 66 public EndXact() 68 { super(); } 69 70 public void writeExternal(ObjectOutput out) throws IOException 71 { 72 out.writeObject(xactId); 73 CompressedNumber.writeInt(out, transactionStatus); 74 } 75 76 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException 77 { 78 xactId = (GlobalTransactionId)in.readObject(); 79 transactionStatus = CompressedNumber.readInt(in); 80 } 81 82 85 public int getTypeFormatId() { 86 return StoredFormatIds.LOGOP_END_XACT; 87 } 88 89 93 94 102 public void doMe(Transaction xact, LogInstant instant, LimitObjectInput in) 103 { 104 105 if ((transactionStatus & Xact.END_PREPARED) == 0) 106 { 107 ((RawTransaction)xact).removeUpdateTransaction(); 108 } 109 else 110 { 111 ((RawTransaction)xact).prepareTransaction(); 112 } 113 } 114 115 124 public ByteArray getPreparedLog() 125 { 126 return (ByteArray) null; 127 } 128 129 135 public boolean needsRedo(Transaction xact) 136 { 137 return true; } 139 140 141 144 public void releaseResource(Transaction xact) 145 {} 146 147 148 151 public int group() 152 { 153 int group = Loggable.RAWSTORE; 154 155 if ((transactionStatus & Xact.END_COMMITTED) != 0) 156 group |= (Loggable.COMMIT | Loggable.LAST); 157 else if ((transactionStatus & Xact.END_ABORTED) != 0) 158 group |= (Loggable.ABORT | Loggable.LAST); 159 else if ((transactionStatus & Xact.END_PREPARED) != 0) 160 group |= Loggable.PREPARE; 161 162 return group; 163 } 164 165 166 169 public String toString() 170 { 171 if (SanityManager.DEBUG) 172 { 173 String endStatus; 174 switch(transactionStatus & 175 (Xact.END_ABORTED | Xact.END_PREPARED | Xact.END_COMMITTED)) 176 { 177 case Xact.END_ABORTED: 178 endStatus = " Aborted"; 179 break; 180 case Xact.END_PREPARED: 181 endStatus = " Prepared"; 182 break; 183 case Xact.END_COMMITTED: 184 endStatus = " Committed"; 185 break; 186 default: 187 endStatus = "Unknown"; 188 } 189 190 return( 191 "EndXact " + xactId + endStatus + 192 " : transactionStatus = " + endStatus); 193 } 194 else 195 { 196 return null; 197 } 198 } 199 } 200 | Popular Tags |