Merge pull request #2801 from ebean-orm/feature/drop-feature-OnQueryOnly

Remove the OnQueryOnly (rollback) feature
This commit is contained in:
Rob Bygrave
2022-08-25 12:30:16 +12:00
committed by GitHub
3 changed files with 7 additions and 160 deletions
@@ -22,23 +22,6 @@ public class DatabasePlatform {
private static final System.Logger log = EbeanVersion.log;
/**
* Behavior used when ending a query only transaction (at read committed isolation level).
*/
public enum OnQueryOnly {
/**
* Rollback the transaction.
*/
ROLLBACK,
/**
* Commit the transaction
*/
COMMIT
}
/**
* Set to true for MySql, no other jdbc drivers need this workaround.
*/
@@ -59,11 +42,6 @@ public class DatabasePlatform {
*/
protected boolean supportsNativeJavaTime = true;
/**
* The behaviour used when ending a read only transaction at read committed isolation level.
*/
protected OnQueryOnly onQueryOnly = OnQueryOnly.COMMIT;
/**
* The open quote used by quoted identifiers.
*/
@@ -409,20 +387,6 @@ public class DatabasePlatform {
return null;
}
/**
* Return the behaviour to use when ending a read only transaction.
*/
public OnQueryOnly getOnQueryOnly() {
return onQueryOnly;
}
/**
* Set the behaviour to use when ending a read only transaction.
*/
public void setOnQueryOnly(OnQueryOnly onQueryOnly) {
this.onQueryOnly = onQueryOnly;
}
/**
* Return the DbEncrypt handler for this DB platform.
*/
@@ -4,7 +4,6 @@ import io.ebean.ProfileLocation;
import io.ebean.TransactionCallback;
import io.ebean.annotation.DocStoreMode;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.dbplatform.DatabasePlatform.OnQueryOnly;
import io.ebean.event.changelog.BeanChange;
import io.ebean.event.changelog.ChangeSet;
import io.ebeaninternal.api.*;
@@ -33,154 +32,69 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
private static final Object PLACEHOLDER = new Object();
private static final String illegalStateMessage = "Transaction is Inactive";
/**
* The associated TransactionManager.
*/
final TransactionManager manager;
/**
* The transaction id.
*/
private final String id;
private final String logPrefix;
private final boolean logSql;
private final boolean logSummary;
private final boolean explicit;
private final boolean onQueryOnlyCommit;
/**
* The user defined label to group execution statistics.
*/
private String label;
/**
* Flag to indicate if this was an explicitly created Transaction.
*/
private final boolean explicit;
/**
* Behaviour for ending query only transactions.
*/
private final OnQueryOnly onQueryOnly;
/**
* The status of the transaction.
*/
private boolean active;
private boolean rollbackOnly;
private boolean nestedUseSavepoint;
/**
* The underlying Connection.
*/
Connection connection;
/**
* Used to queue up persist requests for batch execution.
*/
private BatchControl batchControl;
/**
* The event which holds persisted beans.
*/
private TransactionEvent event;
/**
* Holder of the objects fetched to ensure unique objects are used.
*/
private SpiPersistenceContext persistenceContext;
/**
* Used to give developers more control over the insert update and delete
* functionality.
*/
private boolean persistCascade = true;
/**
* Flag used for performance to skip commit or rollback of query only
* transactions in read committed transaction isolation.
*/
private boolean queryOnly = true;
private boolean localReadOnly;
private Boolean updateAllLoadedProperties;
private boolean oldBatchMode;
private boolean batchMode;
private boolean batchOnCascadeMode;
private int batchSize = -1;
private boolean batchFlushOnQuery = true;
private Boolean batchGetGeneratedKeys;
private Boolean batchFlushOnMixed;
private final String logPrefix;
private Object tenantId;
/**
* The depth used by batch processing to help the ordering of statements.
*/
private int depth;
/**
* Set to true if the connection has autoCommit=true initially.
*/
private boolean autoCommit;
private IdentityHashMap<Object, Object> persistingBeans;
private HashSet<Integer> deletingBeansHash;
private HashMap<String, String> m2mIntersectionSave;
private Map<String, Object> userObjects;
private List<TransactionCallback> callbackList;
private boolean batchOnCascadeSet;
private TChangeLogHolder changeLogHolder;
private List<PersistDeferredRelationship> deferredList;
/**
* The mode for updating doc store indexes for this transaction.
* Only set when you want to override the default behavior.
*/
private DocStoreMode docStoreMode;
private int docStoreBatchSize;
/**
* Explicit control over skipCache.
*/
private Boolean skipCache;
/**
* Default skip cache behavior from {@link DatabaseConfig#isSkipCacheAfterWrite()}.
*/
private final boolean skipCacheAfterWrite;
DocStoreTransaction docStoreTxn;
private ProfileStream profileStream;
private ProfileLocation profileLocation;
private final long startNanos;
private boolean autoPersistUpdates;
/**
* Create a new JdbcTransaction.
*/
JdbcTransaction(String id, boolean explicit, Connection connection, TransactionManager manager) {
try {
this.active = true;
@@ -191,14 +105,13 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
this.connection = connection;
this.persistenceContext = new DefaultPersistenceContext();
this.startNanos = System.nanoTime();
if (manager == null) {
this.logSql = false;
this.logSummary = false;
this.skipCacheAfterWrite = true;
this.batchMode = false;
this.batchOnCascadeMode = false;
this.onQueryOnly = OnQueryOnly.ROLLBACK;
this.onQueryOnlyCommit = false;
} else {
this.autoPersistUpdates = explicit && manager.isAutoPersistUpdates();
this.logSql = manager.isLogSql();
@@ -206,7 +119,7 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
this.skipCacheAfterWrite = manager.isSkipCacheAfterWrite();
this.batchMode = manager.isPersistBatch();
this.batchOnCascadeMode = manager.isPersistBatchOnCascade();
this.onQueryOnly = manager.onQueryOnly();
this.onQueryOnlyCommit = true;
}
checkAutoCommit(connection);
@@ -926,14 +839,14 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
private void connectionEndForQueryOnly() {
try {
withEachCallback(TransactionCallback::preCommit);
if (onQueryOnly == OnQueryOnly.COMMIT) {
if (onQueryOnlyCommit) {
performCommit();
} else {
performRollback();
}
withEachCallback(TransactionCallback::postCommit);
} catch (SQLException e) {
log.log(ERROR, "Error when ending a query only transaction via " + onQueryOnly, e);
log.log(ERROR, "Error when ending a query only transaction", e);
}
}
@@ -10,7 +10,6 @@ import io.ebean.cache.ServerCacheNotification;
import io.ebean.cache.ServerCacheNotify;
import io.ebean.config.CurrentTenantProvider;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.config.dbplatform.DatabasePlatform.OnQueryOnly;
import io.ebean.event.changelog.ChangeLogListener;
import io.ebean.event.changelog.ChangeLogPrepare;
import io.ebean.event.changelog.ChangeSet;
@@ -76,7 +75,6 @@ public class TransactionManager implements SpiTransactionManager {
* Flag to indicate the default Isolation is READ COMMITTED. This enables us
* to close queryOnly transactions rather than commit or rollback them.
*/
private final OnQueryOnly onQueryOnly;
private final BackgroundExecutor backgroundExecutor;
private final ClusterManager clusterManager;
private final String serverName;
@@ -145,7 +143,6 @@ public class TransactionManager implements SpiTransactionManager {
this.bulkEventListenerMap = new BulkEventListenerMap(options.config.getBulkTableEventListeners());
this.prefix = "";
this.externalTransPrefix = "e";
this.onQueryOnly = initOnQueryOnly(options.config.getDatabasePlatform().getOnQueryOnly());
CurrentTenantProvider tenantProvider = options.config.getCurrentTenantProvider();
this.transactionFactory = TransactionFactoryBuilder.build(this, dataSourceSupplier, tenantProvider);
@@ -253,26 +250,6 @@ public class TransactionManager implements SpiTransactionManager {
return persistBatchOnCascade;
}
/**
* Return the behaviour to use when a query only transaction is committed.
* <p>
* There is a potential optimisation available when read committed is the default
* isolation level. If it is, then Connections used only for queries do not require
* commit or rollback but instead can just be put back into the pool via close().
* <p>
* If the Isolation level is higher (say SERIALIZABLE) then Connections used
* just for queries do need to be committed or rollback after the query.
*/
final 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;
}
public final String name() {
return serverName;
}
@@ -292,13 +269,6 @@ public class TransactionManager implements SpiTransactionManager {
return dataSourceSupplier.getReadOnlyDataSource();
}
/**
* Defines the type of behavior to use when closing a transaction that was used to query data only.
*/
final OnQueryOnly onQueryOnly() {
return onQueryOnly;
}
/**
* Wrap the externally supplied Connection.
*/