01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.command.ddl;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.constant.ErrorCode;
11: import org.h2.engine.Database;
12: import org.h2.engine.FunctionAlias;
13: import org.h2.engine.Session;
14: import org.h2.message.Message;
15:
16: /**
17: * This class represents the statement
18: * CREATE ALIAS
19: */
20: public class CreateFunctionAlias extends DefineCommand {
21:
22: private String aliasName;
23: private String javaClassMethod;
24: private boolean ifNotExists;
25: private boolean force;
26:
27: public CreateFunctionAlias(Session session) {
28: super (session);
29: }
30:
31: public int update() throws SQLException {
32: session.commit(true);
33: session.getUser().checkAdmin();
34: Database db = session.getDatabase();
35: if (db.findFunctionAlias(aliasName) != null) {
36: if (!ifNotExists) {
37: throw Message.getSQLException(
38: ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1,
39: aliasName);
40: }
41: } else {
42: int id = getObjectId(false, true);
43: FunctionAlias functionAlias = new FunctionAlias(db, id,
44: aliasName, javaClassMethod, force);
45: db.addDatabaseObject(session, functionAlias);
46: }
47: return 0;
48: }
49:
50: public void setAliasName(String name) {
51: this .aliasName = name;
52: }
53:
54: public void setJavaClassMethod(String string) {
55: this .javaClassMethod = string;
56: }
57:
58: public void setIfNotExists(boolean ifNotExists) {
59: this .ifNotExists = ifNotExists;
60: }
61:
62: public void setForce(boolean force) {
63: this.force = force;
64: }
65:
66: }
|