mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-08 00:38:20 +00:00
#1417 - Breaking API - Remove PersistBatch.INSERT ... migrate to PersistBatch.ALL
This commit is contained in:
1 parent
117737c790
commit
8d976f83a9
14 files changed
+140
-73
No files matched your search
@@ -359,7 +359,10 @@ public interface Transaction extends AutoCloseable {
|
||||
void setBatchMode(boolean useBatch);
|
||||
|
||||
/**
|
||||
* The JDBC batch mode to use for this transaction.
|
||||
* Deprecated - migrate to {@link #setBatchMode(boolean)}.
|
||||
* <p>
|
||||
* Set the JDBC batch mode to use for this transaction.
|
||||
* </p>
|
||||
* <p>
|
||||
* If this is NONE then JDBC batch can still be used for each request - save(), insert(), update() or delete()
|
||||
* and this would be useful if the request cascades to detail beans.
|
||||
@@ -368,15 +371,23 @@ public interface Transaction extends AutoCloseable {
|
||||
* @param persistBatchMode the batch mode to use for this transaction
|
||||
* @see io.ebean.config.ServerConfig#setPersistBatch(PersistBatch)
|
||||
*/
|
||||
@Deprecated
|
||||
void setBatch(PersistBatch persistBatchMode);
|
||||
|
||||
/**
|
||||
* Deprecated - migrate to {@link #isBatchMode()}.
|
||||
* Return the batch mode at the transaction level.
|
||||
*/
|
||||
@Deprecated
|
||||
PersistBatch getBatch();
|
||||
|
||||
/**
|
||||
* Return the batch mode at the transaction level.
|
||||
*/
|
||||
PersistBatch getBatch();
|
||||
boolean isBatchMode();
|
||||
|
||||
/**
|
||||
* Set the JDBC batch mode to use for a save() or delete() request.
|
||||
* Set the JDBC batch mode to use for a save() or delete() when cascading to children.
|
||||
* <p>
|
||||
* This only takes effect when batch mode on the transaction has not already meant that
|
||||
* JDBC batch mode is being used.
|
||||
@@ -385,17 +396,36 @@ public interface Transaction extends AutoCloseable {
|
||||
* This is useful when the single save() or delete() cascades. For example, inserting a 'master' cascades
|
||||
* and inserts a collection of 'detail' beans. The detail beans can be inserted using JDBC batch.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is effectively already turned on for all platforms apart from older Sql Server.
|
||||
* </p>
|
||||
*
|
||||
* @param batchOnCascadeMode the batch mode to use per save(), insert(), update() or delete()
|
||||
* @param batchMode the batch mode to use per save(), insert(), update() or delete()
|
||||
* @see io.ebean.config.ServerConfig#setPersistBatchOnCascade(PersistBatch)
|
||||
*/
|
||||
void setBatchOnCascade(boolean batchMode);
|
||||
|
||||
/**
|
||||
* Set the batch mode when cascading.
|
||||
* <p>
|
||||
* Deprecated in favour of {@link #setBatchOnCascade(boolean)}
|
||||
* </p>
|
||||
*/
|
||||
@Deprecated
|
||||
void setBatchOnCascade(PersistBatch batchOnCascadeMode);
|
||||
|
||||
/**
|
||||
* Deprecated - migrate to {@link #isBatchMode()}.
|
||||
* Return the batch mode at the request level (for each save(), insert(), update() or delete()).
|
||||
*/
|
||||
@Deprecated
|
||||
PersistBatch getBatchOnCascade();
|
||||
|
||||
/**
|
||||
* Return the batch mode at the request level.
|
||||
*/
|
||||
boolean isBatchOnCascade();
|
||||
|
||||
/**
|
||||
* Specify the number of statements before a batch is flushed automatically.
|
||||
*/
|
||||
|
||||
@@ -184,7 +184,7 @@ public interface SpiTransaction extends Transaction {
|
||||
* Return true if this request should be batched. Conversely returns false
|
||||
* if this request should be executed immediately.
|
||||
*/
|
||||
boolean isBatchThisRequest(PersistRequest.Type type);
|
||||
boolean isBatchThisRequest();
|
||||
|
||||
/**
|
||||
* Return the BatchControl used to batch up persist requests.
|
||||
|
||||
@@ -250,6 +250,11 @@ public abstract class SpiTransactionProxy implements SpiTransaction {
|
||||
transaction.setBatchMode(useBatch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchMode() {
|
||||
return transaction.isBatchMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatch(PersistBatch persistBatchMode) {
|
||||
transaction.setBatch(persistBatchMode);
|
||||
@@ -260,11 +265,21 @@ public abstract class SpiTransactionProxy implements SpiTransaction {
|
||||
return transaction.getBatch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchOnCascade(boolean batchMode) {
|
||||
transaction.setBatchOnCascade(batchMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchOnCascade(PersistBatch batchOnCascadeMode) {
|
||||
transaction.setBatchOnCascade(batchOnCascadeMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchOnCascade() {
|
||||
return transaction.isBatchOnCascade();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistBatch getBatchOnCascade() {
|
||||
return transaction.getBatchOnCascade();
|
||||
@@ -361,8 +376,8 @@ public abstract class SpiTransactionProxy implements SpiTransaction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchThisRequest(PersistRequest.Type type) {
|
||||
return transaction.isBatchThisRequest(type);
|
||||
public boolean isBatchThisRequest() {
|
||||
return transaction.isBatchThisRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -92,7 +92,7 @@ public abstract class PersistRequest extends BeanRequest implements BatchPostExe
|
||||
* Return true if this persist request should use JDBC batch.
|
||||
*/
|
||||
public boolean isBatchThisRequest() {
|
||||
return transaction.isBatchThisRequest(type);
|
||||
return transaction.isBatchThisRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -297,11 +297,25 @@ class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEventCode
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchOnCascade() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistBatch getBatch() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchOnCascade(boolean batchMode) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchOnCascade(PersistBatch batchOnCascadeMode) {
|
||||
}
|
||||
@@ -353,7 +367,7 @@ class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEventCode
|
||||
* this request should be executed immediately.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBatchThisRequest(PersistRequest.Type type) {
|
||||
public boolean isBatchThisRequest() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,11 +118,11 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
|
||||
protected Boolean updateAllLoadedProperties;
|
||||
|
||||
protected PersistBatch oldBatchMode;
|
||||
protected boolean oldBatchMode;
|
||||
|
||||
protected PersistBatch batchMode;
|
||||
protected boolean batchMode;
|
||||
|
||||
protected PersistBatch batchOnCascadeMode;
|
||||
protected boolean batchOnCascadeMode;
|
||||
|
||||
protected int batchSize = -1;
|
||||
|
||||
@@ -208,8 +208,8 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
this.logSql = false;
|
||||
this.logSummary = false;
|
||||
this.skipCacheAfterWrite = true;
|
||||
this.batchMode = PersistBatch.NONE;
|
||||
this.batchOnCascadeMode = PersistBatch.NONE;
|
||||
this.batchMode = false;
|
||||
this.batchOnCascadeMode = false;
|
||||
this.onQueryOnly = OnQueryOnly.ROLLBACK;
|
||||
} else {
|
||||
this.startMillis = manager.clockNowMillis();
|
||||
@@ -570,14 +570,6 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
|
||||
@Override
|
||||
public void setBatchMode(boolean batchMode) {
|
||||
if (!isActive()) {
|
||||
throw new IllegalStateException(illegalStateMessage);
|
||||
}
|
||||
this.batchMode = (batchMode) ? PersistBatch.ALL : PersistBatch.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatch(PersistBatch batchMode) {
|
||||
if (!isActive()) {
|
||||
throw new IllegalStateException(illegalStateMessage);
|
||||
}
|
||||
@@ -585,20 +577,40 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistBatch getBatch() {
|
||||
public void setBatch(PersistBatch batchMode) {
|
||||
setBatchMode(PersistBatch.ALL == batchMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchMode() {
|
||||
return batchMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchOnCascade(PersistBatch batchOnCascadeMode) {
|
||||
public PersistBatch getBatch() {
|
||||
return batchMode ? PersistBatch.ALL : PersistBatch.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchOnCascade(boolean batchMode) {
|
||||
if (!isActive()) {
|
||||
throw new IllegalStateException(illegalStateMessage);
|
||||
}
|
||||
this.batchOnCascadeMode = batchOnCascadeMode;
|
||||
this.batchOnCascadeMode = batchMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchOnCascade(PersistBatch batchMode) {
|
||||
setBatchOnCascade(PersistBatch.ALL == batchMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistBatch getBatchOnCascade() {
|
||||
return batchOnCascadeMode ? PersistBatch.ALL : PersistBatch.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchOnCascade() {
|
||||
return batchOnCascadeMode;
|
||||
}
|
||||
|
||||
@@ -657,36 +669,18 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
* this request should be executed immediately.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBatchThisRequest(PersistRequest.Type type) {
|
||||
public boolean isBatchThisRequest() {
|
||||
if (!batchOnCascadeSet && !explicit && depth <= 0) {
|
||||
// implicit transaction, no gain by batching where depth <= 0
|
||||
return false;
|
||||
}
|
||||
return isBatch(batchMode, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if JDBC batch should be used on cascade persist.
|
||||
*/
|
||||
private boolean isBatchOnCascade(PersistRequest.Type type) {
|
||||
return isBatch(batchOnCascadeMode, type);
|
||||
}
|
||||
|
||||
private boolean isBatch(PersistBatch batch, PersistRequest.Type type) {
|
||||
switch (batch) {
|
||||
case ALL:
|
||||
return true;
|
||||
case INSERT:
|
||||
return type == PersistRequest.Type.INSERT;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return batchMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkBatchEscalationOnCollection() {
|
||||
if (batchMode == PersistBatch.NONE && batchOnCascadeMode != PersistBatch.NONE) {
|
||||
batchMode = batchOnCascadeMode;
|
||||
if (!batchMode && batchOnCascadeMode) {
|
||||
batchMode = true;
|
||||
batchOnCascadeSet = true;
|
||||
}
|
||||
}
|
||||
@@ -696,7 +690,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
if (batchOnCascadeSet) {
|
||||
batchFlushReset();
|
||||
// restore the previous batch mode of NONE
|
||||
batchMode = PersistBatch.NONE;
|
||||
batchMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -753,15 +747,15 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
@Override
|
||||
public boolean checkBatchEscalationOnCascade(PersistRequestBean<?> request) {
|
||||
|
||||
if (isBatch(batchMode, request.getType())) {
|
||||
if (batchMode) {
|
||||
// already batching (at top level)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isBatchOnCascade(request.getType())) {
|
||||
if (batchOnCascadeMode) {
|
||||
// escalate up to batch mode for this request (and cascade)
|
||||
oldBatchMode = batchMode;
|
||||
batchMode = PersistBatch.ALL;
|
||||
oldBatchMode = false;
|
||||
batchMode = true;
|
||||
batchFlushReset();
|
||||
// skip using jdbc batch for the top level bean (no gain there)
|
||||
request.setSkipBatchForTopLevel();
|
||||
|
||||
@@ -236,6 +236,15 @@ class NoTransaction implements SpiTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchOnCascade(boolean batchMode) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchOnCascade(PersistBatch batchOnCascadeMode) {
|
||||
|
||||
@@ -246,6 +255,11 @@ class NoTransaction implements SpiTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchOnCascade() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchSize(int batchSize) {
|
||||
|
||||
@@ -337,7 +351,7 @@ class NoTransaction implements SpiTransaction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchThisRequest(PersistRequest.Type type) {
|
||||
public boolean isBatchThisRequest() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,9 +97,9 @@ public class TransactionManager implements SpiTransactionManager {
|
||||
*/
|
||||
protected final DocStoreUpdateProcessor docStoreUpdateProcessor;
|
||||
|
||||
protected final PersistBatch persistBatch;
|
||||
protected final boolean persistBatch;
|
||||
|
||||
protected final PersistBatch persistBatchOnCascade;
|
||||
protected final boolean persistBatchOnCascade;
|
||||
|
||||
protected final BulkEventListenerMap bulkEventListenerMap;
|
||||
|
||||
@@ -153,8 +153,8 @@ public class TransactionManager implements SpiTransactionManager {
|
||||
this.databasePlatform = options.config.getDatabasePlatform();
|
||||
this.skipCacheAfterWrite = options.config.isSkipCacheAfterWrite();
|
||||
this.notifyL2CacheInForeground = options.notifyL2CacheInForeground;
|
||||
this.persistBatch = options.config.getPersistBatch();
|
||||
this.persistBatchOnCascade = options.config.appliedPersistBatchOnCascade();
|
||||
this.persistBatch = PersistBatch.ALL == options.config.getPersistBatch();
|
||||
this.persistBatchOnCascade = PersistBatch.ALL == options.config.appliedPersistBatchOnCascade();
|
||||
this.rollbackOnChecked = options.config.isTransactionRollbackOnChecked();
|
||||
this.beanDescriptorManager = options.descMgr;
|
||||
this.viewInvalidation = options.descMgr.requiresViewEntityCacheInvalidation();
|
||||
@@ -271,11 +271,11 @@ public class TransactionManager implements SpiTransactionManager {
|
||||
return bulkEventListenerMap;
|
||||
}
|
||||
|
||||
public PersistBatch getPersistBatch() {
|
||||
public boolean getPersistBatch() {
|
||||
return persistBatch;
|
||||
}
|
||||
|
||||
public PersistBatch getPersistBatchOnCascade() {
|
||||
public boolean getPersistBatchOnCascade() {
|
||||
return persistBatchOnCascade;
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ public class TransactionManager implements SpiTransactionManager {
|
||||
ExternalJdbcTransaction t = new ExternalJdbcTransaction(id, true, c, this);
|
||||
|
||||
// set the default batch mode
|
||||
t.setBatch(persistBatch);
|
||||
t.setBatchMode(persistBatch);
|
||||
t.setBatchOnCascade(persistBatchOnCascade);
|
||||
return t;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user