KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sessionsystem > UserSessionTable


1 package com.daffodilwoods.daffodildb.server.sessionsystem;
2
3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
5 import com.daffodilwoods.daffodildb.server.datasystem.utility.*;
6 import com.daffodilwoods.daffodildb.server.serversystem.*;
7 import com.daffodilwoods.daffodildb.server.sql99.common.*;
8 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
9 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
10 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
11 import com.daffodilwoods.database.general.*;
12 import com.daffodilwoods.database.resource.*;
13 import com.daffodilwoods.database.utility.P;
14
15 /**
16  * wrapper over the Session Table which is responsible for checking of privileges
17  * of the user for which this object has been taken. It checks the table level
18  * privileges as well as column level privileges for read and write operations.
19  * After verifying, it passes all the calls to SessionTable to complete the operation.
20  */

21
22 public class UserSessionTable implements _UserSessionTable {
23
24    private _UserSession userSession;
25
26    /**
27     * Object of session table for performing Read and Write operations
28     */

29
30    private _SessionTable sessionTable;
31
32    /**
33     * Qualified name of the table
34     */

35
36    private QualifiedIdentifier tableName;
37
38    /**
39     * Object of Privilege Table to check the privileges
40     */

41
42    private _PrivilegeTable privilegeTable;
43
44    /**
45     * Constructs the UserSessionTable
46     */

47
48    public UserSessionTable(QualifiedIdentifier tableName0, _SessionTable sessionTable0, _PrivilegeTable privilegeTable0, _UserSession userSession0) throws DException {
49       tableName = tableName0;
50       sessionTable = sessionTable0;
51       userSession = userSession0;
52       privilegeTable = privilegeTable0;
53    }
54
55    /**
56     * After verifying the privileges, forwards the call to interface _SessionTable
57     * to insert the record in memory.
58     * @param columns indexes of columns whose values are to be inserted
59     * @param values values to be inserted
60     * @return returns an event with the type insert
61     * @throws DException
62     */

63
64    public RecordVersion insert(int[] columns, Object JavaDoc[] values) throws DException {
65       boolean insertRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.INSERT);
66       if (columns == null && !insertRight)
67          throw new PrivilegeException("DSE340", new Object JavaDoc[] {"INSERT", tableName});
68       insertRight = privilegeTable.hasColumnPrivileges(_PrivilegeTable.INSERT, columns);
69       if (!insertRight && columns != null && ! (columns[0] == SystemFields.invalidSessionId && columns.length == 1))
70          throw new PrivilegeException("DSE340", new Object JavaDoc[] {"INSERT", tableName});
71       return sessionTable.insert(columns, values);
72    }
73
74    /**
75     * After verifying the privileges, forwards the call to interface
76     * _SessionTable.
77     * @param columns indexes of columns whose values are to be inserted
78     * @param values values to be inserted
79     * @param date value of the fromDate column
80     * @return returns an event with the type insert
81     * @throws DException
82     */

83
84    public RecordVersion insertVersion(int[] columns, Object JavaDoc[] values, java.sql.Date JavaDoc date) throws DException {
85       boolean insertRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.INSERT);
86       if (!insertRight)
87          throw new PrivilegeException("DSE340", new Object JavaDoc[] {"INSERT", tableName});
88       return sessionTable.insertVersion(columns, values, date);
89    }
90
91    /**
92     * After verifying the privileges, forwards the call to interface _
93     * SessionTable to delete the record.
94     * @param iterator provides the record which is to be deleted
95     * @return returns an event with the type delete
96     * @throws DException
97     */

98
99    public RecordVersion delete(_Iterator iterator) throws DException {
100       boolean deleteRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.DELETE);
101       if (!deleteRight)
102          throw new PrivilegeException("DSE340", new Object JavaDoc[] {"DELETE", tableName});
103       return sessionTable.delete(iterator);
104    }
105
106    /**
107     * After verifying the privileges, forwards the call to interface _
108     * SessionTable to delete the record.
109     * @param iterator provides the record which is to be deleted
110     * @param date date which is to be set in ToDate column to mark it as deleted
111     * @return returns an event with the type delete
112     * @throws DException
113     */

114
115    public RecordVersion deleteVersion(_Iterator iterator, java.sql.Date JavaDoc date) throws DException {
116       boolean deleteRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.DELETE);
117       if (!deleteRight)
118          throw new PrivilegeException("DSE340", new Object JavaDoc[] {"DELETE", tableName});
119       return sessionTable.deleteVersion(iterator, date);
120    }
121
122    /**
123     * After verifying the privileges on table and columns passed by user, forwards
124     * call to _SessionTable interaface.
125     * @param iterator provides the record which is to be deleted
126     * @param columns indexes of columns whose values are to be inserted
127     * @param values values to be inserted
128     * @return returns an event with the type update
129     * @throws DException
130     */

131
132    public RecordVersion update(_Iterator iterator, int[] columns, Object JavaDoc[] values) throws DException {
133       boolean updateRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.UPDATE);
134       if (columns == null && !updateRight)
135          throw new PrivilegeException("DSE340", new Object JavaDoc[] {"UPDATE", tableName});
136       updateRight = privilegeTable.hasColumnPrivileges(_PrivilegeTable.UPDATE, columns);
137       if (!updateRight)
138          throw new PrivilegeException("DSE340", new Object JavaDoc[] {"UPDATE", tableName});
139       return sessionTable.update(iterator, columns, values);
140    }
141
142    /**
143     * After verifying the privileges on table and columns passed by user, forwards
144     * call to _SessionTable interaface.
145     * @param iterator provides the record which is to be deleted
146     * @param columns indexes of columns whose values are to be inserted
147     * @param values values to be inserted
148     * @param date date upto which record is to be marked as invalid
149     * @return returns an event with the type update
150     * @throws DException
151     */

