From f5c12a916d7fc9ae33ed228746bf15442e676f22 Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Tue, 2 Jul 2019 22:58:31 +1200 Subject: [PATCH] #1747 - Refactor io.ebeaninternal.server.transaction access and remove unused --- .../server/core/InternalConfiguration.java | 36 +++--- .../DefaultTransactionScopeManager.java | 4 - .../transaction/DocStoreOnlyTransaction.java | 5 +- .../ExternalTransactionScopeManager.java | 3 +- .../ImplicitReadOnlyTransaction.java | 8 +- .../server/transaction/JdbcTransaction.java | 108 +++++++++--------- .../transaction/JtaTransactionManager.java | 18 +-- .../transaction/NoopPersistenceContext.java | 60 ---------- .../transaction/TransactionManager.java | 87 ++++++-------- .../transaction/TransactionScopeManager.java | 6 - 10 files changed, 122 insertions(+), 213 deletions(-) delete mode 100644 src/main/java/io/ebeaninternal/server/transaction/NoopPersistenceContext.java diff --git a/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java b/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java index cd3ab2e1c..1139eede1 100644 --- a/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java +++ b/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java @@ -163,7 +163,7 @@ public class InternalConfiguration { private final SpiLogManager logManager; - public InternalConfiguration(boolean online, ClusterManager clusterManager, SpiBackgroundExecutor backgroundExecutor, + InternalConfiguration(boolean online, ClusterManager clusterManager, SpiBackgroundExecutor backgroundExecutor, ServerConfig serverConfig, BootupClasses bootupClasses) { this.online = online; @@ -237,7 +237,7 @@ public class InternalConfiguration { return docStoreFactory; } - public ClockService getClockService() { + ClockService getClockService() { return clockService; } @@ -292,7 +292,7 @@ public class InternalConfiguration { /** * Return the ReadAuditLogger implementation to use. */ - public ReadAuditLogger getReadAuditLogger() { + ReadAuditLogger getReadAuditLogger() { ReadAuditLogger found = bootupClasses.getReadAuditLogger(); return plugin(found != null ? found : new DefaultReadAuditLogger()); } @@ -300,7 +300,7 @@ public class InternalConfiguration { /** * Return the ReadAuditPrepare implementation to use. */ - public ReadAuditPrepare getReadAuditPrepare() { + ReadAuditPrepare getReadAuditPrepare() { ReadAuditPrepare found = bootupClasses.getReadAuditPrepare(); return plugin(found != null ? found : new DefaultReadAuditPrepare()); } @@ -334,27 +334,27 @@ public class InternalConfiguration { return new MultiValueBind(); } - public SpiJsonContext createJsonContext(SpiEbeanServer server) { + SpiJsonContext createJsonContext(SpiEbeanServer server) { return new DJsonContext(server, jsonFactory, typeManager); } - public AutoTuneService createAutoTuneService(SpiEbeanServer server) { + AutoTuneService createAutoTuneService(SpiEbeanServer server) { return AutoTuneServiceFactory.create(server, serverConfig); } - public DtoQueryEngine createDtoQueryEngine() { + DtoQueryEngine createDtoQueryEngine() { return new DtoQueryEngine(binder); } - public RelationalQueryEngine createRelationalQueryEngine() { + RelationalQueryEngine createRelationalQueryEngine() { return new DefaultRelationalQueryEngine(binder, serverConfig.getDatabaseBooleanTrue(), serverConfig.getPlatformConfig().getDbUuid().useBinaryOptimized()); } - public OrmQueryEngine createOrmQueryEngine() { + OrmQueryEngine createOrmQueryEngine() { return new DefaultOrmQueryEngine(cQueryEngine, binder); } - public Persister createPersister(SpiEbeanServer server) { + Persister createPersister(SpiEbeanServer server) { return new DefaultPersister(server, binder, beanDescriptorManager); } @@ -382,7 +382,7 @@ public class InternalConfiguration { return binder; } - public BeanDescriptorManager getBeanDescriptorManager() { + BeanDescriptorManager getBeanDescriptorManager() { return beanDescriptorManager; } @@ -398,7 +398,7 @@ public class InternalConfiguration { return deployUtil; } - public CQueryEngine getCQueryEngine() { + CQueryEngine getCQueryEngine() { return cQueryEngine; } @@ -414,14 +414,14 @@ public class InternalConfiguration { /** * Create the DocStoreIntegration components for the given server. */ - public DocStoreIntegration createDocStoreIntegration(SpiServer server) { + DocStoreIntegration createDocStoreIntegration(SpiServer server) { return plugin(docStoreFactory.create(server)); } /** * Create the TransactionManager taking into account autoCommit mode. */ - public TransactionManager createTransactionManager(DocStoreUpdateProcessor indexUpdateProcessor) { + TransactionManager createTransactionManager(DocStoreUpdateProcessor indexUpdateProcessor) { TransactionScopeManager scopeManager = createTransactionScopeManager(); boolean notifyL2CacheInForeground = cacheManager.isLocalL2Caching() || serverConfig.isNotifyL2CacheInForeground(); @@ -496,9 +496,9 @@ public class InternalConfiguration { } if (externalTransactionManager != null) { logger.info("Using Transaction Manager [" + externalTransactionManager.getClass() + "]"); - return new ExternalTransactionScopeManager(serverConfig.getName(), externalTransactionManager); + return new ExternalTransactionScopeManager(externalTransactionManager); } else { - return new DefaultTransactionScopeManager(serverConfig.getName()); + return new DefaultTransactionScopeManager(); } } @@ -559,11 +559,11 @@ public class InternalConfiguration { return multiValueBind; } - public DtoBeanManager getDtoBeanManager() { + DtoBeanManager getDtoBeanManager() { return dtoBeanManager; } - public SpiLogManager getLogManager() { + SpiLogManager getLogManager() { return logManager; } diff --git a/src/main/java/io/ebeaninternal/server/transaction/DefaultTransactionScopeManager.java b/src/main/java/io/ebeaninternal/server/transaction/DefaultTransactionScopeManager.java index 0134ff5ed..0cabba365 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/DefaultTransactionScopeManager.java +++ b/src/main/java/io/ebeaninternal/server/transaction/DefaultTransactionScopeManager.java @@ -12,10 +12,6 @@ public class DefaultTransactionScopeManager extends TransactionScopeManager { private final ThreadLocal local = new ThreadLocal<>(); - public DefaultTransactionScopeManager(String serverName) { - super(serverName); - } - @Override public void register(TransactionManager manager) { // do nothing diff --git a/src/main/java/io/ebeaninternal/server/transaction/DocStoreOnlyTransaction.java b/src/main/java/io/ebeaninternal/server/transaction/DocStoreOnlyTransaction.java index 4bb23735e..43fb216a5 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/DocStoreOnlyTransaction.java +++ b/src/main/java/io/ebeaninternal/server/transaction/DocStoreOnlyTransaction.java @@ -1,7 +1,6 @@ package io.ebeaninternal.server.transaction; import java.sql.Connection; -import java.sql.SQLException; /** * Document store only transaction. @@ -41,12 +40,12 @@ public class DocStoreOnlyTransaction extends JdbcTransaction { } @Override - protected void performRollback() throws SQLException { + protected void performRollback() { // do nothing (could perhaps throw not supported exception) } @Override - protected void performCommit() throws SQLException { + protected void performCommit() { if (docStoreTxn != null) { manager.docStoreUpdateProcessor.commit(docStoreTxn); } diff --git a/src/main/java/io/ebeaninternal/server/transaction/ExternalTransactionScopeManager.java b/src/main/java/io/ebeaninternal/server/transaction/ExternalTransactionScopeManager.java index ffa3bdb1e..b033e277b 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/ExternalTransactionScopeManager.java +++ b/src/main/java/io/ebeaninternal/server/transaction/ExternalTransactionScopeManager.java @@ -13,8 +13,7 @@ public class ExternalTransactionScopeManager extends DefaultTransactionScopeMana /** * Instantiates transaction scope manager. */ - public ExternalTransactionScopeManager(String serverName, ExternalTransactionManager externalManager) { - super(serverName); + public ExternalTransactionScopeManager(ExternalTransactionManager externalManager) { this.externalManager = externalManager; } diff --git a/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java b/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java index 9e0822e15..b43fa2190 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java +++ b/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java @@ -47,24 +47,24 @@ class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEventCode /** * The status of the transaction. */ - protected boolean active; + private boolean active; /** * The underlying Connection which is expected to use autoCommit such that we avoid the * explicit commit call at the end of the 'transaction' (for performance). */ - protected Connection connection; + private Connection connection; /** * Holder of the objects fetched to ensure unique objects are used. */ - protected PersistenceContext persistenceContext; + private PersistenceContext persistenceContext; private Object tenantId; private Map userObjects; - private long startNanos; + private final long startNanos; /** * Create without a tenantId. diff --git a/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java b/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java index fceefc682..20b93bd82 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java +++ b/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java @@ -35,7 +35,7 @@ import java.util.Map; /** * JDBC Connection based transaction. */ -public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { +class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { private static final Logger logger = LoggerFactory.getLogger(JdbcTransaction.class); @@ -46,12 +46,12 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { /** * The associated TransactionManager. */ - protected final TransactionManager manager; + final TransactionManager manager; /** * The transaction id. */ - protected final String id; + private final String id; private final boolean logSql; private final boolean logSummary; @@ -59,137 +59,137 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { /** * The user defined label to group execution statistics. */ - protected String label; + private String label; /** * Flag to indicate if this was an explicitly created Transaction. */ - protected final boolean explicit; + private final boolean explicit; /** * Behaviour for ending query only transactions. */ - protected final OnQueryOnly onQueryOnly; + private final OnQueryOnly onQueryOnly; /** * The status of the transaction. */ - protected boolean active; + private boolean active; - protected boolean rollbackOnly; + private boolean rollbackOnly; - protected boolean nestedUseSavepoint; + private boolean nestedUseSavepoint; /** * The underlying Connection. */ - protected Connection connection; + Connection connection; /** * Used to queue up persist requests for batch execution. */ - protected BatchControl batchControl; + private BatchControl batchControl; /** * The event which holds persisted beans. */ - protected TransactionEvent event; + private TransactionEvent event; /** * Holder of the objects fetched to ensure unique objects are used. */ - protected PersistenceContext persistenceContext; + private PersistenceContext persistenceContext; /** * Used to give developers more control over the insert update and delete * functionality. */ - protected boolean persistCascade = true; + private boolean persistCascade = true; /** * Flag used for performance to skip commit or rollback of query only * transactions in read committed transaction isolation. */ - protected boolean queryOnly = true; + private boolean queryOnly = true; - protected boolean localReadOnly; + private boolean localReadOnly; - protected Boolean updateAllLoadedProperties; + private Boolean updateAllLoadedProperties; - protected boolean oldBatchMode; + private boolean oldBatchMode; - protected boolean batchMode; + private boolean batchMode; - protected boolean batchOnCascadeMode; + private boolean batchOnCascadeMode; - protected int batchSize = -1; + private int batchSize = -1; - protected boolean batchFlushOnQuery = true; + private boolean batchFlushOnQuery = true; - protected Boolean batchGetGeneratedKeys; + private Boolean batchGetGeneratedKeys; - protected Boolean batchFlushOnMixed; + private Boolean batchFlushOnMixed; - protected String logPrefix; + private String logPrefix; private Object tenantId; /** * The depth used by batch processing to help the ordering of statements. */ - protected int depth; + private int depth; /** * Set to true if the connection has autoCommit=true initially. */ - protected boolean autoCommit; + private boolean autoCommit; - protected IdentityHashMap persistingBeans; + private IdentityHashMap persistingBeans; - protected HashSet deletingBeansHash; + private HashSet deletingBeansHash; - protected HashMap m2mIntersectionSave; + private HashMap m2mIntersectionSave; - protected Map userObjects; + private Map userObjects; - protected List callbackList; + private List callbackList; - protected boolean batchOnCascadeSet; + private boolean batchOnCascadeSet; - protected TChangeLogHolder changeLogHolder; + private TChangeLogHolder changeLogHolder; - protected List deferredList; + private List deferredList; /** * The mode for updating doc store indexes for this transaction. * Only set when you want to override the default behavior. */ - protected DocStoreMode docStoreMode; + private DocStoreMode docStoreMode; - protected int docStoreBatchSize; + private int docStoreBatchSize; /** * Explicit control over skipCache. */ - protected Boolean skipCache; + private Boolean skipCache; /** * Default skip cache behavior from {@link ServerConfig#isSkipCacheAfterWrite()}. */ - protected final boolean skipCacheAfterWrite; + private final boolean skipCacheAfterWrite; - protected DocStoreTransaction docStoreTxn; + DocStoreTransaction docStoreTxn; private ProfileStream profileStream; - protected ProfileLocation profileLocation; + private ProfileLocation profileLocation; - protected final long startNanos; + private final long startNanos; /** * Create a new JdbcTransaction. */ - public JdbcTransaction(String id, boolean explicit, Connection connection, TransactionManager manager) { + JdbcTransaction(String id, boolean explicit, Connection connection, TransactionManager manager) { try { this.active = true; this.id = id; @@ -273,7 +273,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { /** * Overridden in AutoCommitJdbcTransaction as that expects to run/operate with autocommit true. */ - protected void checkAutoCommit(Connection connection) throws SQLException { + void checkAutoCommit(Connection connection) throws SQLException { if (connection != null) { this.autoCommit = connection.getAutoCommit(); if (this.autoCommit) { @@ -341,7 +341,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { callbackList.add(callback); } - protected void firePreRollback() { + private void firePreRollback() { if (callbackList != null) { for (TransactionCallback callback : callbackList) { try { @@ -353,7 +353,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { } } - protected void firePostRollback() { + private void firePostRollback() { if (callbackList != null) { for (TransactionCallback callback : callbackList) { try { @@ -368,7 +368,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { } } - protected void firePreCommit() { + private void firePreCommit() { if (callbackList != null) { for (TransactionCallback callback : callbackList) { try { @@ -380,7 +380,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { } } - protected void firePostCommit() { + private void firePostCommit() { if (callbackList != null) { for (TransactionCallback callback : callbackList) { try { @@ -895,7 +895,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { return getInternalConnection(); } - protected void deactivate() { + void deactivate() { try { if (localReadOnly) { // reset readOnly status prior to returning to pool @@ -927,7 +927,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { /** * Notify the transaction manager. */ - protected void notifyCommit() { + void notifyCommit() { if (manager != null) { if (queryOnly) { manager.notifyOfQueryOnly(this); @@ -940,7 +940,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { /** * Rollback or Commit for query only transaction. */ - protected void connectionEndForQueryOnly() { + private void connectionEndForQueryOnly() { try { if (onQueryOnly == OnQueryOnly.COMMIT) { performCommit(); @@ -955,7 +955,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { /** * Perform the actual rollback on the connection. */ - protected void performRollback() throws SQLException { + void performRollback() throws SQLException { long offset = profileOffset(); connection.rollback(); if (profileStream != null) { @@ -966,7 +966,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { /** * Perform the actual commit on the connection. */ - protected void performCommit() throws SQLException { + void performCommit() throws SQLException { long offset = profileOffset(); connection.commit(); if (profileStream != null) { @@ -1071,7 +1071,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { /** * Notify the transaction manager. */ - protected void notifyRollback(Throwable cause) { + void notifyRollback(Throwable cause) { if (manager != null) { if (queryOnly) { manager.notifyOfQueryOnly(this); diff --git a/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java b/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java index 0bfd76e4f..3fbed7d84 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java +++ b/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java @@ -10,13 +10,8 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import javax.persistence.PersistenceException; import javax.sql.DataSource; -import javax.transaction.HeuristicMixedException; -import javax.transaction.HeuristicRollbackException; -import javax.transaction.NotSupportedException; -import javax.transaction.RollbackException; import javax.transaction.Status; import javax.transaction.Synchronization; -import javax.transaction.SystemException; import javax.transaction.TransactionSynchronizationRegistry; import javax.transaction.UserTransaction; @@ -149,29 +144,28 @@ public class JtaTransactionManager implements ExternalTransactionManager { private static class DummyUserTransaction implements UserTransaction { @Override - public void begin() throws NotSupportedException, SystemException { + public void begin() { } @Override - public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, - SecurityException, IllegalStateException, SystemException { + public void commit() throws SecurityException, IllegalStateException { } @Override - public int getStatus() throws SystemException { + public int getStatus() { return 0; } @Override - public void rollback() throws IllegalStateException, SecurityException, SystemException { + public void rollback() throws IllegalStateException, SecurityException { } @Override - public void setRollbackOnly() throws IllegalStateException, SystemException { + public void setRollbackOnly() throws IllegalStateException { } @Override - public void setTransactionTimeout(int seconds) throws SystemException { + public void setTransactionTimeout(int seconds) { } } diff --git a/src/main/java/io/ebeaninternal/server/transaction/NoopPersistenceContext.java b/src/main/java/io/ebeaninternal/server/transaction/NoopPersistenceContext.java deleted file mode 100644 index e66dc8512..000000000 --- a/src/main/java/io/ebeaninternal/server/transaction/NoopPersistenceContext.java +++ /dev/null @@ -1,60 +0,0 @@ -package io.ebeaninternal.server.transaction; - -import io.ebean.bean.PersistenceContext; - -/** - * PersistenceContext used with scope of NONE. - *

