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.Constants;
12: import org.h2.engine.Database;
13: import org.h2.engine.Role;
14: import org.h2.engine.Session;
15: import org.h2.message.Message;
16:
17: /**
18: * This class represents the statement
19: * DROP ROLE
20: */
21: public class DropRole extends DefineCommand {
22:
23: private String roleName;
24: private boolean ifExists;
25:
26: public DropRole(Session session) {
27: super (session);
28: }
29:
30: public void setRoleName(String roleName) {
31: this .roleName = roleName;
32: }
33:
34: public int update() throws SQLException {
35: session.getUser().checkAdmin();
36: session.commit(true);
37: Database db = session.getDatabase();
38: if (roleName.equals(Constants.PUBLIC_ROLE_NAME)) {
39: throw Message.getSQLException(
40: ErrorCode.ROLE_CAN_NOT_BE_DROPPED_1, roleName);
41: }
42: Role role = db.findRole(roleName);
43: if (role == null) {
44: if (!ifExists) {
45: throw Message.getSQLException(
46: ErrorCode.ROLE_NOT_FOUND_1, roleName);
47: }
48: } else {
49: db.removeDatabaseObject(session, role);
50: }
51: return 0;
52: }
53:
54: public void setIfExists(boolean ifExists) {
55: this.ifExists = ifExists;
56: }
57:
58: }
|