1 package com.quadcap.sql.file; 2 3 40 41 import java.io.File ; 42 import java.io.IOException ; 43 44 import java.util.ArrayList ; 45 import java.util.List ; 46 import java.util.Properties ; 47 48 import com.quadcap.util.collections.LongMap; 49 50 import com.quadcap.sql.lock.Transaction; 51 52 import com.quadcap.util.Debug; 53 54 59 public class Log3 implements Log { 60 Datafile db; 61 Properties props; 62 LongMap tt = new LongMap(222); 63 LongMap rowMap = new LongMap(3333); 64 65 68 public void init(Datafile db, boolean create, Properties props) 69 throws IOException { 70 this.db = db; 71 this.props = (Properties )props.clone(); 72 } 73 74 77 public void start() { 78 } 79 80 83 public Datafile getDatafile() { 84 return db; 85 } 86 87 90 public void addEntry(LogEntry entry) throws IOException { 91 int code = entry.getCode(); 92 if (code == LogEntry.BEGIN_TRANSACTION || 93 code == LogEntry.COMMIT) { 94 tt.remove(entry.getTransactionId()); 95 } else if (code == LogEntry.BLOCK_WRITE) { 96 } else { 98 List list = (List )tt.get(entry.getTransactionId()); 99 if (list == null) { 100 list = new ArrayList (); 101 tt.put(entry.getTransactionId(), list); 102 } 103 list.add(entry); 104 } 105 } 106 107 110 public void reallyAddEntry(LogEntry entry) throws IOException { 111 addEntry(entry); 112 } 113 114 117 public void close() throws IOException { 118 tt = new LongMap(tt.buckets()); 119 } 120 121 124 public void flushLog() throws IOException { 125 } 126 127 130 public void checkpoint() throws IOException { 131 } 132 133 136 public void sync() throws IOException { 137 } 138 139 142 public void rollbackTransaction(Transaction trans) throws IOException { 143 List list = (List )tt.get(trans.getTransactionId()); 144 if (list != null) { 145 for (int i = list.size()-1; i >= 0; i--) { 146 LogEntry entry = (LogEntry)list.get(i); 147 switch (entry.getCode()) { 148 case LogEntry.STEP: 149 if (entry.getRedoState() == LogEntry.DONE) { 150 try { 151 entry.undo(trans, db); 152 } catch (Throwable th) { 153 Debug.println("Exception in rollback transaction"); 155 Debug.print(th); 156 } 158 entry.setRedoState(LogEntry.UNDONE); 159 } 160 break; 161 default: 162 break; 163 } 164 } 165 } 166 } 167 168 171 public void rollbackStatement(Transaction trans, int stmtId) 172 throws IOException 173 { 174 List list = (List )tt.get(trans.getTransactionId()); 175 if (list != null) { 176 for (int i = list.size()-1; i >= 0; i--) { 177 LogEntry entry = (LogEntry)list.get(i); 178 if (entry.getStatementId() != stmtId) continue; 179 180 switch (entry.getCode()) { 181 case LogEntry.STEP: 182 if (entry.getRedoState() == LogEntry.DONE) { 183 try { 184 entry.undo(trans, db); 185 } catch (Throwable th) { 186 Debug.println("Exception in rollback transaction"); 188 Debug.print(th); 189 } 191 entry.setRedoState(LogEntry.UNDONE); 192 } 193 break; 194 case LogEntry.BEGIN_STATEMENT: 195 return; 196 default: 197 break; 198 } 199 } 200 } 201 } 202 203 206 public void restart() throws Exception { 207 } 208 209 212 public long getRowMap(long rowId) { 213 long ret = rowId; 214 Long l = (Long )rowMap.get(rowId); 215 if (l != null) ret = l.longValue(); 216 return ret; 217 } 218 219 227 public void putRowMap(long logRow, long fileRow) { 228 rowMap.put(logRow, new Long (fileRow)); 229 } 230 231 234 public void removeRowMap(long row) { 235 rowMap.remove(row); 236 } 237 238 241 public boolean isLogging() { 242 return true; 243 } 244 245 248 public void saveBlock(long b) throws IOException { 249 } 250 251 254 public void restoreBlocks() throws IOException { 255 } 256 257 260 public void resetBlocks() throws IOException { 261 } 262 263 266 public void remove() throws IOException { 267 } 268 269 272 public boolean inRecovery() throws IOException { 273 return false; 274 } 275 } 276 | Popular Tags |