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.util.Vector;
00042
00043
import java.io.Externalizable;
00044
import java.io.IOException;
00045
import java.io.ObjectInput;
00046
import java.io.ObjectOutput;
00047
00048
import java.sql.ResultSet;
00049
import java.sql.SQLException;
00050
00051
import com.quadcap.sql.io.Extern;
00052
import com.quadcap.util.Debug;
00053
00054
00055
00056
00057
00058
00059
00060 public class StmtCreateView extends LogStep implements
Stmt,
Externalizable {
00061 View view;
00062
00063
00064
00065
00066 public StmtCreateView() {}
00067
00068
00069
00070
00071 public StmtCreateView(
Session session,
View view) {
00072 super(session);
00073
this.view = view;
00074 }
00075
00076
00077
00078
00079 public void undo(
Session session)
throws IOException, SQLException {
00080
Database db = session.getDatabase();
00081 db.
removeRelation(
view.
getName());
00082 }
00083
00084
00085
00086
00087 public void redo(
Session session)
throws IOException, SQLException {
00088
Database db = session.getDatabase();
00089 Vector v =
view.
getBaseTables();
00090
00091
for (
int i = 0; i < v.size(); i++) {
00092 String base = (String)v.elementAt(i);
00093 db.
checkViewDependency(base,
view.
getName());
00094 }
00095
00096
view.
addColumns(session);
00097 db.
addRelation(
view);
00098
for (
int i = 0; i < v.size(); i++) {
00099 String base = (String)v.elementAt(i);
00100 db.
addViewDependency(base,
view.
getName());
00101 }
00102 }
00103
00104 public void execute(
Session session)
throws IOException, SQLException {
00105 session.getTableWriteLock(
"#Schema");
00106
view.
addColumns(session);
00107 session.doStep(
this);
00108 }
00109
00110 public void prepare(
Session session)
throws IOException, SQLException {
00111 }
00112
00113 public void readExternal(ObjectInput in)
00114
throws IOException, ClassNotFoundException
00115 {
00116 super.readExternal(in);
00117
view = (
View)in.readObject();
00118 }
00119
00120 public void writeExternal(ObjectOutput out)
throws IOException {
00121 super.writeExternal(out);
00122 out.writeObject(
view);
00123 }
00124
00125
00126
00127
00128
00129 public String
toString() {
00130 StringBuffer sb =
new StringBuffer(super.toString());
00131 sb.append(
" CreateView(");
00132 sb.append(
view.
toString());
00133 sb.append(
')');
00134
return sb.toString();
00135 }
00136
00137
00138 static Extern
extern;
00139 public void setExtern(Extern
extern) {
StmtCreateView.extern =
extern; }
00140 public Extern
getExtern() {
return extern; }
00141 }
00142