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