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.Schema; 13 14 public class DropSchema extends DefineCommand { 15 16 private String schemaName; 17 private boolean ifExists; 18 19 public DropSchema(Session session) { 20 super(session); 21 } 22 23 public void setSchemaName(String name) { 24 this.schemaName = name; 25 } 26 27 public int update() throws SQLException { 28 session.getUser().checkAdmin(); 29 session.commit(); 30 Database db = session.getDatabase(); 31 Schema schema = db.findSchema(schemaName); 32 if(schema == null) { 33 if(!ifExists) { 34 throw Message.getSQLException(Message.SCHEMA_NOT_FOUND_1, schemaName); 35 } 36 } else { 37 if(!schema.canDrop()) { 38 throw Message.getSQLException(Message.SCHEMA_CAN_NOT_BE_DROPPED_1, schemaName); 39 } 40 db.removeDatabaseObject(session, schema); 41 } 42 return 0; 43 } 44 45 public void setIfExists(boolean ifExists) { 46 this.ifExists = ifExists; 47 } 48 49 } 50 | Popular Tags |