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.FunctionAlias; 11 import org.h2.engine.Session; 12 import org.h2.message.Message; 13 14 public class CreateFunctionAlias extends DefineCommand { 15 16 private String aliasName; 17 private String javaClassMethod; 18 private boolean ifNotExists; 19 20 public CreateFunctionAlias(Session session) { 21 super(session); 22 } 23 24 public int update() throws SQLException { 25 session.commit(); 26 session.getUser().checkAdmin(); 27 Database db = session.getDatabase(); 28 if(db.findFunctionAlias(aliasName) != null) { 29 if(!ifNotExists) { 30 throw Message.getSQLException(Message.FUNCTION_ALIAS_ALREADY_EXISTS_1, aliasName); 31 } 32 } else { 33 int id = getObjectId(false, true); 34 FunctionAlias functionAlias = new FunctionAlias(db, id, aliasName, javaClassMethod); 35 db.addDatabaseObject(session, functionAlias); 36 } 37 return 0; 38 } 39 40 public void setAliasName(String name) { 41 this.aliasName = name; 42 } 43 44 public void setJavaClassMethod(String string) { 45 this.javaClassMethod = string; 46 } 47 48 public void setIfNotExists(boolean ifNotExists) { 49 this.ifNotExists = ifNotExists; 50 } 51 52 } 53 | Popular Tags |