From 622a90c7d5dd27b2cb477df635611314e100688d Mon Sep 17 00:00:00 2001
From: rbygrave
* Keeps the Cache and Cluster in sync when transactions are committed.
- *
* If the Isolation level is higher (say SERIALIZABLE) then Connections used * just for queries do need to be committed or rollback after the query. - *
*/ OnQueryOnly initOnQueryOnly(OnQueryOnly dbPlatformOnQueryOnly) { - // first check for a system property 'override' String systemPropertyValue = System.getProperty("ebean.transaction.onqueryonly"); if (systemPropertyValue != null) { return OnQueryOnly.valueOf(systemPropertyValue.trim().toUpperCase()); } - // default to rollback if not defined on the platform return dbPlatformOnQueryOnly == null ? OnQueryOnly.COMMIT : dbPlatformOnQueryOnly; } @@ -359,9 +352,7 @@ public class TransactionManager implements SpiTransactionManager { * Wrap an externally supplied Connection with a known transaction id. */ private SpiTransaction wrapExternalConnection(String id, Connection c) { - ExternalJdbcTransaction t = new ExternalJdbcTransaction(id, true, c, this); - // set the default batch mode t.setBatchMode(persistBatch); t.setBatchOnCascade(persistBatchOnCascade); @@ -409,7 +400,6 @@ public class TransactionManager implements SpiTransactionManager { */ @Override public void notifyOfRollback(SpiTransaction transaction, Throwable cause) { - try { if (txnLogger.isDebug()) { String msg = transaction.getLogPrefix() + "Rollback"; @@ -418,7 +408,6 @@ public class TransactionManager implements SpiTransactionManager { } txnLogger.debug(msg); } - } catch (Exception ex) { logger.error("Error while notifying TransactionEventListener of rollback event", ex); } @@ -445,7 +434,6 @@ public class TransactionManager implements SpiTransactionManager { } private void formatThrowable(Throwable e, StringBuilder sb) { - sb.append(e.toString()); StackTraceElement[] stackTrace = e.getStackTrace(); if (stackTrace.length > 0) { @@ -468,11 +456,9 @@ public class TransactionManager implements SpiTransactionManager { if (txnLogger.isDebug()) { txnLogger.debug(transaction.getLogPrefix() + "Commit"); } - PostCommitProcessing postCommit = new PostCommitProcessing(clusterManager, this, transaction); postCommit.notifyLocalCache(); backgroundExecutor.execute(postCommit.backgroundNotify()); - } catch (Exception ex) { logger.error("NotifyOfCommit failed. L2 Cache potentially not notified.", ex); } @@ -488,7 +474,6 @@ public class TransactionManager implements SpiTransactionManager { } private void externalModificationEvent(TransactionEventTable tableEvents) { - TransactionEvent event = new TransactionEvent(); event.add(tableEvents); @@ -501,25 +486,21 @@ public class TransactionManager implements SpiTransactionManager { * Notify local BeanPersistListeners etc of events from another server in the cluster. */ public void remoteTransactionEvent(RemoteTransactionEvent remoteEvent) { - if (clusterLogger.isDebugEnabled()) { clusterLogger.debug("processing {}", remoteEvent); } - CacheChangeSet changeSet = new CacheChangeSet(); RemoteTableMod tableMod = remoteEvent.getRemoteTableMod(); if (tableMod != null) { changeSet.addInvalidate(tableMod.getTables()); } - List* This will also potentially throw exceptions for MANDATORY and NEVER types. - *
*/ private boolean isCreateNewTransaction(SpiTransaction current, TxType type) { switch (type) { case REQUIRED: case SUPPORTS: return current == null; - case REQUIRES_NEW: return true; - case MANDATORY: if (current == null) { throw new PersistenceException("Transaction missing when MANDATORY"); } return false; - case NEVER: if (current != null) { throw new PersistenceException("Transaction exists for Transactional NEVER"); } return true; // always use NoTransaction instance - case NOT_SUPPORTED: return true; // always use NoTransaction instance - default: throw new RuntimeException("Should never get here?"); }