KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > engine > Role


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.engine;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.message.Message;
10 import org.h2.message.Trace;
11 import org.h2.table.Table;
12 import org.h2.util.ObjectArray;
13
14 public class Role extends RightOwner {
15     
16     private boolean system;
17
18     public Role(Database database, int id, String JavaDoc roleName, boolean system) {
19         super(database, id, roleName, Trace.USER);
20         this.system = system;
21     }
22     
23     public String JavaDoc getCreateSQLForCopy(Table table, String JavaDoc quotedName) {
24         throw Message.getInternalError();
25     }
26     
27     public String JavaDoc getCreateSQL() {
28         if(system) {
29             return null;
30         }
31         return "CREATE ROLE "+getSQL();
32     }
33
34     public int getType() {
35         return DbObject.ROLE;
36     }
37
38     public void removeChildrenAndResources(Session session) throws SQLException JavaDoc {
39         ObjectArray users = database.getAllUsers();
40         for(int i=0; i<users.size(); i++) {
41             User user = (User) users.get(i);
42             Right right = user.getRightForRole(this);
43             if(right != null) {
44                 database.removeDatabaseObject(session, right);
45             }
46         }
47         ObjectArray roles = database.getAllRoles();
48         for(int i=0; i<roles.size(); i++) {
49             Role r2 = (Role) roles.get(i);
50             Right right = r2.getRightForRole(this);
51             if(right != null) {
52                 database.removeDatabaseObject(session, right);
53             }
54         }
55         ObjectArray rights = database.getAllRights();
56         for(int i=0; i<rights.size(); i++) {
57             Right right = (Right) rights.get(i);
58             if(right.getGrantee() == this) {
59                 database.removeDatabaseObject(session, right);
60             }
61         }
62         invalidate();
63     }
64
65     public void checkRename() throws SQLException JavaDoc {
66     }
67
68 }
69
Popular Tags