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: * DROP ALIAS
19: */
20: public class DropFunctionAlias extends DefineCommand {
21:
22: private String aliasName;
23: private boolean ifExists;
24:
25: public DropFunctionAlias(Session session) {
26: super (session);
27: }
28:
29: public int update() throws SQLException {
30: session.getUser().checkAdmin();
31: session.commit(true);
32: Database db = session.getDatabase();
33: FunctionAlias functionAlias = db.findFunctionAlias(aliasName);
34: if (functionAlias == null) {
35: if (!ifExists) {
36: throw Message
37: .getSQLException(
38: ErrorCode.FUNCTION_ALIAS_NOT_FOUND_1,
39: aliasName);
40: }
41: } else {
42: db.removeDatabaseObject(session, functionAlias);
43: }
44: return 0;
45: }
46:
47: public void setAliasName(String name) {
48: this .aliasName = name;
49: }
50:
51: public void setIfExists(boolean ifExists) {
52: this.ifExists = ifExists;
53: }
54:
55: }
|