152
153    public RecordVersion updateVersion(_Iterator iterator, int[] columns, Object JavaDoc[] values, java.sql.Date JavaDoc date) throws DException {
154       boolean updateRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.UPDATE);
155       if (!updateRight)
156          throw new PrivilegeException("DSE340", new Object JavaDoc[] {"UPDATE", tableName});
157       updateRight = privilegeTable.hasColumnPrivileges(_PrivilegeTable.UPDATE, columns);
158       if (!updateRight)
159          throw new PrivilegeException("DSE340", new Object JavaDoc[] {"UPDATE", tableName});
160       return sessionTable.updateVersion(iterator, columns, values, date);
161    }
162
163    /**
164     * Provides an iterator to fetch the records after verifying the privileges
165     * @param _SingleTableExecuter This object contains the condition and order
166     * @param _ServerSession Object of serverSession which is used to get the
167     * information for inner query
168     * @return returns an object of _Iterator interaface to fetch the record
169     * @throws DException
170     */

171
172    public _Iterator getIterator(_SingleTableExecuter singleTableExecuter, _ServerSession serverSession) throws DException {
173       if (singleTableExecuter.checkUserRight()) {
174          boolean fetchRight = false;
175          if (singleTableExecuter.getColumns() != null) {
176             fetchRight = privilegeTable.hasColumnPrivileges(_PrivilegeTable.SELECT, singleTableExecuter.getColumns());
177             if (!fetchRight) {
178                throw new DException("DSE8132", null);
179             }
180          } else if (singleTableExecuter.getColumns() == null) {
181             fetchRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.SELECT);
182             if (!fetchRight) {
183                throw new DException("DSE342", null);
184             }
185          }
186       }
187       ParameterisedCondition pCondition = privilegeTable.getPrivilegeCondition();
188       singleTableExecuter.addCondition(pCondition.getBVE());
189       _Reference[] references = GeneralPurposeStaticClass.changeReferences(pCondition.getBVE().getParameters(null));
190       _Iterator iterator = sessionTable.getIterator(singleTableExecuter, serverSession);
191       if (references != null && references.length != 0) {
192          iterator.setConditionVariableValue(references, (Object JavaDoc[]) pCondition.getVariableValues().getColumnValues(references), 1);
193       }
194       return iterator;
195    }
196
197    /**
198     * Provides an iterator to fetch the records of both referencing as well as
199     * referenced after verifying the privileges
200     * @param _SingleTableExecuter This object contains the condition and order
201     * @param _IndexTable Object of ForeignConstraint table which is having
202     * all the information required to make the Foreign key iterator.
203     * @return returns an object of _Iterator interaface to fetch the record
204     * @throws DException
205     */

206
207    public _Iterator getForeignConstraintIterator(_SingleTableExecuter conditionExecuter, _IndexTable foreignConstraintTable) throws DException {
208       boolean fetchRight = false;
209       try {
210          fetchRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.SELECT);
211       } catch (DatabaseException ex) {
212          throw new DException("DSE342", null);
213       }
214       if (!fetchRight)
215          throw new DException("DSE342", null);
216       ParameterisedCondition pCondition = privilegeTable.getPrivilegeCondition();
217       conditionExecuter.addCondition(pCondition.getBVE());
218       _Reference[] references = (_Reference[]) pCondition.getBVE().getParameters(null);
219       _Iterator iterator = sessionTable.getForeignConstraintIterator(conditionExecuter, foreignConstraintTable);
220       if (references != null) {
221          iterator.setConditionVariableValue(references, (Object JavaDoc[]) pCondition.getVariableValues().getColumnValues(references), 1);
222       }
223       return new SessionIterator(iterator);
224
225    }
226
227    public _Iterator getInternalIterator(_SingleTableExecuter singleTableExecuter, _ServerSession serverSession) throws DException {
228       boolean fetchRight = false;
229       if (singleTableExecuter.getColumns() != null) {
230          fetchRight = privilegeTable.hasColumnPrivileges(_PrivilegeTable.SELECT,
231              singleTableExecuter.getColumns());
232          if (!fetchRight) {
233             throw new DException("DSE8132", null);
234          }
235       }
236
237       ParameterisedCondition pCondition = privilegeTable.getPrivilegeCondition();
238       singleTableExecuter.addCondition(pCondition.getBVE());
239       _Reference[] references = GeneralPurposeStaticClass.changeReferences(pCondition.getBVE().getParameters(null));
240       _Iterator iterator = sessionTable.getConditionalIterator(singleTableExecuter, serverSession);
241       if (references != null && references.length != 0) {
242          iterator.setConditionVariableValue(references, (Object JavaDoc[]) pCondition.getVariableValues().getColumnValues(references), 1);
243       }
244       return iterator;
245    }
246
247    public RecordVersion insertWithoutRights(int[] columns, Object JavaDoc[] values) throws DException {
248       return sessionTable.insert(columns, values);
249    }
250
251    public RecordVersion updateWithoutRights(_Iterator iterator, int[] columns, Object JavaDoc[] values) throws DException {
252       return sessionTable.update(iterator, columns, values);
253    }
254
255    public RecordVersion deleteWithoutRights(_Iterator iterator) throws DException {
256       return sessionTable.delete(iterator);
257    }
258
259    public _PrivilegeTable getPrivilegeTable() throws DException {
260       return privilegeTable;
261    }
262 }
263
Popular Tags