- * When used effectively means no PersistenceContext is used at all. This is not expected to be used much and - * actually is not recommended. - */ -public class NoopPersistenceContext implements PersistenceContext { - - @Override - public void put(Class rootType, Object id, Object bean) { - // do nothing - } - - @Override - public Object putIfAbsent(Class rootType, Object id, Object bean) { - // do nothing - return null; - } - - @Override - public Object get(Class beanType, Object uid) { - // do nothing, return null - return null; - } - - @Override - public WithOption getWithOption(Class beanType, Object uid) { - // do nothing, return null - return null; - } - - @Override - public void clear() { - // do nothing - } - - @Override - public void clear(Class beanType) { - // do nothing - } - - @Override - public void clear(Class beanType, Object uid) { - // do nothing - } - - @Override - public void deleted(Class beanType, Object id) { - // do nothing - } - - @Override - public int size(Class beanType) { - return 0; - } -} diff --git a/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java b/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java index c1d5aadd9..8b5c87671 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java +++ b/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java @@ -30,7 +30,6 @@ import io.ebeaninternal.api.TransactionEventTable; import io.ebeaninternal.api.TransactionEventTable.TableIUD; import io.ebeaninternal.server.cache.CacheChangeSet; import io.ebeaninternal.server.cluster.ClusterManager; -import io.ebeaninternal.server.core.ClockService; import io.ebeaninternal.server.deploy.BeanDescriptorManager; import io.ebeaninternal.server.profile.TimedProfileLocation; import io.ebeaninternal.server.profile.TimedProfileLocationRegistry; @@ -57,9 +56,9 @@ public class TransactionManager implements SpiTransactionManager { private static final Logger logger = LoggerFactory.getLogger(TransactionManager.class); - public static final Logger clusterLogger = LoggerFactory.getLogger("io.ebean.Cluster"); + private static final Logger clusterLogger = LoggerFactory.getLogger("io.ebean.Cluster"); - protected final BeanDescriptorManager beanDescriptorManager; + private final BeanDescriptorManager beanDescriptorManager; /** * Ebean defaults this to true but for EJB compatible behaviour set this to @@ -70,39 +69,39 @@ public class TransactionManager implements SpiTransactionManager { /** * Prefix for transaction id's (logging). */ - protected final String prefix; + final String prefix; - protected final String externalTransPrefix; + private final String externalTransPrefix; /** * The dataSource of connections. */ - protected final DataSourceSupplier dataSourceSupplier; + private final DataSourceSupplier dataSourceSupplier; /** * Flag to indicate the default Isolation is READ COMMITTED. This enables us * to close queryOnly transactions rather than commit or rollback them. */ - protected final OnQueryOnly onQueryOnly; + private final OnQueryOnly onQueryOnly; - protected final BackgroundExecutor backgroundExecutor; + private final BackgroundExecutor backgroundExecutor; - protected final ClusterManager clusterManager; + private final ClusterManager clusterManager; - protected final String serverName; + private final String serverName; - protected final boolean docStoreActive; + private final boolean docStoreActive; /** * The elastic search index update processor. */ - protected final DocStoreUpdateProcessor docStoreUpdateProcessor; + final DocStoreUpdateProcessor docStoreUpdateProcessor; - protected final boolean persistBatch; + private final boolean persistBatch; - protected final boolean persistBatchOnCascade; + private final boolean persistBatchOnCascade; - protected final BulkEventListenerMap bulkEventListenerMap; + private final BulkEventListenerMap bulkEventListenerMap; /** * Used to prepare the change set setting user context information in the @@ -120,9 +119,9 @@ public class TransactionManager implements SpiTransactionManager { */ private final boolean changeLogAsync; - protected final boolean notifyL2CacheInForeground; + final boolean notifyL2CacheInForeground; - protected final boolean viewInvalidation; + private final boolean viewInvalidation; private final boolean skipCacheAfterWrite; @@ -142,7 +141,6 @@ public class TransactionManager implements SpiTransactionManager { private final TableModState tableModState; private final ServerCacheNotify cacheNotify; - private final ClockService clockService; /** * Create the TransactionManager @@ -167,7 +165,6 @@ public class TransactionManager implements SpiTransactionManager { this.scopeManager = options.scopeManager; this.tableModState = options.tableModState; this.cacheNotify = options.cacheNotify; - this.clockService = options.clockService; this.backgroundExecutor = options.backgroundExecutor; this.dataSourceSupplier = options.dataSourceSupplier; this.docStoreActive = options.config.getDocStoreConfig().isActive(); @@ -189,13 +186,6 @@ public class TransactionManager implements SpiTransactionManager { scopeManager.register(this); } - /** - * Return the NOW timestamp in epoch millis. - */ - public long clockNowMillis() { - return clockService.nowMillis(); - } - /** * Create a new scoped transaction. */ @@ -228,7 +218,7 @@ public class TransactionManager implements SpiTransactionManager { /** * Return the current active transaction as a scoped transaction. */ - public ScopedTransaction getActiveScoped() { + private ScopedTransaction getActiveScoped() { return (ScopedTransaction) scopeManager.getActive(); } @@ -252,15 +242,15 @@ public class TransactionManager implements SpiTransactionManager { } } - public boolean isDocStoreActive() { + boolean isDocStoreActive() { return docStoreActive; } - public DocStoreTransaction createDocStoreTransaction(int docStoreBatchSize) { + DocStoreTransaction createDocStoreTransaction(int docStoreBatchSize) { return docStoreUpdateProcessor.createTransaction(docStoreBatchSize); } - public boolean isSkipCacheAfterWrite() { + boolean isSkipCacheAfterWrite() { return skipCacheAfterWrite; } @@ -268,11 +258,11 @@ public class TransactionManager implements SpiTransactionManager { return beanDescriptorManager; } - public BulkEventListenerMap getBulkEventListenerMap() { + BulkEventListenerMap getBulkEventListenerMap() { return bulkEventListenerMap; } - public boolean getPersistBatch() { + boolean getPersistBatch() { return persistBatch; } @@ -292,7 +282,7 @@ public class TransactionManager implements SpiTransactionManager { * just for queries do need to be committed or rollback after the query. *

*/ - protected OnQueryOnly initOnQueryOnly(OnQueryOnly dbPlatformOnQueryOnly) { + OnQueryOnly initOnQueryOnly(OnQueryOnly dbPlatformOnQueryOnly) { // first check for a system property 'override' String systemPropertyValue = System.getProperty("ebean.transaction.onqueryonly"); @@ -321,7 +311,7 @@ public class TransactionManager implements SpiTransactionManager { /** * Defines the type of behavior to use when closing a transaction that was used to query data only. */ - public OnQueryOnly getOnQueryOnly() { + OnQueryOnly getOnQueryOnly() { return onQueryOnly; } @@ -329,14 +319,13 @@ public class TransactionManager implements SpiTransactionManager { * Wrap the externally supplied Connection. */ public SpiTransaction wrapExternalConnection(Connection c) { - return wrapExternalConnection(externalTransPrefix + c.hashCode(), c); } /** * Wrap an externally supplied Connection with a known transaction id. */ - public SpiTransaction wrapExternalConnection(String id, Connection c) { + private SpiTransaction wrapExternalConnection(String id, Connection c) { ExternalJdbcTransaction t = new ExternalJdbcTransaction(id, true, c, this); @@ -363,7 +352,7 @@ public class TransactionManager implements SpiTransactionManager { /** * Create a new transaction. */ - protected SpiTransaction createTransaction(boolean explicit, Connection c, long id) { + SpiTransaction createTransaction(boolean explicit, Connection c, long id) { return new JdbcTransaction(prefix + id, explicit, c, this); } @@ -371,7 +360,7 @@ public class TransactionManager implements SpiTransactionManager { /** * Process a local rolled back transaction. */ - public void notifyOfRollback(SpiTransaction transaction, Throwable cause) { + void notifyOfRollback(SpiTransaction transaction, Throwable cause) { try { if (txnLogger.isDebug()) { @@ -390,7 +379,7 @@ public class TransactionManager implements SpiTransactionManager { /** * Query only transaction in read committed isolation. */ - public void notifyOfQueryOnly(SpiTransaction transaction) { + void notifyOfQueryOnly(SpiTransaction transaction) { // Nothing that interesting here if (txnLogger.isTrace()) { @@ -425,7 +414,7 @@ public class TransactionManager implements SpiTransactionManager { /** * Process a local committed transaction. */ - public void notifyOfCommit(SpiTransaction transaction) { + void notifyOfCommit(SpiTransaction transaction) { try { if (txnLogger.isDebug()) { @@ -498,14 +487,14 @@ public class TransactionManager implements SpiTransactionManager { /** * Process the docstore / ElasticSearch updates. */ - public void processDocStoreUpdates(DocStoreUpdates docStoreUpdates, int bulkBatchSize) { + void processDocStoreUpdates(DocStoreUpdates docStoreUpdates, int bulkBatchSize) { docStoreUpdateProcessor.process(docStoreUpdates, bulkBatchSize); } /** * Prepare and then send/log the changeSet. */ - public void sendChangeLog(final ChangeSet changeSet) { + void sendChangeLog(final ChangeSet changeSet) { // can set userId, userIpAddress & userContext if desired if (changeLogPrepare.prepare(changeSet)) { @@ -522,7 +511,7 @@ public class TransactionManager implements SpiTransactionManager { /** * Invalidate the query caches for entities based on views. */ - public void processTouchedTables(Set touchedTables) { + void processTouchedTables(Set touchedTables) { tableModState.touch(touchedTables); if (viewInvalidation) { beanDescriptorManager.processViewInvalidation(touchedTables); @@ -533,28 +522,28 @@ public class TransactionManager implements SpiTransactionManager { /** * Process the collected transaction profiling information. */ - public void profileCollect(TransactionProfile transactionProfile) { + void profileCollect(TransactionProfile transactionProfile) { profileHandler.collectTransactionProfile(transactionProfile); } /** * Collect execution time for an explicit transaction. */ - public void collectMetric(long exeMicros) { + void collectMetric(long exeMicros) { txnMain.add(exeMicros); } /** * Collect execution time for implicit read only transaction. */ - public void collectMetricReadOnly(long exeMicros) { + void collectMetricReadOnly(long exeMicros) { txnReadOnly.add(exeMicros); } /** * Collect execution time for a named transaction. */ - public void collectMetricNamed(long exeMicros, String label) { + void collectMetricNamed(long exeMicros, String label) { txnNamed.add(label, exeMicros); } @@ -712,6 +701,7 @@ public class TransactionManager implements SpiTransactionManager { private boolean isCreateNewTransaction(SpiTransaction current, TxType type) { switch (type) { case REQUIRED: + case SUPPORTS: return current == null; case REQUIRES_NEW: @@ -723,9 +713,6 @@ public class TransactionManager implements SpiTransactionManager { } return false; - case SUPPORTS: - return current == null; - case NEVER: if (current != null) { throw new PersistenceException("Transaction exists for Transactional NEVER"); diff --git a/src/main/java/io/ebeaninternal/server/transaction/TransactionScopeManager.java b/src/main/java/io/ebeaninternal/server/transaction/TransactionScopeManager.java index ac5ce6616..0034ca2e4 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/TransactionScopeManager.java +++ b/src/main/java/io/ebeaninternal/server/transaction/TransactionScopeManager.java @@ -8,12 +8,6 @@ import io.ebeaninternal.api.SpiTransactionScopeManager; */ public abstract class TransactionScopeManager implements SpiTransactionScopeManager { - protected final String serverName; - - public TransactionScopeManager(String serverName) { - this.serverName = serverName; - } - /** * Register the transaction manager (for use by external transaction scopes). */