1 package com.quadcap.sql; 2 3 40 41 import java.io.Externalizable ; 42 import java.io.IOException ; 43 import java.io.ObjectInput ; 44 import java.io.ObjectOutput ; 45 46 import java.sql.SQLException ; 47 48 import com.quadcap.sql.file.ByteUtil; 49 import com.quadcap.sql.file.SubPageManager; 50 51 import com.quadcap.sql.io.Extern; 52 53 import com.quadcap.sql.index.Btree; 54 55 import com.quadcap.util.Util; 56 57 62 public class AddIndexEntry extends ModIndexEntry implements Externalizable { 63 long rowId; 64 65 68 public AddIndexEntry() {} 69 70 73 public AddIndexEntry(Session session, Constraint constraint, 74 byte[] key, long rowId) { 75 super(session, constraint, key); 76 this.rowId = rowId; 77 } 78 79 82 public void redo(Session session) throws IOException , SQLException { 83 if (index == null) { 84 getIndex(session); 85 } 86 if (session.getConnection().inRecovery()) { 87 rowId = session.getLog().getRowMap(rowId); 88 } 89 index.set(key, key.length, session.getBuf8(rowId), 0, 8); 90 } 91 92 95 public void undo(Session session) throws IOException { 96 if (index == null) { 97 getIndex(session); 98 } 99 index.delete(key); 100 } 101 102 105 public void readExternal(ObjectInput in) 106 throws IOException , ClassNotFoundException 107 { 108 super.readExternal(in); 109 rowId = in.readLong(); 110 } 111 112 115 public void writeExternal(ObjectOutput out) throws IOException { 116 super.writeExternal(out); 117 out.writeLong(rowId); 118 } 119 120 123 static Extern extern; 124 public void setExtern(Extern extern) { AddIndexEntry.extern = extern; } 125 public Extern getExtern() { return extern; } 126 127 131 public String toString() { 132 return "Add: " + super.toString() + ", rowId = " + 133 SubPageManager.toString(rowId); 134 } 135 137 } 138 139 140 | Popular Tags |