KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datadictionarysystem > PrivilegeCharacteristics


1 package com.daffodilwoods.daffodildb.server.datadictionarysystem;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.serversystem.*;
6 import com.daffodilwoods.daffodildb.server.sql99.common.*;
7 import com.daffodilwoods.daffodildb.server.sql99.ddl.utility.*;
8 import com.daffodilwoods.daffodildb.utils.comparator.*;
9 import com.daffodilwoods.database.general.*;
10 import com.daffodilwoods.database.resource.*;
11 import com.daffodilwoods.database.utility.*;
12
13 public class PrivilegeCharacteristics implements _PrivilegeCharacteristics {
14
15    private PreparedStatementGetter preparedStatementGetter;
16    private _DataDictionary dataDictionary;
17    private String JavaDoc authorizationIdentifier;
18    private String JavaDoc[] applicableRoles;
19
20    private Map privilegeTableMap;
21    private String JavaDoc[] enabledAuthorizations;
22
23    public PrivilegeCharacteristics(PreparedStatementGetter preparedStatementGetter0, String JavaDoc authorizationIdentifier0, int authorizationType, _DataDictionary dataDictionary0) throws DException {
24       preparedStatementGetter = preparedStatementGetter0;
25       authorizationIdentifier = authorizationIdentifier0;
26       if (authorizationType == AUTHORIZATION_ROLE) {
27          applicableRoles = GeneralUtility.getApplicableRoleNames(preparedStatementGetter0, authorizationIdentifier);
28       }
29       dataDictionary = dataDictionary0;
30       privilegeTableMap = Collections.synchronizedMap(new TreeMap(new CRvbmjgjfeDpnqbsbups()));
31    }
32
33    public _PrivilegeTable getPrivilegeTable(QualifiedIdentifier tableName) throws DException {
34       _PrivilegeTable privilegeTable = (_PrivilegeTable) privilegeTableMap.get(tableName);
35       if (privilegeTable != null)
36          return privilegeTable;
37       synchronized (this) {
38          privilegeTable = (_PrivilegeTable) privilegeTableMap.get(tableName);
39          if (privilegeTable != null)
40             return privilegeTable;
41          if (authorizationIdentifier.equalsIgnoreCase(SystemTables.SYSTEM)) {
42             privilegeTable = new SystemPrivilegeTable(preparedStatementGetter);
43          } else if (authorizationIdentifier.equalsIgnoreCase(ServerSystem.browserUser)) {
44             privilegeTable = new BrowserUserPrivilegeTable(dataDictionary,
45                 preparedStatementGetter, tableName);
46          } else {
47             privilegeTable = new PrivilegeTable(dataDictionary,
48                                                 preparedStatementGetter, tableName);
49             ( (PrivilegeTable) privilegeTable).setAuthorization(
50                 authorizationIdentifier);
51             ( (PrivilegeTable) privilegeTable).setApplicableRole(applicableRoles);
52          }
53          updateTableMap();
54          privilegeTableMap.put(tableName, privilegeTable);
55          return privilegeTable;
56       }
57
58    }
59
60    public void removeTable(QualifiedIdentifier tableName) throws DException {
61       privilegeTableMap.remove(tableName);
62    }
63
64    private void updateTableMap() {
65       if (privilegeTableMap.size() > 25) {
66          Object JavaDoc[] obj = privilegeTableMap.keySet().toArray();
67          if (obj.length > 0)
68             privilegeTableMap.remove(obj[0]);
69       }
70    }
71
72    public _PrivilegeTable getRoutinePrivilegeTable() throws DException {
73       if (authorizationIdentifier.equalsIgnoreCase(SystemTables.SYSTEM)) {
74          return new SystemPrivilegeTable(preparedStatementGetter);
75       } else if (authorizationIdentifier.equalsIgnoreCase(ServerSystem.browserUser)) {
76          return new BrowserUserPrivilegeTable(dataDictionary,
77                                               preparedStatementGetter, null);
78       } else {
79          PrivilegeTable privilegeTable = new PrivilegeTable(dataDictionary,
80              preparedStatementGetter, null);
81          privilegeTable.setAuthorization(authorizationIdentifier);
82          privilegeTable.setApplicableRole(applicableRoles);
83          return privilegeTable;
84       }
85    }
86
87    public boolean isEnabledAuthorizationIdentifier(String JavaDoc authorizationIdentifier0) throws DException {
88       if (enabledAuthorizations == null) {
89          int len = applicableRoles == null ? 0 : applicableRoles.length;
90          enabledAuthorizations = new String JavaDoc[2 + len];
91          enabledAuthorizations[0] = authorizationIdentifier;
92          enabledAuthorizations[1] = SqlKeywords.PUBLIC;
93          if (len != 0) {
94             System.arraycopy(applicableRoles, 0, enabledAuthorizations, 2, len);
95          }
96       }
97       return P.indexOfIgnoreCase(enabledAuthorizations, authorizationIdentifier0) != -1;
98    }
99
100 }
101
Popular Tags