ESTUP2-668 enabled bulk processing for repository service for a given class
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/services/repository/RepositoryService.java b/api/applib/src/main/java/org/apache/causeway/applib/services/repository/RepositoryService.java
index 35d9945..775b078 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/services/repository/RepositoryService.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/services/repository/RepositoryService.java
@@ -85,12 +85,12 @@
<T> T detachedEntity(@NonNull T entity);
/**
- * Suspends flushing transaction for {@param object} instances until the {@param bulkMode} is turned off again.
+ * Suspends flushing transaction for {@param aClass} instances until the {@param bulkMode} is turned off again.
* <p>
* Usage should be wrapped in a try {} finally {} construction.
*
*/
- <T> void setBulkMode(final T object, final Boolean bulkMode);
+ <T extends Class> void setBulkMode(final T aClass, final Boolean bulkMode);
/**
* Persist the specified object (or do nothing if already persistent).
diff --git a/extensions/security/audittrail/applib/src/main/java/org/apache/causeway/extensions/audittrail/applib/dom/AuditTrailEntryRepositoryAbstract.java b/extensions/security/audittrail/applib/src/main/java/org/apache/causeway/extensions/audittrail/applib/dom/AuditTrailEntryRepositoryAbstract.java
index 80c5820..88185cd 100644
--- a/extensions/security/audittrail/applib/src/main/java/org/apache/causeway/extensions/audittrail/applib/dom/AuditTrailEntryRepositoryAbstract.java
+++ b/extensions/security/audittrail/applib/src/main/java/org/apache/causeway/extensions/audittrail/applib/dom/AuditTrailEntryRepositoryAbstract.java
@@ -76,14 +76,14 @@
public Can<AuditTrailEntry> createForBulk(Can<EntityPropertyChange> entityPropertyChanges) {
Collection<AuditTrailEntry> auditTrailEntries = new ArrayList<>();
try {
- repositoryService.setBulkMode(AuditTrailEntry.class, true);
+ repositoryService.setBulkMode(AuditTrailEntry.class, Boolean.TRUE);
entityPropertyChanges.forEach(change -> {
E entry = factoryService.detachedEntity(auditTrailEntryClass);
entry.init(change);
auditTrailEntries.add(repositoryService.persist(entry));
});
} finally {
- repositoryService.setBulkMode(AuditTrailEntry.class, false);
+ repositoryService.setBulkMode(AuditTrailEntry.class, Boolean.FALSE);
}
return Can.ofCollection(auditTrailEntries);
}
diff --git a/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/repository/RepositoryServiceDefault.java b/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/repository/RepositoryServiceDefault.java
index 5be5c51..0cd0358 100644
--- a/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/repository/RepositoryServiceDefault.java
+++ b/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/repository/RepositoryServiceDefault.java
@@ -122,15 +122,16 @@
@Override
public <T> T persistAndFlush(final T object) {
persist(object);
- if(!bulkModeMap.computeIfAbsent(object.getClass(), aClass -> false)) {
+ if(!bulkModeMap.getOrDefault(object.getClass(), Boolean.FALSE)) {
transactionService.flushTransaction();
}
return object;
}
@Override
- public <T> void setBulkMode(final T object, final Boolean bulkMode) {
- if (!bulkModeMap.computeIfAbsent(object.getClass(), aClass -> bulkMode)) {
+ public <T extends Class> void setBulkMode(final T aClass, final Boolean bulkMode) {
+ bulkModeMap.computeIfAbsent(aClass, cl -> bulkMode);
+ if (!bulkMode) {
transactionService.flushTransaction();
}
}