1 package com.daffodilwoods.daffodildb.server.sessionsystem; 2 3 import java.sql.*; 4 import java.sql.Date ; 5 import java.util.*; 6 7 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 8 import com.daffodilwoods.daffodildb.server.serversystem.*; 9 import com.daffodilwoods.daffodildb.utils.comparator.*; 10 import com.daffodilwoods.database.general.*; 11 import com.daffodilwoods.database.resource.*; 12 13 22 23 public class UserSession implements _UserSession { 24 25 private _Session session; 26 27 30 31 private String userName; 32 33 36 37 private _PrivilegeCharacteristics privilegeCharacteristics; 38 39 42 43 private WeakOrderedKeyList userSessionTableList = new WeakOrderedKeyList(new CTusjohDbtfJoTfotjujwfDpnqbsbups()); 44 45 48 49 ArrayList savePoints = new ArrayList(5); 50 51 54 55 public UserSession(_Session session0, String userName0, _PrivilegeCharacteristics privilegeCharacteristics0) throws DException { 56 session = session0; 57 userName = userName0; 58 privilegeCharacteristics = privilegeCharacteristics0; 59 } 60 61 67 68 public _UserSessionTable getUserSessionTable(QualifiedIdentifier tableName) throws DException { 69 _UserSessionTable userSessionTable = (_UserSessionTable) userSessionTableList.get(tableName.getIdentifier()); 70 if (userSessionTable != null) 71 return userSessionTable; 72 _SessionTable sessionTable = session.getSessionTable(tableName); 73 try { 74 _PrivilegeTable privilegeTable = privilegeCharacteristics.getPrivilegeTable(tableName); 75 userSessionTable = new UserSessionTable(tableName, sessionTable, privilegeTable, this); 76 userSessionTableList.put(tableName.getIdentifier(), userSessionTable); 77 return userSessionTable; 78 } catch (DatabaseException ex) { 79 TableException tb = new TableException("DSE810", null); 80 tb.setException(ex); 81 throw tb; 82 } 83 } 84 85 91 92 public Object getTransactionAccessMode() throws DException { 93 return session.getTransactionMode().getTransactionAccessMode(); 94 } 95 96 100 101 public void startSavePoint() throws DException { 102 if (session.getAutoCommit()) 103 return; 104 session.startSavePoint(); 105 } 106 107 114 115 public void commit(_StatementExecutionContext statementExecutionContext) throws DException { 116 int savePoints = session.getNumberOfSavePiontsStarted(); 117 for (int i = 1; i <= savePoints; i++) { 118 session.commitSavePoint(statementExecutionContext); 119 } 120 121 statementExecutionContext.setUserSession(this); 122 session.commit(statementExecutionContext); 123 } 124 125 130 131 public void rollback(_StatementExecutionContext statementExecutionContext) throws DException { 132 int savePoints = session.getNumberOfSavePiontsStarted(); 133 for (int i = 1; i <= savePoints; i++) { 134 session.rollbackSavePoint(statementExecutionContext); 135 } 136 session.rollback(statementExecutionContext); 137 } 138 139 144 145 public _Session getSession() throws DException { 146 return session; 147 } 148 149 154 155 public _PrivilegeCharacteristics getPrivilegeCharacteristics() throws DException { 156 return privilegeCharacteristics; 157 } 158 159 164 165 public String getCurrentRole() throws DException { 166 return session.getCurrentRole(); 167 } 168 169 174 175 public String getCurrentUser() throws DException { 176 return userName; 177 } 178 179 185 186 public boolean isEnabledAuthorizationIdentifier(String authorizationIdentifier) throws DException { 187 return privilegeCharacteristics.isEnabledAuthorizationIdentifier(authorizationIdentifier); 188 } 189 190 195 196 public String getAuthorizationIdentifier() throws DException { 197 return session.getAuthorizationIdentifier(); 198 } 199 200 205 206 public void setTransactionMode(SessionTransactionMode sessionTransactionMode) throws DException { 207 session.setTransactionMode(sessionTransactionMode); 208 } 209 210 215 216 public SessionTransactionMode getTransactionMode() throws DException { 217 return session.getTransactionMode(); 218 } 219 220 225 226 public ArrayList getSavePointVector() throws DException { 227 return savePoints; 228 } 229 230 234 235 public void addSavePoint(Object obj) throws DException { 236 savePoints.add( ( (String ) obj).toUpperCase()); 237 } 238 239 public Date getDate() throws DException { 240 return session.getDate(); 241 } 242 243 public Time getTime() throws DException { 244 return session.getTime(); 245 } 246 247 public int getMonth() throws DException { 248 return session.getMonth(); 249 } 250 251 public int getYear() throws DException { 252 return session.getYear(); 253 } 254 255 public int getHour() throws DException { 256 return session.getHour(); 257 } 258 259 public int getMinutes() throws DException { 260 return session.getMinutes(); 261 } 262 263 public int getSeconds() throws DException { 264 return session.getSeconds(); 265 } 266 267 271 272 public void releaseLastSavePoint() throws DException { 273 savePoints.remove(savePoints.size() - 1); 274 } 275 276 public TimeZone getTimeZone() throws DException { 277 return session.getTimeZone(); 278 } 279 280 public void setConstraintStatus(Object constraintName, String mode) throws DException { 281 session.setConstraintStatus(constraintName, mode); 282 283 } 284 285 public java.sql.Timestamp getTimeStamp() throws DException { 286 return session.getTimeStamp(); 287 288 } 289 290 295 296 public String getUserName() throws DException { 297 return userName; 298 } 299 300 public Object getSessionConstant() throws DException { 301 return session.getSessionConstant(); 302 } 303 304 public _ServerSession getGlobalSession() throws DException { 305 return session.getGlobalSession(); 306 } 307 308 public boolean prepare(_StatementExecutionContext statementExecutionContext) throws DException { 309 session.prepare(statementExecutionContext); 310 return true; 311 } 312 313 public boolean makePersistent(_StatementExecutionContext statementExecutionContext) throws DException { 314 session.makePersistent(statementExecutionContext); 315 return true; 316 } 317 318 323 324 public void setAuthorizationIdentifier(String userName0) throws DException { 325 userName = userName0; 326 _DataDictionary dataDictionary = session.getSessionDatabase().getDataDictionary(); 327 if (session.getAuthorizationIdentifier().equalsIgnoreCase(userName)) 328 dataDictionary.refreshPrivilegeCharacteristics(session.getAuthorizationIdentifier() + _PrivilegeCharacteristics.AUTHORIZATION_USER); 329 else 330 dataDictionary.refreshPrivilegeCharacteristics(session.getAuthorizationIdentifier() + _PrivilegeCharacteristics.AUTHORIZATION_ROLE); 331 AuthorizationIdentifier authoriz = new AuthorizationIdentifier(); 332 authoriz.setUser(userName); 333 userSessionTableList = new WeakOrderedKeyList(new CTusjohDbtfJoTfotjujwfDpnqbsbups()); 334 privilegeCharacteristics = dataDictionary.getPrivilegeCharacteristics(userName, _PrivilegeCharacteristics.AUTHORIZATION_USER); 335 session.pushAuthorizationIdentifier(authoriz); 336 } 337 338 343 344 public void setPrivilegeCharacteristics(_PrivilegeCharacteristics priCharacteristics) throws DException { 345 privilegeCharacteristics = priCharacteristics; 346 } 347 348 352 353 public void removeAllTables() throws DException { 354 WeakOrderedKeyList.WeakOrderedKeyListIterator iterator = userSessionTableList.getWeakOrderedKeyListIterator(); 355 if (iterator.top()) 356 do { 357 Object key = iterator.getKey(); 358 userSessionTableList.remove(key); 359 } while (iterator.next()); 360 session.removeAllTables(); 361 } 362 363 public void removeTable(QualifiedIdentifier tableName) throws DException { 364 userSessionTableList.remove(tableName.getIdentifier()); 365 session.removeTable(tableName); 366 } 367 368 public void commitSavePoint(_StatementExecutionContext sec) throws DException { 369 if (session.getAutoCommit()) 370 return; 371 sec.setUserSession(this); 372 session.commitSavePoint(sec); 373 } 374 375 public void rollbackSavePoint(_StatementExecutionContext sec) throws DException { 376 if (session.getAutoCommit()) { 377 rollback(sec); 378 return; 379 } 380 381 session.rollbackSavePoint(sec); 382 } 383 384 public void releaseSavePoint(_StatementExecutionContext sec) throws DException { 385 sec.setUserSession(this); 386 session.releaseSavePoint(sec); 387 } 388 389 public void hideSavePoint() throws DException { 390 session.hideSavePoint(); 391 } 392 393 public void unhideSavePoint() throws DException { 394 session.unhideSavePoint(); 395 } 396 397 public void ignoreParallelSavePoint() throws DException { 398 session.ignoreParallelSavePoint(); 399 } 400 401 public void allowParallelSavePoint() throws DException { 402 session.allowParallelSavePoint(); 403 } 404 405 public void checkImmediateConstraintsOnCommit() throws DException { 406 session.checkImmediateConstraintsOnCommit(); 407 } 408 409 public void setRole(String roleName) throws DException { 410 _DataDictionary dataDictionary = session.getSessionDatabase().getDataDictionary(); 411 if (session.getAuthorizationIdentifier().equalsIgnoreCase(userName)) 412 dataDictionary.refreshPrivilegeCharacteristics(session.getAuthorizationIdentifier() + _PrivilegeCharacteristics.AUTHORIZATION_USER); 413 else 414 dataDictionary.refreshPrivilegeCharacteristics(session.getAuthorizationIdentifier() + _PrivilegeCharacteristics.AUTHORIZATION_ROLE); 415 AuthorizationIdentifier authoriz = new AuthorizationIdentifier(); 416 userSessionTableList = new WeakOrderedKeyList(new CTusjohDbtfJoTfotjujwfDpnqbsbups()); 417 if (roleName == null) { 418 privilegeCharacteristics = dataDictionary.getPrivilegeCharacteristics(userName, _PrivilegeCharacteristics.AUTHORIZATION_USER); 419 authoriz.setUser(userName); 420 } else { 421 privilegeCharacteristics = dataDictionary.getPrivilegeCharacteristics(roleName, _PrivilegeCharacteristics.AUTHORIZATION_ROLE); 422 authoriz.setRole(roleName); 423 } 424 session.pushAuthorizationIdentifier(authoriz); 425 } 426 427 public void setAutoCommit(boolean autoCommit0) { 428 session.setAutoCommit(autoCommit0); 429 } 430 431 public boolean getAutoCommit() { 432 return session.getAutoCommit(); 433 } 434 435 public void startTransaction() throws DException { 436 session.startTransaction(); 437 } 438 } 439 | Popular Tags |