| 1 package com.quadcap.sql; 2 3 40 41 import java.io.BufferedOutputStream ; 42 import java.io.Externalizable ; 43 import java.io.IOException ; 44 import java.io.ObjectInput ; 45 import java.io.ObjectOutput ; 46 import java.io.OutputStream ; 47 48 import java.util.Enumeration ; 49 import java.util.Vector ; 50 51 import java.sql.SQLException ; 52 53 import com.quadcap.sql.io.ObjectInputStream; 54 import com.quadcap.sql.io.ObjectOutputStream; 55 import com.quadcap.sql.io.Extern; 56 57 import com.quadcap.sql.file.BlockAccess; 58 import com.quadcap.sql.file.BlockFile; 59 import com.quadcap.sql.file.PageManager; 60 import com.quadcap.sql.file.SubPageManager; 61 62 import com.quadcap.sql.types.Value; 63 64 import com.quadcap.util.Debug; 65 66 71 public class DropTable extends LogStep implements Externalizable { 72 Relation table; 73 Vector bases; 74 75 public DropTable() {} 76 77 public DropTable(Session session, Relation table) { 78 super(session); 79 this.table = table; 80 } 81 82 public void undo(Session session) throws IOException , SQLException { 83 Database db = session.getDatabase(); 84 db.addRelation(table); 85 if (bases != null) { 86 for (int i = 0; i < bases.size(); i++) { 87 db.addViewDependency(bases.elementAt(i).toString(), 88 table.getName()); 89 } 90 } 91 } 92 93 public void redo(Session session) throws IOException , SQLException { 94 Database db = session.getDatabase(); 95 db.removeRelation(table.getName()); 96 } 97 98 public void prepare(Session session) throws IOException , SQLException { 99 Database db = session.getDatabase(); 100 Enumeration b = db.getBases(table.getName()); 101 this.bases = new Vector (); 102 while (b.hasMoreElements()) { 103 bases.addElement(b.nextElement()); 104 } 105 } 106 107 public void readExternal(ObjectInput in) 108 throws IOException , ClassNotFoundException  109 { 110 super.readExternal(in); 111 table = (Relation)in.readObject(); 112 this.bases = (Vector )in.readObject(); 113 } 114 115 public void writeExternal(ObjectOutput out) throws IOException { 116 super.writeExternal(out); 117 out.writeObject(table); 118 out.writeObject(bases); 119 } 120 121 public String toString() { 123 StringBuffer sb = new StringBuffer (super.toString()); 124 sb.append(" DropTable("); 125 sb.append(table.toString()); 126 sb.append(')'); 127 return sb.toString(); 128 } 129 131 static Extern extern; 132 public void setExtern(Extern extern) { DropTable.extern = extern; } 133 public Extern getExtern() { return extern; } 134 } 135 | Popular Tags |