KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > command > ddl > CreateFunctionAlias


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.command.ddl;
6
7 import java.sql.SQLException JavaDoc;
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 JavaDoc aliasName;
17     private String JavaDoc javaClassMethod;
18     private boolean ifNotExists;
19     
20     public CreateFunctionAlias(Session session) {
21         super(session);
22     }
23
24     public int update() throws SQLException JavaDoc {
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 JavaDoc name) {
41         this.aliasName = name;
42     }
43
44     public void setJavaClassMethod(String JavaDoc string) {
45         this.javaClassMethod = string;
46     }
47
48     public void setIfNotExists(boolean ifNotExists) {
49         this.ifNotExists = ifNotExists;
50     }
51
52 }
53
Popular Tags