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 21 22 public class UserSessionTable implements _UserSessionTable { 23 24 private _UserSession userSession; 25 26 29 30 private _SessionTable sessionTable; 31 32 35 36 private QualifiedIdentifier tableName; 37 38 41 42 private _PrivilegeTable privilegeTable; 43 44 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 63 64 public RecordVersion insert(int[] columns, Object [] values) throws DException { 65 boolean insertRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.INSERT); 66 if (columns == null && !insertRight) 67 throw new PrivilegeException("DSE340", new Object [] {"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 [] {"INSERT", tableName}); 71 return sessionTable.insert(columns, values); 72 } 73 74 83 84 public RecordVersion insertVersion(int[] columns, Object [] values, java.sql.Date date) throws DException { 85 boolean insertRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.INSERT); 86 if (!insertRight) 87 throw new PrivilegeException("DSE340", new Object [] {"INSERT", tableName}); 88 return sessionTable.insertVersion(columns, values, date); 89 } 90 91 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 [] {"DELETE", tableName}); 103 return sessionTable.delete(iterator); 104 } 105 106 114 115 public RecordVersion deleteVersion(_Iterator iterator, java.sql.Date date) throws DException { 116 boolean deleteRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.DELETE); 117 if (!deleteRight) 118 throw new PrivilegeException("DSE340", new Object [] {"DELETE", tableName}); 119 return sessionTable.deleteVersion(iterator, date); 120 } 121 122 131 132 public RecordVersion update(_Iterator iterator, int[] columns, Object [] values) throws DException { 133 boolean updateRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.UPDATE); 134 if (columns == null && !updateRight) 135 throw new PrivilegeException("DSE340", new Object [] {"UPDATE", tableName}); 136 updateRight = privilegeTable.hasColumnPrivileges(_PrivilegeTable.UPDATE, columns); 137 if (!updateRight) 138 throw new PrivilegeException("DSE340", new Object [] {"UPDATE", tableName}); 139 return sessionTable.update(iterator, columns, values); 140 } 141 142 152 153 public RecordVersion updateVersion(_Iterator iterator, int[] columns, Object [] values, java.sql.Date date) throws DException { 154 boolean updateRight = privilegeTable.hasTablePrivileges(_PrivilegeTable.UPDATE); 155 if (!updateRight) 156 throw new PrivilegeException("DSE340", new Object [] {"UPDATE", tableName}); 157 updateRight = privilegeTable.hasColumnPrivileges(_PrivilegeTable.UPDATE, columns); 158 if (!updateRight) 159 throw new PrivilegeException("DSE340", new Object [] {"UPDATE", tableName}); 160 return sessionTable.updateVersion(iterator, columns, values, date); 161 } 162 163 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 []) pCondition.getVariableValues().getColumnValues(references), 1); 193 } 194 return iterator; 195 } 196 197 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 []) 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 []) pCondition.getVariableValues().getColumnValues(references), 1); 243 } 244 return iterator; 245 } 246 247 public RecordVersion insertWithoutRights(int[] columns, Object [] values) throws DException { 248 return sessionTable.insert(columns, values); 249 } 250 251 public RecordVersion updateWithoutRights(_Iterator iterator, int[] columns, Object [] 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 |