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.BlockFile; 49 import com.quadcap.sql.file.ByteUtil; 50 import com.quadcap.sql.file.SubPageManager; 51 import com.quadcap.sql.io.Extern; 52 53 import com.quadcap.sql.index.Btree; 54 55 import com.quadcap.util.Debug; 56 import com.quadcap.util.Util; 57 58 63 public class DeleteIndexEntry extends ModIndexEntry 64 implements Externalizable { 65 byte[] data; 66 67 70 public DeleteIndexEntry() {} 71 72 75 public DeleteIndexEntry(Session session, Constraint constraint, 76 byte[] key) { 77 super(session, constraint, key); 78 } 79 80 public void redo(Session session) throws IOException , SQLException { 81 if (index == null) getIndex(session); 82 index.delete(key); 83 } 84 85 public void undo(Session session) throws IOException { 86 if (data != null) { 87 if (index == null) getIndex(session); 88 long rowId = ByteUtil.getLong(data, 0); 89 ByteUtil.putLong(data, 0, session.getLog().getRowMap(rowId)); 90 index.set(key, data); 91 } 92 } 93 94 public void prepare(Session session) throws IOException { 95 if (index == null) getIndex(session); 96 this.data = index.get(key); 97 } 98 99 104 public void readExternal(ObjectInput in) 105 throws IOException , ClassNotFoundException 106 { 107 super.readExternal(in); 108 this.data = null; 109 int cnt = in.readInt(); 110 if (cnt > 0) { 111 data = new byte[cnt]; 112 in.read(data); 113 } 114 } 115 116 121 public void writeExternal(ObjectOutput out) throws IOException { 122 super.writeExternal(out); 123 if (data == null) { 124 out.writeInt(0); 125 } else { 126 out.writeInt(data.length); 127 out.write(data); 128 } 129 } 130 131 135 public String toString() { 136 return "Del: " + super.toString() + ", rowId = " + 137 (data != null && data.length >= 8 138 ? SubPageManager.toString(ByteUtil.getLong(data, 0)) 139 : "<NULL>"); 140 } 141 143 146 static Extern extern; 147 public void setExtern(Extern extern) { DeleteIndexEntry.extern = extern; } 148 public Extern getExtern() { return extern; } 149 } 150 151 | Popular Tags |