Quadcap Embeddable Database

com/quadcap/sql/DeleteIndexEntry.java

Go to the documentation of this file.
00001 package com.quadcap.sql; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 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 * Log step to delete an index entry. 00060 * 00061 * @author Stan Bailes 00062 */ 00063 public class DeleteIndexEntry extends ModIndexEntry 00064 implements Externalizable { 00065 byte[] data; 00066 00067 /** 00068 * Default constructor 00069 */ 00070 public DeleteIndexEntry() {} 00071 00072 /** 00073 * Explicit constructor 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 * Read me from a stream 00101 * 00102 * @exception IOException may be thrown 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 * Write me to a stream 00118 * 00119 * @exception IOException may be thrown 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 //#ifdef DEBUG 00132 /** 00133 * Return string representation for debugging 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 //#endif 00142 00143 /** 00144 * My class's extern object 00145 */ 00146 static Extern extern; 00147 public void setExtern(Extern extern) { DeleteIndexEntry.extern = extern; } 00148 public Extern getExtern() { return extern; } 00149 } 00150