File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\command\ddl\DropRole.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.command.ddl;
8
9 import org.h2.command.CommandInterface;
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.DbException;
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() {
35 session.getUser().checkAdmin();
36 session.commit(true);
37 Database db = session.getDatabase();
38 if (roleName.equals(Constants.PUBLIC_ROLE_NAME)) {
39 throw DbException.get(ErrorCode.ROLE_CAN_NOT_BE_DROPPED_1, roleName);
40 }
41 Role role = db.findRole(roleName);
42 if (role == null) {
43 if (!ifExists) {
44 throw DbException.get(ErrorCode.ROLE_NOT_FOUND_1, roleName);
45 }
46 } else {
47 db.removeDatabaseObject(session, role);
48 }
49 return 0;
50 }
51
52 public void setIfExists(boolean ifExists) {
53 this.ifExists = ifExists;
54 }
55
56 public int getType() {
57 return CommandInterface.DROP_ROLE;
58 }
59
60 }
61