mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1835 Refactor JDBC batch escalation
This commit is contained in:
@@ -283,7 +283,7 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
|
||||
* Check for batch escalation on cascade.
|
||||
*/
|
||||
public void checkBatchEscalationOnCascade() {
|
||||
if (type != Type.INSERT || beanDescriptor.isCascadeBatchEscalateSupported()) {
|
||||
if (type == Type.UPDATE || beanDescriptor.isBatchEscalateOnCascade(type)) {
|
||||
if (transaction.checkBatchEscalationOnCascade(this)) {
|
||||
// we escalated to use batch mode so flush when done
|
||||
// but if createdTransaction then commit will flush it
|
||||
|
||||
@@ -140,7 +140,8 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
private final short profileBeanId;
|
||||
|
||||
private final boolean multiValueSupported;
|
||||
private boolean cascadeBatchEscalateSupported;
|
||||
private boolean batchEscalateOnCascadeInsert;
|
||||
private boolean batchEscalateOnCascadeDelete;
|
||||
|
||||
public enum EntityType {
|
||||
ORM, EMBEDDED, VIEW, SQL, DOC
|
||||
@@ -831,7 +832,8 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
void initialiseDocMapping() {
|
||||
cascadeBatchEscalateSupported = supportCascadeBatch();
|
||||
batchEscalateOnCascadeInsert = supportBatchEscalateOnInsert();
|
||||
batchEscalateOnCascadeDelete = supportBatchEscalateOnDelete();
|
||||
for (BeanPropertyAssocMany<?> many : propertiesMany) {
|
||||
many.initialisePostTarget();
|
||||
}
|
||||
@@ -846,7 +848,19 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
cacheHelp.deriveNotifyFlags();
|
||||
}
|
||||
|
||||
private boolean supportCascadeBatch() {
|
||||
private boolean supportBatchEscalateOnDelete() {
|
||||
if (softDelete) {
|
||||
return false;
|
||||
}
|
||||
for (BeanPropertyAssocMany<?> assocMany : propertiesManyDelete) {
|
||||
if (assocMany.isCascadeDeleteEscalate()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean supportBatchEscalateOnInsert() {
|
||||
return idType == IdType.IDENTITY || !hasCircularImportedId();
|
||||
}
|
||||
|
||||
@@ -854,8 +868,8 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
* Return false if JDBC batch can't be implicitly escalated to.
|
||||
* This happens when we have circular import id situation (need to defer setting identity value).
|
||||
*/
|
||||
public boolean isCascadeBatchEscalateSupported() {
|
||||
return cascadeBatchEscalateSupported;
|
||||
public boolean isBatchEscalateOnCascade(PersistRequest.Type type) {
|
||||
return type == PersistRequest.Type.INSERT ? batchEscalateOnCascadeInsert : batchEscalateOnCascadeDelete;
|
||||
}
|
||||
|
||||
void initInheritInfo() {
|
||||
|
||||
@@ -958,6 +958,10 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
return cascadeInfo.isDelete() || o2mJoinTable || ModifyListenMode.REMOVALS == modifyListenMode;
|
||||
}
|
||||
|
||||
public boolean isCascadeDeleteEscalate() {
|
||||
return !elementCollection && cascadeInfo.isDelete();
|
||||
}
|
||||
|
||||
public String insertElementCollection() {
|
||||
return sqlHelp.insertElementCollection();
|
||||
}
|
||||
|
||||
@@ -639,11 +639,6 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
*/
|
||||
@Override
|
||||
public boolean isBatchThisRequest() {
|
||||
if (!batchOnCascadeSet && !explicit && depth <= 0) {
|
||||
// implicit transaction, no gain by batching where depth <= 0
|
||||
return false;
|
||||
}
|
||||
//
|
||||
return batchMode;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user