1 21 package oracle.toplink.essentials.internal.sessions; 23 24 import java.util.*; 25 import java.io.*; 26 import oracle.toplink.essentials.descriptors.ClassDescriptor; 27 import oracle.toplink.essentials.internal.helper.*; 28 import oracle.toplink.essentials.platform.server.ServerPlatform; 29 import oracle.toplink.essentials.queryframework.*; 30 import oracle.toplink.essentials.expressions.*; 31 import oracle.toplink.essentials.internal.identitymaps.*; 32 import oracle.toplink.essentials.internal.descriptors.*; 33 import oracle.toplink.essentials.internal.databaseaccess.*; 34 import oracle.toplink.essentials.exceptions.*; 35 import oracle.toplink.essentials.sessions.*; 36 import oracle.toplink.essentials.internal.sequencing.Sequencing; 37 import oracle.toplink.essentials.logging.*; 38 import oracle.toplink.essentials.internal.sessions.AbstractRecord; 39 import oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl; 40 import oracle.toplink.essentials.internal.helper.ConcurrencyManager; 41 import oracle.toplink.essentials.internal.helper.IdentityHashtable; 42 43 72 public abstract class AbstractSession implements oracle.toplink.essentials.sessions.Session, java.io.Serializable , java.lang.Cloneable { 73 74 75 transient protected ExceptionHandler exceptionHandler; 76 77 78 transient protected IntegrityChecker integrityChecker; 79 80 81 transient protected oracle.toplink.essentials.sessions.Project project; 82 83 84 transient protected ConcurrencyManager transactionMutex; 85 86 87 protected oracle.toplink.essentials.internal.sessions.IdentityMapAccessor identityMapAccessor; 88 89 90 protected boolean wasJTSTransactionInternallyStarted; 91 92 93 transient protected Accessor accessor; 94 95 96 transient protected Platform platform; 97 98 99 transient protected Map queries; 100 101 102 transient protected List ejbqlPlaceHolderQueries; 103 104 105 transient protected CommitManager commitManager; 106 107 108 transient protected SessionProfiler profiler; 109 110 111 transient protected AbstractSession broker; 112 113 114 protected String name; 115 116 117 transient protected int numberOfActiveUnitsOfWork; 118 119 120 transient protected SessionLog sessionLog; 121 122 123 transient protected String logSessionString; 124 125 126 transient protected SessionEventManager eventManager; 127 128 129 protected Map properties; 130 131 132 transient protected ExternalTransactionController externalTransactionController; 133 134 135 transient protected ClassDescriptor lastDescriptorAccessed; 136 137 138 public boolean isInProfile; 139 140 147 protected AbstractSession() { 148 this.name = ""; 149 initializeIdentityMapAccessor(); 150 this.numberOfActiveUnitsOfWork = 0; 152 } 153 154 158 protected AbstractSession(int nothing) { 159 } 160 161 170 public AbstractSession(Login login) { 171 this(new oracle.toplink.essentials.sessions.Project(login)); 172 } 173 174 182 public AbstractSession(oracle.toplink.essentials.sessions.Project project) { 183 this(); 184 this.project = project; 185 if (project.getDatasourceLogin() == null) { 186 throw ValidationException.projectLoginIsNull(this); 187 } 188 } 189 190 195 public long getNextQueryId() { 196 return QueryCounter.getCount(); 197 } 198 199 203 public UnitOfWorkImpl acquireNonSynchronizedUnitOfWork() { 204 setNumberOfActiveUnitsOfWork(getNumberOfActiveUnitsOfWork() + 1); 205 UnitOfWorkImpl unitOfWork = new UnitOfWorkImpl(this); 206 if (shouldLog(SessionLog.FINER, SessionLog.TRANSACTION)) { 207 log(SessionLog.FINER, SessionLog.TRANSACTION, "acquire_unit_of_work_with_argument", String.valueOf(System.identityHashCode(unitOfWork))); 208 } 209 return unitOfWork; 210 } 211 212 220 public UnitOfWork acquireUnitOfWork() { 221 UnitOfWorkImpl unitOfWork = acquireNonSynchronizedUnitOfWork(); 222 unitOfWork.registerWithTransactionIfRequired(); 223 224 return unitOfWork; 225 } 226 227 231 public void addAlias(String alias, ClassDescriptor descriptor) { 232 project.addAlias(alias, descriptor); 233 } 234 235 240 public void addQuery(String name, DatabaseQuery query) { 241 query.setName(name); 242 addQuery(query); 243 } 244 245 250 public void addEjbqlPlaceHolderQuery(DatabaseQuery query) { 251 getEjbqlPlaceHolderQueries().add(query); 252 } 253 254 258 protected void addQuery(DatabaseQuery query) { 259 Vector queriesByName = (Vector)getQueries().get(query.getName()); 260 if (queriesByName == null) { 261 queriesByName = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); 263 getQueries().put(query.getName(), queriesByName); 264 } 265 266 for (Enumeration enumtr = queriesByName.elements(); enumtr.hasMoreElements();) { 268 DatabaseQuery existingQuery = (DatabaseQuery)enumtr.nextElement(); 269 if (Helper.areTypesAssignable(query.getArgumentTypes(), existingQuery.getArgumentTypes())) { 270 throw ValidationException.existingQueryTypeConflict(query, existingQuery); 271 } 272 } 273 queriesByName.add(query); 274 } 275 276 281 protected void basicBeginTransaction() throws DatabaseException { 282 try { 283 getAccessor().beginTransaction(this); 284 } catch (RuntimeException exception) { 285 handleException(exception); 286 } 287 } 288 289 293 public void afterTransaction(boolean committed, boolean isExternalTransaction) { 294 } 295 296 301 protected void basicCommitTransaction() throws DatabaseException { 302 try { 303 getAccessor().commitTransaction(this); 304 } catch (RuntimeException exception) { 305 handleException(exception); 306 } 307 } 308 309 314 protected void basicRollbackTransaction() throws DatabaseException { 315 try { 316 getAccessor().rollbackTransaction(this); 317 } catch (RuntimeException exception) { 318 handleException(exception); 319 } 320 } 321 322 330 public boolean beginExternalTransaction() { 331 boolean externalTransactionHasBegun = false; 332 if (hasExternalTransactionController() && !wasJTSTransactionInternallyStarted()) { 333 try { 334 getExternalTransactionController().beginTransaction(this); 335 } catch (RuntimeException exception) { 336 handleException(exception); 337 } 338 if (wasJTSTransactionInternallyStarted()) { 339 externalTransactionHasBegun = true; 340 log(SessionLog.FINER, SessionLog.TRANSACTION, "external_transaction_has_begun_internally"); 341 } 342 } 343 return externalTransactionHasBegun; 344 } 345 346 359 public void beginTransaction() throws DatabaseException, ConcurrencyException { 360 if (!isInTransaction()) { 365 beginExternalTransaction(); 366 } 367 368 if (isUnitOfWork() || isClientSession()) { 371 getTransactionMutex().setActiveThread(Thread.currentThread()); 372 } 373 374 getTransactionMutex().acquire(); 376 if (!getTransactionMutex().isNested()) { 377 getEventManager().preBeginTransaction(); 378 basicBeginTransaction(); 379 getEventManager().postBeginTransaction(); 380 } 381 } 382 383 387 public void clearIntegrityChecker() { 388 setIntegrityChecker(null); 389 } 390 391 395 public void clearLastDescriptorAccessed() { 396 lastDescriptorAccessed = null; 397 } 398 399 403 public void clearProfile() { 404 setProfiler(null); 405 } 406 407 411 public Object clone() { 412 try { 414 return super.clone(); 415 } catch (Exception exception) { 416 return null; 417 } 418 } 419 420 428 public boolean commitExternalTransaction() { 429 boolean externalTransactionHasCommitted = false; 430 if (hasExternalTransactionController() && wasJTSTransactionInternallyStarted()) { 431 try { 432 getExternalTransactionController().commitTransaction(this); 433 } catch (RuntimeException exception) { 434 handleException(exception); 435 } 436 if (!wasJTSTransactionInternallyStarted()) { 437 externalTransactionHasCommitted = true; 438 log(SessionLog.FINER, SessionLog.TRANSACTION, "external_transaction_has_committed_internally"); 439 } 440 } 441 return externalTransactionHasCommitted; 442 } 443 444 456 public void commitTransaction() throws DatabaseException, ConcurrencyException { 457 if (!getTransactionMutex().isNested()) { 459 getEventManager().preCommitTransaction(); 460 basicCommitTransaction(); 461 getEventManager().postCommitTransaction(); 462 } 463 464 getTransactionMutex().release(); 466 467 if (!isInTransaction()) { 471 commitExternalTransaction(); 472 } 473 } 474 475 480 public boolean compareObjects(Object firstObject, Object secondObject) { 481 if ((firstObject == null) && (secondObject == null)) { 482 return true; 483 } 484 485 if ((firstObject == null) || (secondObject == null)) { 486 return false; 487 } 488 489 if (!(firstObject.getClass().equals(secondObject.getClass()))) { 490 return false; 491 } 492 493 ObjectBuilder builder = getDescriptor(firstObject.getClass()).getObjectBuilder(); 494 495 return builder.compareObjects(builder.unwrapObject(firstObject, this), builder.unwrapObject(secondObject, this), this); 496 } 497 498 503 public boolean compareObjectsDontMatch(Object firstObject, Object secondObject) { 504 return !this.compareObjects(firstObject, secondObject); 505 } 506 507 511 public boolean containsQuery(String queryName) { 512 return getQueries().containsKey(queryName); 513 } 514 515 524 public Object copyObject(Object original) { 525 return copyObject(original, new ObjectCopyingPolicy()); 526 } 527 528 535 public Object copyObject(Object original, ObjectCopyingPolicy policy) { 536 if (original == null) { 537 return null; 538 } 539 540 ClassDescriptor descriptor = getDescriptor(original); 541 if (descriptor == null) { 542 return original; 543 } 544 545 policy.setSession(this); 546 return descriptor.getObjectBuilder().copyObject(original, policy); 547 } 548 549 556 public Vector copyReadOnlyClasses() { 557 return getDefaultReadOnlyClasses(); 558 } 559 560 571 public void deleteAllObjects(Collection domainObjects) throws DatabaseException, OptimisticLockException { 572 for (Iterator objectsEnum = domainObjects.iterator(); objectsEnum.hasNext();) { 573 deleteObject(objectsEnum.next()); 574 } 575 } 576 577 588 public void deleteAllObjects(Vector domainObjects) throws DatabaseException, OptimisticLockException { 589 for (Enumeration objectsEnum = domainObjects.elements(); objectsEnum.hasMoreElements();) { 590 deleteObject(objectsEnum.nextElement()); 591 } 592 } 593 594 607 public Object deleteObject(Object domainObject) throws DatabaseException, OptimisticLockException { 608 DeleteObjectQuery query = new DeleteObjectQuery(); 609 query.setObject(domainObject); 610 return executeQuery(query); 611 } 612 613 618 public boolean doesObjectExist(Object object) throws DatabaseException { 619 DoesExistQuery query = new DoesExistQuery(); 620 query.setObject(object); 621 query.checkDatabaseForDoesExist(); 622 return ((Boolean )executeQuery(query)).booleanValue(); 623 } 624 625 629 public void dontLogMessages() { 630 setLogLevel(SessionLog.OFF); 631 } 632 633 637 public void endOperationProfile(String operationName) { 638 if (isInProfile()) { 639 getProfiler().endOperationProfile(operationName); 640 } 641 } 642 643 647 public void updateProfile(String operationName, Object value) { 648 if (isInProfile()) { 649 getProfiler().update(operationName, value); 650 } 651 } 652 653 657 public void incrementProfile(String operationName) { 658 if (isInProfile()) { 659 getProfiler().occurred(operationName); 660 } 661 } 662 663 669 public Object executeCall(Call call, AbstractRecord translationRow, DatabaseQuery query) throws DatabaseException { 670 if (query.getAccessor() == null) { 672 query.setAccessor(getAccessor()); 673 } 674 try { 675 return query.getAccessor().executeCall(call, translationRow, this); 676 } finally { 677 if (call.isFinished()) { 678 query.setAccessor(null); 679 } 680 } 681 } 682 683 693 public int executeNonSelectingCall(Call call) throws DatabaseException { 694 DataModifyQuery query = new DataModifyQuery(); 695 query.setCall(call); 696 Integer value = (Integer )executeQuery(query); 697 if (value == null) { 698 return 0; 699 } else { 700 return value.intValue(); 701 } 702 } 703 704 711 public void executeNonSelectingSQL(String sqlString) throws DatabaseException { 712 executeNonSelectingCall(new SQLCall(sqlString)); 713 } 714 715 722 public Object executeQuery(String queryName) throws DatabaseException { 723 DatabaseQuery query = getQuery(queryName); 724 725 if (query == null) { 726 throw QueryException.queryNotDefined(queryName); 727 } 728 729 return executeQuery(query); 730 } 731 732 740 public Object executeQuery(String queryName, Class domainClass) throws DatabaseException { 741 ClassDescriptor descriptor = getDescriptor(domainClass); 742 743 if (descriptor == null) { 744 throw QueryException.descriptorIsMissingForNamedQuery(domainClass, queryName); 745 } 746 747 DatabaseQuery query = (DatabaseQuery)descriptor.getQueryManager().getQuery(queryName); 748 749 if (query == null) { 750 throw QueryException.queryNotDefined(queryName, domainClass); 751 } 752 753 return executeQuery(query); 754 } 755 756 764 public Object executeQuery(String queryName, Class domainClass, Object arg1) throws DatabaseException { 765 Vector argumentValues = new Vector(); 766 argumentValues.addElement(arg1); 767 return executeQuery(queryName, domainClass, argumentValues); 768 } 769 770 778 public Object executeQuery(String queryName, Class domainClass, Object arg1, Object arg2) throws DatabaseException { 779 Vector argumentValues = new Vector(); 780 argumentValues.addElement(arg1); 781 argumentValues.addElement(arg2); 782 return executeQuery(queryName, domainClass, argumentValues); 783 } 784 785 793 public Object executeQuery(String queryName, Class domainClass, Object arg1, Object arg2, Object arg3) throws DatabaseException { 794 Vector argumentValues = new Vector(); 795 argumentValues.addElement(arg1); 796 argumentValues.addElement(arg2); 797 argumentValues.addElement(arg3); 798 return executeQuery(queryName, domainClass, argumentValues); 799 } 800 801 809 public Object executeQuery(String queryName, Class domainClass, Vector argumentValues) throws DatabaseException { 810 ClassDescriptor descriptor = getDescriptor(domainClass); 811 812 if (descriptor == null) { 813 throw QueryException.descriptorIsMissingForNamedQuery(domainClass, queryName); 814 } 815 816 DatabaseQuery query = (DatabaseQuery)descriptor.getQueryManager().getQuery(queryName, argumentValues); 817 818 if (query == null) { 819 throw QueryException.queryNotDefined(queryName, domainClass); 820 } 821 822 return executeQuery(query, argumentValues); 823 } 824 825 832 public Object executeQuery(String queryName, Object arg1) throws DatabaseException { 833 Vector argumentValues = new Vector(); 834 argumentValues.addElement(arg1); 835 return executeQuery(queryName, argumentValues); 836 } 837 838 845 public Object executeQuery(String queryName, Object arg1, Object arg2) throws DatabaseException { 846 Vector argumentValues = new Vector(); 847 argumentValues.addElement(arg1); 848 argumentValues.addElement(arg2); 849 return executeQuery(queryName, argumentValues); 850 } 851 852 859 public Object executeQuery(String queryName, Object arg1, Object arg2, Object arg3) throws DatabaseException { 860 Vector argumentValues = new Vector(); 861 argumentValues.addElement(arg1); 862 argumentValues.addElement(arg2); 863 argumentValues.addElement(arg3); 864 return executeQuery(queryName, argumentValues); 865 } 866 867 874 public Object executeQuery(String queryName, Vector argumentValues) throws DatabaseException { 875 DatabaseQuery query = getQuery(queryName, argumentValues); 876 877 if (query == null) { 878 throw QueryException.queryNotDefined(queryName); 879 } 880 881 return executeQuery(query, argumentValues); 882 } 883 884 893 public Object executeQuery(DatabaseQuery query) throws DatabaseException { 894 return executeQuery(query, new DatabaseRecord(1)); 895 } 896 897 902 public Object executeQuery(DatabaseQuery query, Vector argumentValues) throws DatabaseException { 903 if (query == null) { 904 throw QueryException.queryNotDefined(); 905 } 906 907 AbstractRecord row = query.rowFromArguments(argumentValues); 908 909 return executeQuery(query, row); 910 } 911 912 917 public Object executeQuery(DatabaseQuery query, AbstractRecord row) throws DatabaseException { 918 if (hasBroker()) { 919 if (!((query.isDataModifyQuery() || query.isDataReadQuery()) && (query.getSessionName() == null))) { 920 return getBroker().executeQuery(query, row); 921 } 922 } 923 924 if (query == null) { 925 throw QueryException.queryNotDefined(); 926 } 927 928 log(SessionLog.FINEST, SessionLog.QUERY, "execute_query", query); 930 931 try { 932 getEventManager().preExecuteQuery(query); 933 Object result; 934 if (isInProfile()) { 935 result = getProfiler().profileExecutionOfQuery(query, row, this); 936 } else { 937 result = internalExecuteQuery(query, row); 938 } 939 getEventManager().postExecuteQuery(query, result); 940 return result; 941 } catch (RuntimeException exception) { 942 if (exception instanceof QueryException) { 943 QueryException queryException = (QueryException)exception; 944 if (queryException.getQuery() == null) { 945 queryException.setQuery(query); 946 } 947 if (queryException.getQueryArgumentsRecord() == null) { 948 queryException.setQueryArguments(row); 949 } 950 if (queryException.getSession() == null) { 951 queryException.setSession(this); 952 } 953 } else if (exception instanceof DatabaseException) { 954 DatabaseException databaseException = (DatabaseException)exception; 955 if (databaseException.getQuery() == null) { 956 databaseException.setQuery(query); 957 } 958 if (databaseException.getQueryArgumentsRecord() == null) { 959 databaseException.setQueryArguments(row); 960 } 961 if (databaseException.getSession() == null) { 962 databaseException.setSession(this); 963 } 964 } 965 return handleException(exception); 966 } 967 } 968 969 980 public Vector executeSelectingCall(Call call) throws DatabaseException { 981 DataReadQuery query = new DataReadQuery(); 982 query.setCall(call); 983 return (Vector)executeQuery(query); 984 } 985 986 996 public Vector executeSQL(String sqlString) throws DatabaseException { 997 return executeSelectingCall(new SQLCall(sqlString)); 998 } 999 1000 1005 public synchronized Accessor getAccessor() { 1006 if ((accessor == null) && (project != null) && (project.getDatasourceLogin() != null)) { 1007 accessor = project.getDatasourceLogin().buildAccessor(); 1009 } 1010 return accessor; 1011 } 1012 1013 1020 public Accessor getAccessor(Class domainClass) { 1021 return getAccessor(); 1022 } 1023 1024 1031 public Accessor getAccessor(String sessionName) { 1032 return getAccessor(); 1033 } 1034 1035 1040 public oracle.toplink.essentials.sessions.Session getActiveSession() { 1041 oracle.toplink.essentials.sessions.Session activeSession = getActiveUnitOfWork(); 1042 if (activeSession == null) { 1043 activeSession = this; 1044 } 1045 1046 return activeSession; 1047 } 1048 1049 1054 public oracle.toplink.essentials.sessions.UnitOfWork getActiveUnitOfWork() { 1055 if (hasExternalTransactionController()) { 1056 return getExternalTransactionController().getActiveUnitOfWork(); 1057 } 1058 1059 1064 if (isClientSession()) { 1065 return ((oracle.toplink.essentials.threetier.ClientSession)this).getParent().getActiveUnitOfWork(); 1066 } 1067 1068 return null; 1069 } 1070 1071 1075 public Map getAliasDescriptors() { 1076 return project.getAliasDescriptors(); 1077 } 1078 1079 1083 public AbstractSession getBroker() { 1084 return broker; 1085 } 1086 1087 1102 public AbstractSession getRootSession(DatabaseQuery query) { 1103 return getParentIdentityMapSession(query, false, true); 1104 } 1105 1106 1112 public AbstractSession getParentIdentityMapSession(DatabaseQuery query) { 1113 return getParentIdentityMapSession(query, false, false); 1114 } 1115 1116 1132 public AbstractSession getParentIdentityMapSession(DatabaseQuery query, boolean canReturnSelf, boolean terminalOnly) { 1133 return this; 1134 } 1135 1136 1151 public AbstractSession getExecutionSession(DatabaseQuery query) { 1152 return this; 1153 } 1154 1155 1160 public CommitManager getCommitManager() { 1161 if (hasBroker()) { 1162 return getBroker().getCommitManager(); 1163 } 1164 1165 if (commitManager == null) { 1167 commitManager = new CommitManager(this); 1168 } 1169 return commitManager; 1170 } 1171 1172 1178 public Vector getDefaultReadOnlyClasses() { 1179 if (hasBroker()) { 1181 return getBroker().getDefaultReadOnlyClasses(); 1182 } 1183 return getProject().getDefaultReadOnlyClasses(); 1184 } 1185 1186 1193 public ClassDescriptor getClassDescriptor(Class theClass) { 1194 ClassDescriptor desc = getDescriptor(theClass); 1195 if (desc instanceof ClassDescriptor) { 1196 return (ClassDescriptor)desc; 1197 } else { 1198 throw ValidationException.cannotCastToClass(desc, desc.getClass(), ClassDescriptor.class); 1199 } 1200 } 1201 1202 1206 public ClassDescriptor getClassDescriptor(Object domainObject) { 1207 ClassDescriptor desc = getDescriptor(domainObject); 1208 if (desc instanceof ClassDescriptor) { 1209 return (ClassDescriptor)desc; 1210 } else { 1211 throw ValidationException.cannotCastToClass(desc, desc.getClass(), ClassDescriptor.class); 1212 } 1213 } 1214 1215 1220 public ClassDescriptor getClassDescriptorForAlias(String alias) { 1221 return project.getClassDescriptorForAlias(alias); 1222 } 1223 1224 1231 public ClassDescriptor getDescriptor(Class theClass) { 1232 if (theClass == null) { 1233 return null; 1234 } 1235 1236 ClassDescriptor lastDescriptor = this.lastDescriptorAccessed; 1238 if ((lastDescriptor != null) && (lastDescriptor.getJavaClass().equals(theClass))) { 1239 return lastDescriptor; 1240 } 1241 1242 ClassDescriptor descriptor = (ClassDescriptor)getDescriptors().get(theClass); 1243 1244 if ((descriptor == null) && hasBroker()) { 1245 descriptor = getBroker().getDescriptor(theClass); 1247 } 1248 if (descriptor == null) { 1249 getEventManager().missingDescriptor(theClass); 1251 descriptor = (ClassDescriptor)getDescriptors().get(theClass); 1252 } 1253 1254 if (descriptor == null) { 1255 if (!theClass.isInterface()) { 1260 Class [] interfaces = theClass.getInterfaces(); 1261 for (int index = 0; index < interfaces.length; ++index) { 1262 Class interfaceClass = (Class )interfaces[index]; 1263 descriptor = getDescriptor(interfaceClass); 1264 if (descriptor != null) { 1265 getDescriptors().put(interfaceClass, descriptor); 1266 break; 1267 } 1268 } 1269 if (descriptor == null) { 1270 descriptor = getDescriptor(theClass.getSuperclass()); 1271 } 1272 } 1273 } 1274 1275 this.lastDescriptorAccessed = descriptor; 1277 1278 return descriptor; 1279 } 1280 1281 1285 public ClassDescriptor getDescriptor(Object domainObject) { 1286 return getDescriptor(domainObject.getClass()); 1287 } 1288 1289 1293 public ClassDescriptor getDescriptorForAlias(String alias) { 1294 return project.getDescriptorForAlias(alias); 1295 } 1296 1297 1301 public Map getDescriptors() { 1302 return getProject().getDescriptors(); 1303 } 1304 1305 1310 public List getEjbqlPlaceHolderQueries() { 1311 if (ejbqlPlaceHolderQueries == null) { 1313 ejbqlPlaceHolderQueries = new Vector(); 1314 } 1315 return ejbqlPlaceHolderQueries; 1316 } 1317 1318 1323 public synchronized SessionEventManager getEventManager() { 1324 if (eventManager == null) { 1325 eventManager = new SessionEventManager(this); 1327 } 1328 return eventManager; 1329 } 1330 1331 1337 public String getExceptionHandlerClass() { 1338 String className = null; 1339 try { 1340 className = getExceptionHandler().getClass().getName(); 1341 } catch (Exception exception) { 1342 return null; 1343 } 1344 return className; 1345 } 1346 1347 1351 public ExceptionHandler getExceptionHandler() { 1352 return exceptionHandler; 1353 } 1354 1355 1363 public ExternalTransactionController getExternalTransactionController() { 1364 return externalTransactionController; 1365 } 1366 1367 1373 public oracle.toplink.essentials.sessions.IdentityMapAccessor getIdentityMapAccessor() { 1374 return identityMapAccessor; 1375 } 1376 1377 1381 public oracle.toplink.essentials.internal.sessions.IdentityMapAccessor getIdentityMapAccessorInstance() { 1382 return identityMapAccessor; 1383 } 1384 1385 1389 public IntegrityChecker getIntegrityChecker() { 1390 if (integrityChecker == null) { 1392 integrityChecker = new IntegrityChecker(); 1393 } 1394 1395 return integrityChecker; 1396 } 1397 1398 1405 public Writer getLog() { 1406 return getSessionLog().getWriter(); 1407 } 1408 1409 1418 public String getLogSessionString() { 1419 if (logSessionString == null) { 1420 StringWriter writer = new StringWriter(); 1421 writer.write(getSessionTypeString()); 1422 writer.write("("); 1423 writer.write(String.valueOf(System.identityHashCode(this))); 1424 writer.write(")"); 1425 logSessionString = writer.toString(); 1426 } 1427 return logSessionString; 1428 } 1429 1430 1441 public String getSessionTypeString() { 1442 return Helper.getShortClassName(getClass()); 1443 } 1444 1445 1452 public DatabaseLogin getLogin() { 1453 try { 1454 return (DatabaseLogin)getDatasourceLogin(); 1455 } catch (ClassCastException wrongType) { 1456 throw ValidationException.notSupportedForDatasource(); 1457 } 1458 } 1459 1460 1465 public Login getDatasourceLogin() { 1466 return getProject().getDatasourceLogin(); 1467 } 1468 1469 1474 public String getName() { 1475 return name; 1476 } 1477 1478 1482 public Number getNextSequenceNumberValue(Class domainClass) { 1483 return (Number )getSequencing().getNextValue(domainClass); 1484 } 1485 1486 1490 public int getNumberOfActiveUnitsOfWork() { 1491 return numberOfActiveUnitsOfWork; 1492 } 1493 1494 1501 public DatabasePlatform getPlatform() { 1502 return getDatasourceLogin().getPlatform(); 1503 } 1504 1505 1510 public Platform getDatasourcePlatform() { 1511 if (platform == null) { 1513 platform = getDatasourceLogin().getDatasourcePlatform(); 1514 } 1515 return platform; 1516 } 1517 1518 1524 public ServerPlatform getServerPlatform(){ 1525 return null; 1526 } 1527 1528 1534 public Platform getPlatform(Class domainClass) { 1535 if (platform == null) { 1537 platform = getDatasourcePlatform(); 1538 } 1539 return platform; 1540 } 1541 1542 1548 public SessionProfiler getProfiler() { 1549 return profiler; 1550 } 1551 1552 1556 public oracle.toplink.essentials.sessions.Project getProject() { 1557 return project; 1558 } 1559 1560 1564 public Map getProperties() { 1565 if (properties == null) { 1566 properties = new HashMap(5); 1567 } 1568 return properties; 1569 } 1570 1571 1575 public boolean hasProperties() { 1576 return ((properties != null) && !properties.isEmpty()); 1577 } 1578 1579 1583 public Object getProperty(String name) { 1584 return getProperties().get(name); 1585 } 1586 1587 1592 public Map getQueries() { 1593 if (queries == null) { 1595 queries = new HashMap(5); 1596 } 1597 return queries; 1598 } 1599 1600 1607 public Vector getAllQueries() { 1608 Vector allQueries = new Vector(); 1609 for (Iterator vectors = getQueries().values().iterator(); vectors.hasNext();) { 1610 allQueries.addAll((Vector)vectors.next()); 1611 } 1612 return allQueries; 1613 } 1614 1615 1620 public DatabaseQuery getQuery(String name) { 1621 return getQuery(name, null); 1622 } 1623 1624 1633 public DatabaseQuery getQuery(String name, Vector arguments) { 1634 Vector queries = (Vector)getQueries().get(name); 1635 if ((queries == null) || queries.isEmpty()) { 1636 return null; 1637 } 1638 1639 if (queries.size() == 1) { 1641 return (DatabaseQuery)queries.firstElement(); 1642 } 1643 1644 int argumentTypesSize = 0; 1652 if (arguments != null) { 1653 argumentTypesSize = arguments.size(); 1654 } 1655 Vector argumentTypes = new Vector(argumentTypesSize); 1656 for (int i = 0; i < argumentTypesSize; i++) { 1657 argumentTypes.addElement(arguments.elementAt(i).getClass()); 1658 } 1659 for (Enumeration queriesEnum = queries.elements(); queriesEnum.hasMoreElements();) { 1660 DatabaseQuery query = (DatabaseQuery)queriesEnum.nextElement(); 1661 if (Helper.areTypesAssignable(argumentTypes, query.getArgumentTypes())) { 1662 return query; 1663 } 1664 } 1665 return null; 1666 } 1667 1668 1672 public Sequencing getSequencing() { 1673 return null; 1674 } 1675 1676 1681 public AbstractSession getSessionForClass(Class domainClass) { 1682 if (hasBroker()) { 1683 return getBroker().getSessionForClass(domainClass); 1684 } 1685 return this; 1686 } 1687 1688 1693 public SessionLog getSessionLog() { 1694 if (sessionLog == null) { 1695 setSessionLog(new DefaultSessionLog()); 1696 } 1697 return sessionLog; 1698 } 1699 1700 1704 public synchronized ConcurrencyManager getTransactionMutex() { 1705 if (transactionMutex == null) { 1707 transactionMutex = new ConcurrencyManager(); 1708 } 1709 return transactionMutex; 1710 } 1711 1712 1716 public Object handleException(RuntimeException exception) throws RuntimeException { 1717 if ((exception instanceof TopLinkException)) { 1718 TopLinkException topLinkException = (TopLinkException)exception; 1719 if (topLinkException.getSession() == null) { 1720 topLinkException.setSession(this); 1721 } 1722 if (!topLinkException.hasBeenLogged()) { 1724 logThrowable(SessionLog.WARNING, null, exception); 1725 topLinkException.setHasBeenLogged(true); 1726 } 1727 } else { 1728 logThrowable(SessionLog.WARNING, null, exception); 1729 } 1730 if (hasExceptionHandler()) { 1731 return getExceptionHandler().handleException(exception); 1732 } else { 1733 throw exception; 1734 } 1735 } 1736 1737 1741 public boolean hasBroker() { 1742 return broker != null; 1743 } 1744 1745 1749 public boolean hasDescriptor(Class theClass) { 1750 if (theClass == null) { 1751 return false; 1752 } 1753 1754 return getDescriptors().get(theClass) != null; 1755 } 1756 1757 1761 public boolean hasExceptionHandler() { 1762 if (exceptionHandler == null) { 1763 return false; 1764 } 1765 return true; 1766 } 1767 1768 1775 public boolean hasExternalTransactionController() { 1776 return externalTransactionController != null; 1777 } 1778 1779 1784 public void initializeIdentityMapAccessor() { 1785 this.identityMapAccessor = new oracle.toplink.essentials.internal.sessions.IdentityMapAccessor(this, new IdentityMapManager(this)); 1786 } 1787 1788 1801 public Object insertObject(Object domainObject) throws DatabaseException { 1802 InsertObjectQuery query = new InsertObjectQuery(); 1803 query.setObject(domainObject); 1804 return executeQuery(query); 1805 } 1806 1807 1814 public Object internalExecuteQuery(DatabaseQuery query, AbstractRecord databaseRow) throws DatabaseException { 1815 return query.execute(this, databaseRow); 1816 } 1817 1818 1822 public boolean isBroker() { 1823 return false; 1824 } 1825 1826 1830 public boolean isInBroker() { 1831 return false; 1832 } 1833 1834 1838 public boolean isClassReadOnly(Class theClass) { 1839 ClassDescriptor descriptor = getDescriptor(theClass); 1840 return isClassReadOnly(theClass, descriptor); 1841 } 1842 1843 1848 public boolean isClassReadOnly(Class theClass, ClassDescriptor descriptor) { 1849 if ((descriptor != null) && descriptor.shouldBeReadOnly()) { 1850 return true; 1851 } 1852 if (theClass != null) { 1853 return getDefaultReadOnlyClasses().contains(theClass); 1854 } 1855 return false; 1856 } 1857 1858 1862 public boolean isClientSession() { 1863 return false; 1864 } 1865 1866 1870 public boolean isConnected() { 1871 if (getAccessor() == null) { 1872 return false; 1873 } 1874 1875 return getAccessor().isConnected(); 1876 } 1877 1878 1882 public boolean isDatabaseSession() { 1883 return false; 1884 } 1885 1886 1890 public boolean isDistributedSession() { 1891 return false; 1892 } 1893 1894 1898 public boolean isInProfile() { 1899 return isInProfile; 1900 } 1901 1902 1906 public void setIsInProfile(boolean inProfile) { 1907 this.isInProfile = inProfile; 1908 } 1909 1910 1915 public boolean isInTransaction() { 1916 return getTransactionMutex().isAcquired(); 1917 } 1918 1919 1923 public boolean isRemoteSession() { 1924 return false; 1925 } 1926 1927 1931 public boolean isRemoteUnitOfWork() { 1932 return false; 1933 } 1934 1935 1939 public boolean isServerSession() { 1940 return false; 1941 } 1942 1943 1947 public boolean isSessionBroker() { 1948 return false; 1949 } 1950 1951 1955 public boolean isUnitOfWork() { 1956 return false; 1957 } 1958 1959 1963 public Vector keyFromObject(Object domainObject) throws ValidationException { 1964 ClassDescriptor descriptor = getDescriptor(domainObject); 1965 return keyFromObject(domainObject, descriptor); 1966 } 1967 1968 1972 public Vector keyFromObject(Object domainObject, ClassDescriptor descriptor) throws ValidationException { 1973 if (descriptor == null) { 1974 throw ValidationException.missingDescriptor(domainObject.getClass().getName()); 1975 } 1976 Object implemention = descriptor.getObjectBuilder().unwrapObject(domainObject, this); 1977 if (implemention == null) { 1978 return null; 1979 } 1980 return descriptor.getObjectBuilder().extractPrimaryKeyFromObject(implemention, this); 1981 } 1982 1983 1987 public void log(SessionLogEntry entry) { 1988 if (shouldLog(entry.getLevel(), entry.getNameSpace())) { 1989 if (entry.getSession() == null) { entry.setSession(this); 1991 } 1992 getSessionLog().log(entry); 1993 } 1994 } 1995 1996 1999 public void logMessage(String message) { 2000 log(SessionLog.FINER, message, (Object [])null, null, false); 2001 } 2002 2003 2011 public DatabaseQuery prepareDatabaseQuery(DatabaseQuery query) { 2012 if (!isUnitOfWork() && query.isObjectLevelReadQuery()) { 2013 return ((ObjectLevelReadQuery)query).prepareOutsideUnitOfWork(this); 2014 } else { 2015 return query; 2016 } 2017 } 2018 2019 2025 public void processEJBQLQueries() { 2026 List queries = getEjbqlPlaceHolderQueries(); 2027 processEJBQLQueries(queries); 2028 queries.clear(); 2029 } 2030 2031 2037 public void processEJBQLQueries(List queries) { 2038 for (Iterator iterator = queries.iterator(); iterator.hasNext();) { 2039 EJBQLPlaceHolderQuery existingQuery = (EJBQLPlaceHolderQuery)iterator.next(); 2040 this.addQuery(existingQuery.processEjbQLQuery(this)); 2041 } 2042 } 2043 2044 2053 public Vector readAllObjects(Class domainClass) throws DatabaseException { 2054 ReadAllQuery query = new ReadAllQuery(); 2055 query.setReferenceClass(domainClass); 2056 return (Vector)executeQuery(query); 2057 } 2058 2059 2067 public Vector readAllObjects(Class domainClass, String sqlString) throws DatabaseException { 2068 ReadAllQuery query = new ReadAllQuery(); 2069 query.setReferenceClass(domainClass); 2070 query.setSQLString(sqlString); 2071 return (Vector)executeQuery(query); 2072 } 2073 2074 2082 public Vector readAllObjects(Class referenceClass, Call aCall) throws DatabaseException { 2083 ReadAllQuery raq = new ReadAllQuery(); 2084 raq.setReferenceClass(referenceClass); 2085 raq.setCall(aCall); 2086 return (Vector)executeQuery(raq); 2087 } 2088 2089 2096 public Vector readAllObjects(Class domainClass, Expression expression) throws DatabaseException { 2097 ReadAllQuery query = new ReadAllQuery(); 2098 query.setReferenceClass(domainClass); 2099 query.setSelectionCriteria(expression); 2100 return (Vector)executeQuery(query); 2101 } 2102 2103 2112 public Object readObject(Class domainClass) throws DatabaseException { 2113 ReadObjectQuery query = new ReadObjectQuery(); 2114 query.setReferenceClass(domainClass); 2115 return executeQuery(query); 2116 } 2117 2118 2126 public Object readObject(Class domainClass, String sqlString) throws DatabaseException { 2127 ReadObjectQuery query = new ReadObjectQuery(); 2128 query.setReferenceClass(domainClass); 2129 query.setSQLString(sqlString); 2130 return executeQuery(query); 2131 } 2132 2133 2142 public Object readObject(Class domainClass, Call aCall) throws DatabaseException { 2143 ReadObjectQuery query = new ReadObjectQuery(); 2144 query.setReferenceClass(domainClass); 2145 query.setCall(aCall); 2146 return executeQuery(query); 2147 } 2148 2149 2156 public Object readObject(Class domainClass, Expression expression) throws DatabaseException { 2157 ReadObjectQuery query = new ReadObjectQuery(); 2158 query.setReferenceClass(domainClass); 2159 query.setSelectionCriteria(expression); 2160 return executeQuery(query); 2161 } 2162 2163 2169 public Object readObject(Object object) throws DatabaseException { 2170 ReadObjectQuery query = new ReadObjectQuery(); 2171 query.setSelectionObject(object); 2172 return executeQuery(query); 2173 } 2174 2175 2183 public Object refreshAndLockObject(Object object) throws DatabaseException { 2184 ReadObjectQuery query = new ReadObjectQuery(); 2185 query.setSelectionObject(object); 2186 query.refreshIdentityMapResult(); 2187 query.cascadePrivateParts(); 2188 query.setLockMode(ObjectBuildingQuery.LOCK); 2189 return executeQuery(query); 2190 } 2191 2192 2198 public Object refreshAndLockObject(Object object, short lockMode) throws DatabaseException { 2199 ReadObjectQuery query = new ReadObjectQuery(); 2200 query.setSelectionObject(object); 2201 query.refreshIdentityMapResult(); 2202 query.cascadePrivateParts(); 2203 query.setLockMode(lockMode); 2204 return executeQuery(query); 2205 } 2206 2207 2214 public Object refreshObject(Object object) throws DatabaseException { 2215 return refreshAndLockObject(object, ObjectBuildingQuery.NO_LOCK); 2216 } 2217 2218 2223 public void release() { 2224 } 2225 2226 2230 public void releaseUnitOfWork(UnitOfWorkImpl unitOfWork) { 2231 setNumberOfActiveUnitsOfWork(getNumberOfActiveUnitsOfWork() - 1); 2233 } 2234 2235 2236 2240 public void removeProperty(String property) { 2241 getProperties().remove(property); 2242 } 2243 2244 2250 public void removeQuery(String queryName) { 2251 getQueries().remove(queryName); 2252 } 2253 2254 2258 public void removeQuery(String queryName, Vector argumentTypes) { 2259 Vector queries = (Vector)getQueries().get(queryName); 2260 if (queries == null) { 2261 return; 2262 } else { 2263 DatabaseQuery query = null; 2264 for (Enumeration enumtr = queries.elements(); enumtr.hasMoreElements();) { 2265 query = (DatabaseQuery)enumtr.nextElement(); 2266 if (Helper.areTypesAssignable(argumentTypes, query.getArgumentTypes())) { 2267 break; 2268 } 2269 } 2270 if (query != null) { 2271 queries.remove(query); 2272 } 2273 } 2274 } 2275 2276 2284 protected boolean rollbackExternalTransaction() { 2285 boolean externalTransactionHasRolledBack = false; 2286 if (hasExternalTransactionController() && wasJTSTransactionInternallyStarted()) { 2287 try { 2288 getExternalTransactionController().rollbackTransaction(this); 2289 } catch (RuntimeException exception) { 2290 handleException(exception); 2291 } 2292 if (!wasJTSTransactionInternallyStarted()) { 2293 externalTransactionHasRolledBack = true; 2294 log(SessionLog.FINER, SessionLog.TRANSACTION, "external_transaction_has_rolled_back_internally"); 2295 } 2296 } 2297 return externalTransactionHasRolledBack; 2298 } 2299 2300 2311 public void rollbackTransaction() throws DatabaseException, ConcurrencyException { 2312 try { 2314 if (!getTransactionMutex().isNested()) { 2315 getEventManager().preRollbackTransaction(); 2316 basicRollbackTransaction(); 2317 getEventManager().postRollbackTransaction(); 2318 } 2319 } finally { 2320 getTransactionMutex().release(); 2321 2322 if (!isInTransaction()) { 2326 rollbackExternalTransaction(); 2327 } 2328 } 2329 } 2330 2331 2335 public void setAccessor(Accessor accessor) { 2336 this.accessor = accessor; 2337 } 2338 2339 2343 public void setBroker(AbstractSession broker) { 2344 this.broker = broker; 2345 } 2346 2347 2351 public void setCommitManager(CommitManager commitManager) { 2352 this.commitManager = commitManager; 2353 } 2354 2355 2360 public void setEventManager(SessionEventManager eventManager) { 2361 if (eventManager != null) { 2362 this.eventManager = eventManager; 2363 } else { 2364 this.eventManager = new SessionEventManager(); 2365 } 2366 this.eventManager.setSession(this); 2367 } 2368 2369 2374 public void setExceptionHandler(ExceptionHandler exceptionHandler) { 2375 this.exceptionHandler = exceptionHandler; 2376 } 2377 2378 2381 public void setExternalTransactionController(ExternalTransactionController externalTransactionController) { 2382 this.externalTransactionController = externalTransactionController; 2383 if (externalTransactionController == null) { 2384 return; 2385 } 2386 externalTransactionController.setSession(this); 2387 } 2388 2389 2393 public void setIntegrityChecker(IntegrityChecker integrityChecker) { 2394 this.integrityChecker = integrityChecker; 2395 } 2396 2397 2404 public void setLog(Writer log) { 2405 getSessionLog().setWriter(log); 2406 } 2407 2408 2412 public void setLogin(DatabaseLogin login) { 2413 setDatasourceLogin(login); 2414 } 2415 2416 2420 public void setLogin(Login login) { 2421 setDatasourceLogin(login); 2422 } 2423 2424 2428 public void setDatasourceLogin(Login login) { 2429 getProject().setDatasourceLogin(login); 2430 } 2431 2432 2437 public void setName(String name) { 2438 this.name = name; 2439 } 2440 2441 protected void setNumberOfActiveUnitsOfWork(int numberOfActiveUnitsOfWork) { 2442 this.numberOfActiveUnitsOfWork = numberOfActiveUnitsOfWork; 2443 } 2444 2445 2450 public void setProfiler(SessionProfiler profiler) { 2451 this.profiler = profiler; 2452 if (profiler != null) { 2453 profiler.setSession(this); 2454 setIsInProfile(getProfiler().getProfileWeight() != SessionProfiler.NONE); 2455 getIdentityMapAccessorInstance().getIdentityMapManager().clearCacheAccessPreCheck(); 2457 } else { 2458 setIsInProfile(false); 2459 } 2460 } 2461 2462 2466 public void setProject(oracle.toplink.essentials.sessions.Project project) { 2467 this.project = project; 2468 } 2469 2470 2474 public void setProperties(Hashtable properties) { 2475 this.properties = properties; 2476 } 2477 2478 2482 public void setProperty(String propertyName, Object propertyValue) { 2483 getProperties().put(propertyName, propertyValue); 2484 } 2485 2486 protected void setQueries(Hashtable queries) { 2487 this.queries = queries; 2488 } 2489 2490 2500 public void setSessionLog(SessionLog sessionLog) { 2501 this.sessionLog = (SessionLog)((AbstractSessionLog)sessionLog).clone(); 2502 if (this.sessionLog != null) { 2503 this.sessionLog.setSession(this); 2504 } 2505 } 2506 2507 protected void setTransactionMutex(ConcurrencyManager transactionMutex) { 2508 this.transactionMutex = transactionMutex; 2509 } 2510 2511 2516 public void setWasJTSTransactionInternallyStarted(boolean wasJTSTransactionInternallyStarted) { 2517 this.wasJTSTransactionInternallyStarted = wasJTSTransactionInternallyStarted; 2518 } 2519 2520 2524 public boolean shouldLogMessages() { 2525 if (getLogLevel(null) == SessionLog.OFF) { 2526 return false; 2527 } else { 2528 return true; 2529 } 2530 } 2531 2532 2536 public void startOperationProfile(String operationName) { 2537 if (isInProfile()) { 2538 getProfiler().startOperationProfile(operationName); 2539 } 2540 } 2541 2542 2545 public String toString() { 2546 StringWriter writer = new StringWriter(); 2547 writer.write(getSessionTypeString() + "(" + Helper.cr() + "\t" + getAccessor() + Helper.cr() + "\t" + getDatasourcePlatform() + ")"); 2548 return writer.toString(); 2549 } 2550 2551 2556 public Object unwrapObject(Object proxy) { 2557 return getDescriptor(proxy).getObjectBuilder().unwrapObject(proxy, this); 2558 } 2559 2560 2575 public Object updateObject(Object domainObject) throws DatabaseException, OptimisticLockException { 2576 UpdateObjectQuery query = new UpdateObjectQuery(); 2577 query.setObject(domainObject); 2578 return executeQuery(query); 2579 } 2580 2581 2586 public void validateQuery(DatabaseQuery query) { 2587 } 2589 2590 2594 public boolean verifyDelete(Object domainObject) { 2595 ObjectBuilder builder = getDescriptor(domainObject).getObjectBuilder(); 2596 Object implementation = builder.unwrapObject(domainObject, this); 2597 2598 return builder.verifyDelete(implementation, this); 2599 } 2600 2601 2606 public boolean wasJTSTransactionInternallyStarted() { 2607 return wasJTSTransactionInternallyStarted; 2608 } 2609 2610 2615 public Object wrapObject(Object implementation) { 2616 return getDescriptor(implementation).getObjectBuilder().wrapObject(implementation, this); 2617 } 2618 2619 2626 protected void writeAllObjects(IdentityHashtable domainObjects) throws DatabaseException, OptimisticLockException { 2627 getCommitManager().commitAllObjects(domainObjects); 2628 } 2629 2630 2637 protected void writeAllObjectsWithChangeSet(UnitOfWorkChangeSet uowChangeSet) throws DatabaseException, OptimisticLockException { 2638 getCommitManager().commitAllObjectsWithChangeSet(uowChangeSet); 2639 } 2640 2641 2657 public Object writeObject(Object domainObject) throws DatabaseException, OptimisticLockException { 2658 WriteObjectQuery query = new WriteObjectQuery(); 2659 query.setObject(domainObject); 2660 return executeQuery(query); 2661 } 2662 2663 2669 public void writesCompleted() { 2670 getAccessor().writesCompleted(this); 2671 } 2672 2673 2684 public int getLogLevel(String category) { 2685 return getSessionLog().getLevel(category); 2686 } 2687 2688 2696 public int getLogLevel() { 2697 return getSessionLog().getLevel(); 2698 } 2699 2700 2709 public void setLogLevel(int level) { 2710 getSessionLog().setLevel(level); 2711 } 2712 2713 2725 public boolean shouldLog(int Level, String category) { 2726 return getSessionLog().shouldLog(Level, category); 2727 } 2728 2729 2742 public void log(int level, String category, String message) { 2743 if (!shouldLog(level, category)) { 2744 return; 2745 } 2746 log(level, category, message, (Object [])null); 2747 } 2748 2749 2764 public void log(int level, String category, String message, Object param) { 2765 if (!shouldLog(level, category)) { 2766 return; 2767 } 2768 log(level, category, message, new Object [] { param }); 2769 } 2770 2771 2788 public void log(int level, String category, String message, Object param1, Object param2) { 2789 if (!shouldLog(level, category)) { 2790 return; 2791 } 2792 log(level, category, message, new Object [] { param1, param2 }); 2793 } 2794 2795 2814 public void log(int level, String category, String message, Object param1, Object param2, Object param3) { 2815 if (!shouldLog(level, category)) { 2816 return; 2817 } 2818 log(level, category, message, new Object [] { param1, param2, param3 }); 2819 } 2820 2821 2836 public void log(int level, String category, String message, Object [] params) { 2837 log(level, category, message, params, null); 2838 } 2839 2840 2857 public void log(int level, String category, String message, Object [] params, Accessor accessor) { 2858 log(level, category, message, params, accessor, true); 2859 } 2860 2861 2880 public void log(int level, String category, String message, Object [] params, Accessor accessor, boolean shouldTranslate) { 2881 if (shouldLog(level, category)) { 2882 startOperationProfile(SessionProfiler.Logging); 2883 log(new SessionLogEntry(level, category, this, message, params, accessor, shouldTranslate)); 2884 endOperationProfile(SessionProfiler.Logging); 2885 } 2886 } 2887 2888 2903 public void log(int level, String message, Object [] params, Accessor accessor) { 2904 log(level, message, params, accessor, true); 2905 } 2906 2907 2924 public void log(int level, String message, Object [] params, Accessor accessor, boolean shouldTranslate) { 2925 if (shouldLog(level, null)) { 2926 startOperationProfile(SessionProfiler.Logging); 2927 log(new SessionLogEntry(level, this, message, params, accessor, shouldTranslate)); 2928 endOperationProfile(SessionProfiler.Logging); 2929 } 2930 } 2931 2932 2945 public void logThrowable(int level, String category, Throwable throwable) { 2946 if (shouldLog(level, category)) { 2948 startOperationProfile(SessionProfiler.Logging); 2949 log(new SessionLogEntry(this, level, category, throwable)); 2950 endOperationProfile(SessionProfiler.Logging); 2951 } 2952 } 2953 2954 2964 public void severe(String message, String category) { 2965 log(SessionLog.SEVERE, category, message); 2966 } 2967 2968 2978 public void warning(String message, String category) { 2979 log(SessionLog.WARNING, category, message); 2980 } 2981 2982 2992 public void info(String message, String category) { 2993 log(SessionLog.INFO, category, message); 2994 } 2995 2996 3006 public void config(String message, String category) { 3007 log(SessionLog.CONFIG, category, message); 3008 } 3009 3010 3020 public void fine(String message, String category) { 3021 log(SessionLog.FINE, category, message); 3022 } 3023 3024 3034 public void finer(String message, String category) { 3035 log(SessionLog.FINER, category, message); 3036 } 3037 3038 3048 public void finest(String message, String category) { 3049 log(SessionLog.FINEST, category, message); 3050 } 3051 3052 3056 public Object handleSevere(RuntimeException exception) throws RuntimeException { 3057 logThrowable(SessionLog.SEVERE, null, exception); 3058 if (hasExceptionHandler()) { 3059 return getExceptionHandler().handleException(exception); 3060 } else { 3061 throw exception; 3062 } 3063 } 3064} 3065 | Popular Tags |