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.engine.UserDataType; |
13 | import org.h2.message.DbException; |
14 | |
15 | /** |
16 | * This class represents the statement |
17 | * DROP DOMAIN |
18 | */ |
19 | public class DropUserDataType extends DefineCommand { |
20 | |
21 | private String typeName; |
22 | private boolean ifExists; |
23 | |
24 | public DropUserDataType(Session session) { |
25 | super(session); |
26 | } |
27 | |
28 | public void setIfExists(boolean ifExists) { |
29 | this.ifExists = ifExists; |
30 | } |
31 | |
32 | @Override |
33 | public int update() { |
34 | session.getUser().checkAdmin(); |
35 | session.commit(true); |
36 | Database db = session.getDatabase(); |
37 | UserDataType type = db.findUserDataType(typeName); |
38 | if (type == null) { |
39 | if (!ifExists) { |
40 | throw DbException.get(ErrorCode.USER_DATA_TYPE_NOT_FOUND_1, typeName); |
41 | } |
42 | } else { |
43 | db.removeDatabaseObject(session, type); |
44 | } |
45 | return 0; |
46 | } |
47 | |
48 | public void setTypeName(String name) { |
49 | this.typeName = name; |
50 | } |
51 | |
52 | @Override |
53 | public int getType() { |
54 | return CommandInterface.DROP_DOMAIN; |
55 | } |
56 | |
57 | } |