File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\engine\Role.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.engine;
8
9 import org.h2.message.DbException;
10 import org.h2.message.Trace;
11 import org.h2.table.Table;
12
13 /**
14 * Represents a role. Roles can be granted to users, and to other roles.
15 */
16 public class Role extends RightOwner {
17
18 private final boolean system;
19
20 public Role(Database database, int id, String roleName, boolean system) {
21 super(database, id, roleName, Trace.USER);
22 this.system = system;
23 }
24
25 public String getCreateSQLForCopy(Table table, String quotedName) {
26 throw DbException.throwInternalError();
27 }
28
29 public String getDropSQL() {
30 return null;
31 }
32
33 /**
34 * Get the CREATE SQL statement for this object.
35 *
36 * @param ifNotExists true if IF NOT EXISTS should be used
37 * @return the SQL statement
38 */
39 public String getCreateSQL(boolean ifNotExists) {
40 if (system) {
41 return null;
42 }
43 StringBuilder buff = new StringBuilder("CREATE ROLE ");
44 if (ifNotExists) {
45 buff.append("IF NOT EXISTS ");
46 }
47 buff.append(getSQL());
48 return buff.toString();
49 }
50
51 public String getCreateSQL() {
52 return getCreateSQL(false);
53 }
54
55 public int getType() {
56 return DbObject.ROLE;
57 }
58
59 public void removeChildrenAndResources(Session session) {
60 for (User user : database.getAllUsers()) {
61 Right right = user.getRightForRole(this);
62 if (right != null) {
63 database.removeDatabaseObject(session, right);
64 }
65 }
66 for (Role r2 : database.getAllRoles()) {
67 Right right = r2.getRightForRole(this);
68 if (right != null) {
69 database.removeDatabaseObject(session, right);
70 }
71 }
72 for (Right right : database.getAllRights()) {
73 if (right.getGrantee() == this) {
74 database.removeDatabaseObject(session, right);
75 }
76 }
77 database.removeMeta(session, getId());
78 invalidate();
79 }
80
81 public void checkRename() {
82 // ok
83 }
84
85 }
86