KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > ddl > descriptors > TablePrivilegesDescriptor


1 package com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
6 import com.daffodilwoods.daffodildb.server.serversystem.*;
7 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem.*;
8 import com.daffodilwoods.daffodildb.server.sql99.common.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
10 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
11 import com.daffodilwoods.database.general.*;
12 import com.daffodilwoods.database.resource.*;
13
14 public class TablePrivilegesDescriptor extends PrivilegeDescriptor {
15
16    public String JavaDoc privilege_type;
17    public String JavaDoc with_hierarchy = SqlSchemaConstants.NO;
18
19    public TablePrivilegesDescriptor() throws DException {
20    }
21
22    public TablePrivilegesDescriptor(TablePrivilegesDescriptor tpd) throws DException {
23       object_catalog = (tpd.object_catalog == null)
24           ? null : tpd.object_catalog.toString();
25       object_name = (tpd.object_name == null)
26           ? null : tpd.object_name.toString();
27       object_schema = (tpd.object_schema == null)
28           ? null : tpd.object_schema.toString();
29       privilege_type = (tpd.privilege_type == null)
30         ? null : tpd.privilege_type;
31       with_hierarchy = (tpd.with_hierarchy == null)
32           ? null : tpd.with_hierarchy;
33       grantee = (tpd.grantee == null) ? null : tpd.grantee.toString();
34       grantor = (tpd.grantor == null) ? null : tpd.grantor.toString();
35       is_grantable = (tpd.is_grantable == null)
36           ? null : tpd.is_grantable.toString();
37    }
38
39    public int hashCode() {
40       return privilege_type.toUpperCase().hashCode() * 3
41           + getGrantee().toUpperCase().hashCode() * 7
42           + getGrantor().toUpperCase().hashCode() * 11
43           + object_catalog.toUpperCase().hashCode() * 13
44           + object_schema.toUpperCase().hashCode() * 17
45           + object_name.toUpperCase().hashCode() * 19;
46    }
47
48    public boolean equals(Object JavaDoc temp) {
49       if (! (temp instanceof TablePrivilegesDescriptor)) {
50          return false;
51       }
52
53       TablePrivilegesDescriptor pd = (TablePrivilegesDescriptor) temp;
54       return ( ( (privilege_type == null) && (pd.privilege_type == null))
55               || privilege_type.equalsIgnoreCase(pd.privilege_type))
56           && ( ( (with_hierarchy == null) && (pd.with_hierarchy == null))
57               || with_hierarchy.equalsIgnoreCase(pd.with_hierarchy))
58           && ( ( (getGrantee() == null) && (pd.getGrantee() == null))
59               || getGrantee().equalsIgnoreCase(pd.getGrantee()))
60           && ( ( (getGrantor() == null) && (pd.getGrantor() == null))
61               || getGrantor().equalsIgnoreCase(pd.getGrantor()))
62           && ( ( (object_catalog == null) && (pd.object_catalog == null))
63               || object_catalog.equalsIgnoreCase(pd.object_catalog))
64           && ( ( (object_schema == null) && (pd.object_schema == null))
65               || object_schema.equalsIgnoreCase(pd.object_schema))
66           && ( ( (object_name == null) && (pd.object_name == null))
67               || object_name.equalsIgnoreCase(pd.object_name))
68           && ( ( (is_grantable == null) && (pd.is_grantable == null))
69               || is_grantable.equalsIgnoreCase(pd.is_grantable));
70    }
71
72    public void load(_ServerSession serverSession) throws DException {
73       DataDictionary dd = (DataDictionary) serverSession.getDataDictionary();
74       _SelectQueryIterator iter = (_SelectQueryIterator) dd.getPreparedStatementGetter().
75           getTablePrivlegesTableExecuter().executeForFresh(new Object JavaDoc[] {grantor,
76           grantee, object_catalog, object_schema, object_name, privilege_type});
77       if (!iter.first()) {
78          throw new DException("DSE265", new Object JavaDoc[] {object_catalog,
79                               object_schema, object_name, privilege_type});
80       } else {
81          Object JavaDoc[] values = (Object JavaDoc[]) iter.getObject();
82          is_grantable = (String JavaDoc) values[SystemTablesFields.
83              tablePrivileges_is_grantable];
84          with_hierarchy = (String JavaDoc) values[SystemTablesFields.
85              tablePrivileges_with_hierarchy];
86       }
87    }
88
89    public void save(_ServerSession serverSession) throws DException {
90       Object JavaDoc[] parameters = new Object JavaDoc[] {
91           grantor, grantee, object_catalog,
92           object_schema, object_name, privilege_type, is_grantable,
93           with_hierarchy};
94       try {
95          SqlSchemaConstants.insert(serverSession,
96                                    SqlSchemaConstants.table_privileges_TableName,
97                                    null, parameters);
98       } catch (PrimaryConstraintException de) {
99          throw new DException("DSE1138", new Object JavaDoc[] {privilege_type,
100                               grantor, grantee, getTableName()});
101       } catch (SizeMisMatchException de) {
102          if (de.getDseCode().equals("DSE773")) {
103             DException tde = new DException("DSE8103", null);
104             throw tde;
105          }
106       } catch (DException de) {
107          if (de.getDseCode().equals("DSE1255")) {
108             throw new DException("DSE1138", new Object JavaDoc[] {privilege_type,
109                                  grantor, grantee, getTableName()});
110          }
111          if (de.getDseCode().equals("DSE773")) {
112             DException tde = new DException("DSE8103", null);
113             throw tde;
114          }
115          throw de;
116       }
117    }
118
119    public void saveColumnsPrivilegeDescriptor(_ServerSession serverSession, ArrayList all_col, TablePrivilegesDescriptor tpd, ArrayList grantee_list) throws DException {
120       for (int i = 0, size = all_col.size(); i < size; i++) {
121          ColumnDescriptor temp_col = (ColumnDescriptor) all_col.get(i);
122          if (temp_col.column_name.equalsIgnoreCase(SystemFields.systemFields[SystemFields.rowId])) {
123             if (! (tpd.privilege_type.equalsIgnoreCase(SqlKeywords.SELECT) || tpd.privilege_type.equalsIgnoreCase(SqlKeywords.REFERENCES))) {
124                continue;
125             }
126          }
127          if (tpd.privilege_type.equalsIgnoreCase(SqlKeywords.DELETE) || tpd.privilege_type.equalsIgnoreCase(SqlKeywords.TRIGGER)) {
128             continue;
129          }
130          ColumnPrivilegeDescriptor cpd = new ColumnPrivilegeDescriptor();
131          cpd.setGrantor(tpd.grantor);
132          cpd.object_catalog = tpd.object_catalog.toString();
133          cpd.object_schema = tpd.object_schema.toString();
134          cpd.object_name = tpd.object_name.toString();
135          cpd.column_name = temp_col.column_name.toString();
136           cpd.privilege_type = tpd.privilege_type;
137          cpd.is_grantable = tpd.is_grantable.toString();
138          for (int j = 0, tempsize = grantee_list.size(); j < tempsize; j++) {
139             cpd.setGrantee(grantee_list.get(j));
140             try {
141                cpd.save(serverSession);
142             } catch (DException de) {
143                if (de.getDseCode().equals("DSE1139") && cpd.is_grantable.equalsIgnoreCase(SqlSchemaConstants.YES)) {
144                   cpd.updateIsGrantableValue(serverSession, cpd.is_grantable);
145                }
146             }
147          }
148       }
149    }
150
151    public void loadDataFromRecord(_SelectQueryIterator iter) throws DException {
152       Object JavaDoc[] values = (Object JavaDoc[]) iter.getObject();
153       grantor = values[SystemTablesFields.tablePrivileges_grantor];
154       grantee = values[SystemTablesFields.tablePrivileges_grantee];
155       object_catalog = (String JavaDoc) values[SystemTablesFields.tablePrivileges_object_catalog];
156       object_schema = (String JavaDoc) values[SystemTablesFields.tablePrivileges_object_schema];
157       object_name = (String JavaDoc) values[SystemTablesFields.tablePrivileges_object_name];
158       privilege_type = (String JavaDoc) values[SystemTablesFields.tablePrivileges_privilege_type];
159       is_grantable = (String JavaDoc) values[SystemTablesFields.tablePrivileges_is_grantable];
160       with_hierarchy = (String JavaDoc) values[SystemTablesFields.tablePrivileges_with_hierarchy];
161    }
162
163    public void delete(_ServerSession serverSession) throws DException {
164       booleanvalueexpression condition = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getTablePrivlegesTableCondition();
165       super.deleteTablePrivilegeDescriptor(serverSession, SqlSchemaConstants.table_privileges_TableName, condition, new Object JavaDoc[] {grantor, grantee, object_catalog, object_schema, object_name, privilege_type});
166    }
167
168    private String JavaDoc getTableName() {
169       StringBuffer JavaDoc tableName = new StringBuffer JavaDoc();
170       tableName.append(object_catalog).append(".").append(object_schema)
171           .append(".").append(object_name);
172       return tableName.toString();
173    }
174
175    public int getDescriptorType() {
176       return TABLE_PRIVILEGE_DESCRIPTOR;
177    }
178
179    public void updateIsGrantableValue(_ServerSession serversession, String JavaDoc isGrantable) throws DException {
180       booleanvalueexpression condition = ( (DataDictionary) serversession.
181                                           getDataDictionary()).
182           getPreparedStatementGetter().getTablePrivlegesTableCondition();
183       super.update(serversession, SystemTables.table_privileges_TableName, condition,
184                    new Object JavaDoc[] {grantor, grantee, object_catalog, object_schema,
185                    object_name, privilege_type}
186                    ,
187                    new Object JavaDoc[] {isGrantable}
188                    ,
189                    new int[] {SystemTablesFields.tablePrivileges_is_grantable});
190    }
191
192 }
193
Popular Tags