1 package com.quadcap.sql; 2 3 40 41 import java.io.IOException ; 42 43 import java.sql.SQLException ; 44 45 50 public class StmtAddConstraint implements Stmt { 51 String tableName; 52 Constraint constraintDef; 53 54 public StmtAddConstraint(String tableName, Constraint constraintDef) { 55 this.tableName = tableName; 56 this.constraintDef = constraintDef; 57 } 58 59 public void execute(Session session) throws IOException , SQLException { 60 Database db = session.getDatabase(); 61 session.getTableWriteLock("#Schema"); 62 session.getTableWriteLock(tableName); 63 Table table = (Table)db.getRelation(tableName); 64 String constraintName = constraintDef.getName(); 65 if (constraintName != null && 66 table.getConstraint(constraintName) != null) { 67 throw new SQLException ("ADD CONSTRAINT: constraint '" + 68 constraintName + "' already exists in " + 69 "table '" + tableName + "'"); 70 } 71 session.doStep(new AddConstraint(session, table, constraintDef)); 72 } 73 } 74 | Popular Tags |