1 8 9 package com.sleepycat.je.log; 10 11 import java.io.IOException ; 12 import java.nio.ByteBuffer ; 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import javax.transaction.xa.Xid ; 17 18 import com.sleepycat.je.DatabaseException; 19 import com.sleepycat.je.dbi.DatabaseId; 20 import com.sleepycat.je.dbi.EnvironmentImpl; 21 import com.sleepycat.je.log.entry.LNLogEntry; 22 import com.sleepycat.je.log.entry.LogEntry; 23 import com.sleepycat.je.tree.LN; 24 import com.sleepycat.je.txn.TxnAbort; 25 import com.sleepycat.je.txn.TxnCommit; 26 import com.sleepycat.je.txn.TxnPrepare; 27 28 32 public class LNFileReader extends FileReader { 33 34 39 protected Map targetEntryMap; 40 protected LogEntry targetLogEntry; 41 42 58 public LNFileReader(EnvironmentImpl env, 59 int readBufferSize, 60 long startLsn, 61 boolean redo, 62 long endOfFileLsn, 63 long finishLsn, 64 Long singleFileNum) 65 throws IOException , DatabaseException { 66 67 super(env, readBufferSize, redo, startLsn, 68 singleFileNum, endOfFileLsn, finishLsn); 69 70 targetEntryMap = new HashMap (); 71 } 72 73 public void addTargetType(LogEntryType entryType) 74 throws DatabaseException { 75 76 targetEntryMap.put(entryType, entryType.getNewLogEntry()); 77 } 78 79 82 protected boolean isTargetEntry(byte entryTypeNum, 83 byte entryTypeVersion) { 84 85 if (LogEntryType.isProvisional(entryTypeVersion)) { 86 87 targetLogEntry = null; 88 } else { 89 LogEntryType fromLogType = 90 new LogEntryType(entryTypeNum, entryTypeVersion); 91 92 93 targetLogEntry = (LogEntry) targetEntryMap.get(fromLogType); 94 } 95 return (targetLogEntry != null); 96 } 97 98 101 protected boolean processEntry(ByteBuffer entryBuffer) 102 throws DatabaseException { 103 104 targetLogEntry.readEntry(entryBuffer, currentEntrySize, 105 currentEntryTypeVersion, true); 106 return true; 107 } 108 109 112 public boolean isLN() { 113 return (targetLogEntry instanceof LNLogEntry); 114 } 115 116 119 public LN getLN() { 120 return ((LNLogEntry) targetLogEntry).getLN(); 121 } 122 123 126 public DatabaseId getDatabaseId() { 127 return ((LNLogEntry) targetLogEntry).getDbId(); 128 } 129 130 133 public byte[] getKey() { 134 return ((LNLogEntry) targetLogEntry).getKey(); 135 } 136 137 140 public byte[] getDupTreeKey() { 141 return ((LNLogEntry) targetLogEntry).getDupKey(); 142 } 143 144 147 public Long getTxnId() { 148 return ((LNLogEntry) targetLogEntry).getTxnId(); 149 } 150 151 154 public boolean isPrepare() { 155 return (targetLogEntry.getMainItem() instanceof TxnPrepare); 156 } 157 158 161 public long getTxnPrepareId() { 162 return ((TxnPrepare) targetLogEntry.getMainItem()).getId(); 163 } 164 165 168 public Xid getTxnPrepareXid() { 169 return ((TxnPrepare) targetLogEntry.getMainItem()).getXid(); 170 } 171 172 175 public boolean isAbort() { 176 return (targetLogEntry.getMainItem() instanceof TxnAbort); 177 } 178 179 182 public long getTxnAbortId() { 183 return ((TxnAbort) targetLogEntry.getMainItem()).getId(); 184 } 185 186 189 public long getTxnCommitId() { 190 return ((TxnCommit) targetLogEntry.getMainItem()).getId(); 191 } 192 193 196 public long getNodeId() { 197 return ((LNLogEntry) targetLogEntry).getLN().getNodeId(); 198 } 199 200 203 public long getAbortLsn() { 204 return ((LNLogEntry) targetLogEntry).getAbortLsn(); 205 } 206 207 210 public boolean getAbortKnownDeleted() { 211 return ((LNLogEntry) targetLogEntry).getAbortKnownDeleted(); 212 } 213 } 214 | Popular Tags |