1 package com.quadcap.sql; 2 3 40 41 import java.util.Vector ; 42 43 import java.io.Externalizable ; 44 import java.io.IOException ; 45 import java.io.ObjectInput ; 46 import java.io.ObjectOutput ; 47 48 import java.sql.ResultSet ; 49 import java.sql.SQLException ; 50 51 import com.quadcap.sql.io.Extern; 52 import com.quadcap.util.Debug; 53 54 59 60 public class StmtCreateView extends LogStep implements Stmt, Externalizable { 61 View view; 62 63 66 public StmtCreateView() {} 67 68 71 public StmtCreateView(Session session, View view) { 72 super(session); 73 this.view = view; 74 } 75 76 79 public void undo(Session session) throws IOException , SQLException { 80 Database db = session.getDatabase(); 81 db.removeRelation(view.getName()); 82 } 83 84 87 public void redo(Session session) throws IOException , SQLException { 88 Database db = session.getDatabase(); 89 Vector v = view.getBaseTables(); 90 91 for (int i = 0; i < v.size(); i++) { 92 String base = (String )v.elementAt(i); 93 db.checkViewDependency(base, view.getName()); 94 } 95 96 view.addColumns(session); 97 db.addRelation(view); 98 for (int i = 0; i < v.size(); i++) { 99 String base = (String )v.elementAt(i); 100 db.addViewDependency(base, view.getName()); 101 } 102 } 103 104 public void execute(Session session) throws IOException , SQLException { 105 session.getTableWriteLock("#Schema"); 106 view.addColumns(session); 107 session.doStep(this); 108 } 109 110 public void prepare(Session session) throws IOException , SQLException { 111 } 112 113 public void readExternal(ObjectInput in) 114 throws IOException , ClassNotFoundException 115 { 116 super.readExternal(in); 117 view = (View)in.readObject(); 118 } 119 120 public void writeExternal(ObjectOutput out) throws IOException { 121 super.writeExternal(out); 122 out.writeObject(view); 123 } 124 125 129 public String toString() { 130 StringBuffer sb = new StringBuffer (super.toString()); 131 sb.append(" CreateView("); 132 sb.append(view.toString()); 133 sb.append(')'); 134 return sb.toString(); 135 } 136 138 static Extern extern; 139 public void setExtern(Extern extern) { StmtCreateView.extern = extern; } 140 public Extern getExtern() { return extern; } 141 } 142 143 | Popular Tags |