1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.command.ddl; |
7 | |
8 | import org.h2.api.ErrorCode; |
9 | import org.h2.command.CommandInterface; |
10 | import org.h2.engine.Database; |
11 | import org.h2.engine.Session; |
12 | import org.h2.message.DbException; |
13 | import org.h2.schema.Constant; |
14 | import org.h2.schema.Schema; |
15 | |
16 | /** |
17 | * This class represents the statement |
18 | * DROP CONSTANT |
19 | */ |
20 | public class DropConstant extends SchemaCommand { |
21 | |
22 | private String constantName; |
23 | private boolean ifExists; |
24 | |
25 | public DropConstant(Session session, Schema schema) { |
26 | super(session, schema); |
27 | } |
28 | |
29 | public void setIfExists(boolean b) { |
30 | ifExists = b; |
31 | } |
32 | |
33 | public void setConstantName(String constantName) { |
34 | this.constantName = constantName; |
35 | } |
36 | |
37 | @Override |
38 | public int update() { |
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 DbException.get(ErrorCode.CONSTANT_NOT_FOUND_1, constantName); |
46 | } |
47 | } else { |
48 | db.removeSchemaObject(session, constant); |
49 | } |
50 | return 0; |
51 | } |
52 | |
53 | @Override |
54 | public int getType() { |
55 | return CommandInterface.DROP_CONSTANT; |
56 | } |
57 | |
58 | } |