1 5 package org.h2.command.ddl; 6 7 import java.sql.SQLException ; 8 9 import org.h2.engine.Database; 10 import org.h2.engine.Session; 11 import org.h2.message.Message; 12 import org.h2.schema.Constant; 13 import org.h2.schema.Schema; 14 15 public class DropConstant extends SchemaCommand { 16 17 private String constantName; 18 private boolean ifExists; 19 20 public DropConstant(Session session, Schema schema) { 21 super(session, schema); 22 } 23 24 public void setIfExists(boolean b) { 25 ifExists = b; 26 } 27 28 public void setConstantName(String constantName) { 29 this.constantName = constantName; 30 } 31 32 public int update() throws SQLException { 33 session.getUser().checkAdmin(); 34 session.commit(); 35 Database db = session.getDatabase(); 36 Constant constant = getSchema().findConstant(constantName); 37 if(constant == null) { 38 if(!ifExists) { 39 throw Message.getSQLException(Message.CONSTANT_NOT_FOUND_1, constantName); 40 } 41 } else { 42 db.removeSchemaObject(session, constant); 43 } 44 return 0; 45 } 46 47 } 48 | Popular Tags |