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.Session;
13: import org.h2.message.Message;
14: import org.h2.schema.Constant;
15: import org.h2.schema.Schema;
16:
17: /**
18: * This class represents the statement
19: * DROP CONSTANT
20: */
21: public class DropConstant extends SchemaCommand {
22:
23: private String constantName;
24: private boolean ifExists;
25:
26: public DropConstant(Session session, Schema schema) {
27: super (session, schema);
28: }
29:
30: public void setIfExists(boolean b) {
31: ifExists = b;
32: }
33:
34: public void setConstantName(String constantName) {
35: this .constantName = constantName;
36: }
37:
38: public int update() throws SQLException {
39: session.getUser().checkAdmin();
40: session.commit(true);
41: Database db = session.getDatabase();
42: Constant constant = getSchema().findConstant(constantName);
43: if (constant == null) {
44: if (!ifExists) {
45: throw Message.getSQLException(
46: ErrorCode.CONSTANT_NOT_FOUND_1, constantName);
47: }
48: } else {
49: db.removeSchemaObject(session, constant);
50: }
51: return 0;
52: }
53:
54: }
|