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.engine.User; 12 import org.h2.message.Message; 13 import org.h2.schema.Schema; 14 15 public class CreateSchema extends DefineCommand { 16 17 private String schemaName; 18 private String authorization; 19 private boolean ifNotExists; 20 21 public CreateSchema(Session session) { 22 super(session); 23 } 24 25 public void setIfNotExists(boolean ifNotExists) { 26 this.ifNotExists = ifNotExists; 27 } 28 29 public int update() throws SQLException { 30 session.getUser().checkAdmin(); 31 session.commit(); 32 Database db = session.getDatabase(); 33 User user = db.getUser(authorization); 34 user.checkAdmin(); 35 if(db.findSchema(schemaName) != null) { 36 if (ifNotExists) { 37 return 0; 38 } 39 throw Message.getSQLException(Message.SCHEMA_ALREADY_EXISTS_1, schemaName); 40 } 41 int id = getObjectId(true, true); 42 Schema schema = new Schema(db, id, schemaName, user, false); 43 db.addDatabaseObject(session, schema); 44 return 0; 45 } 46 47 public void setSchemaName(String name) { 48 this.schemaName = name; 49 } 50 51 public void setAuthorization(String userName) { 52 this.authorization = userName; 53 } 54 55 } 56 57 | Popular Tags |