1 package com.quadcap.sql; 2 3 40 41 import java.io.IOException ; 42 43 import java.util.Vector ; 44 45 import java.sql.SQLException ; 46 47 import com.quadcap.util.Debug; 48 49 54 55 56 public class StmtCreateTable implements Stmt { 57 Table table; 58 Vector constraints; 59 boolean index = false; 60 61 64 public StmtCreateTable() {} 65 66 69 public StmtCreateTable(Table table, Vector constraints) { 70 this.table = table; 71 this.constraints = constraints; 72 } 73 74 78 void addConstraints(Session session, Vector constraints) 79 throws IOException , SQLException 80 { 81 Database db = session.getDatabase(); 82 for (int j = 0; j < constraints.size(); j++) { 83 Constraint con = (Constraint)constraints.elementAt(j); 84 if (con instanceof UniqueConstraint) { 85 index = true; 86 } 87 session.doStep(new AddConstraint(session, table, con)); 88 } 89 } 90 91 94 public void execute(Session session) throws IOException , SQLException { 95 session.getTableWriteLock("#Schema"); 96 table.setUnderConstruction(true); 97 try { 98 session.doStep(new AddTable(session, table)); 99 for (int i = 1; i <= table.getColumnCount(); i++) { 100 Vector v = table.getColumn(i).getConstraints(); 101 if (v != null) { 102 addConstraints(session, v); 103 } 104 } 105 addConstraints(session, constraints); 106 if (!index) { 107 Vector v = new Vector (); 108 v.addElement(new DefaultTableConstraint()); 109 addConstraints(session, v); 110 } 111 } finally { 112 table.setUnderConstruction(false); 113 } 114 } 115 } 116 117 118 | Popular Tags |