00001
package com.quadcap.sql;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
import java.io.Externalizable;
00042
import java.io.IOException;
00043
import java.io.ObjectInput;
00044
import java.io.ObjectOutput;
00045
00046
import java.sql.SQLException;
00047
00048
import com.quadcap.sql.file.BlockFile;
00049
import com.quadcap.sql.file.ByteUtil;
00050
import com.quadcap.sql.file.SubPageManager;
00051
import com.quadcap.sql.io.Extern;
00052
00053
import com.quadcap.sql.index.Btree;
00054
00055
import com.quadcap.util.Debug;
00056
import com.quadcap.util.Util;
00057
00058
00059
00060
00061
00062
00063 public class DeleteIndexEntry extends ModIndexEntry
00064 implements
Externalizable {
00065 byte[]
data;
00066
00067
00068
00069
00070 public DeleteIndexEntry() {}
00071
00072
00073
00074
00075 public DeleteIndexEntry(
Session session,
Constraint constraint,
00076 byte[] key) {
00077 super(session, constraint, key);
00078 }
00079
00080 public void redo(
Session session)
throws IOException, SQLException {
00081
if (index == null) getIndex(session);
00082 index.
delete(key);
00083 }
00084
00085 public void undo(
Session session)
throws IOException {
00086
if (
data != null) {
00087
if (index == null) getIndex(session);
00088
long rowId =
ByteUtil.getLong(
data, 0);
00089
ByteUtil.putLong(
data, 0, session.getLog().getRowMap(rowId));
00090 index.
set(key,
data);
00091 }
00092 }
00093
00094 public void prepare(
Session session)
throws IOException {
00095
if (index == null) getIndex(session);
00096
this.data = index.
get(key);
00097 }
00098
00099
00100
00101
00102
00103
00104 public void readExternal(ObjectInput in)
00105
throws IOException, ClassNotFoundException
00106 {
00107 super.readExternal(in);
00108
this.data = null;
00109
int cnt = in.readInt();
00110
if (cnt > 0) {
00111
data =
new byte[cnt];
00112 in.read(
data);
00113 }
00114 }
00115
00116
00117
00118
00119
00120
00121 public void writeExternal(ObjectOutput out)
throws IOException {
00122 super.writeExternal(out);
00123
if (
data == null) {
00124 out.writeInt(0);
00125 }
else {
00126 out.writeInt(
data.length);
00127 out.write(
data);
00128 }
00129 }
00130
00131
00132
00133
00134
00135 public String
toString() {
00136
return "Del: " + super.toString() +
", rowId = " +
00137 (
data != null &&
data.length >= 8
00138 ?
SubPageManager.toString(
ByteUtil.getLong(
data, 0))
00139 :
"<NULL>");
00140 }
00141
00142
00143
00144
00145
00146 static Extern
extern;
00147 public void setExtern(Extern
extern) {
DeleteIndexEntry.extern =
extern; }
00148 public Extern
getExtern() {
return extern; }
00149 }
00150