| 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 import java.io.OutputStream ; 46 47 import java.sql.SQLException ; 48 49 import com.quadcap.util.Debug; 50 import com.quadcap.sql.io.Extern; 51 52 57 public class AddTable extends LogStep implements Externalizable { 58 Relation table; 59 60 63 public AddTable() {} 64 65 68 public AddTable(Session session, Relation table) { 69 super(session); 70 this.table = table; 71 } 72 73 76 public void redo(Session session) throws IOException , SQLException { 77 Database db = session.getDatabase(); 78 db.addRelation(table); 79 } 80 81 84 public void undo(Session session) throws IOException , SQLException { 85 Database db = session.getDatabase(); 86 db.removeRelation(table.getName()); 87 } 88 89 94 public void prepare(Session session) throws IOException , SQLException { 95 Database db = session.getDatabase(); 96 if (db.getRelation(table.getName()) != null) { 97 throw new SQLException ("Table/view already exists: " + 98 table.getName(), 99 "42000"); 100 } 101 } 102 103 106 public void readExternal(ObjectInput in) 107 throws IOException , ClassNotFoundException  108 { 109 super.readExternal(in); 110 table = (Relation)in.readObject(); 111 } 112 113 116 public void writeExternal(ObjectOutput out) throws IOException { 117 super.writeExternal(out); 118 out.writeObject(table); 119 } 120 121 125 public String toString() { 126 StringBuffer sb = new StringBuffer (super.toString()); 127 sb.append(" AddTable("); 128 sb.append(table.toString()); 129 sb.append(')'); 130 return sb.toString(); 131 } 132 134 static Extern extern; 135 public void setExtern(Extern extern) { AddTable.extern = extern; } 136 public Extern getExtern() { return extern; } 137 } 138 | Popular Tags |