You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2022/08/04 06:04:50 UTC
[isis] 02/02: ISIS-3110: fixes up compile issues resulting from deletion of unneeded superclass
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-3110
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 6e5e265f786b6801636014a393f4818306923e9e
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Aug 4 07:04:37 2022 +0100
ISIS-3110: fixes up compile issues resulting from deletion of unneeded superclass
---
.../publish/LifecycleCallbackNotifier.java | 120 +++++++++------------
.../PersistenceCallbackHandlerAbstract.java | 61 -----------
.../changetracking/EntityChangeTrackerDefault.java | 22 +---
.../DomainModelTest_usingBadDomain.java | 8 +-
4 files changed, 63 insertions(+), 148 deletions(-)
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/LifecycleCallbackNotifier.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/LifecycleCallbackNotifier.java
index d6a941c67e..fbd6d448a8 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/LifecycleCallbackNotifier.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/LifecycleCallbackNotifier.java
@@ -32,11 +32,15 @@ import org.springframework.stereotype.Component;
import org.apache.isis.applib.annotation.InteractionScope;
import org.apache.isis.applib.annotation.PriorityPrecedence;
+import org.apache.isis.applib.events.lifecycle.AbstractLifecycleEvent;
import org.apache.isis.applib.services.bookmark.Bookmark;
import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.iactnlayer.InteractionService;
+import org.apache.isis.commons.internal.factory._InstanceUtil;
import org.apache.isis.core.metamodel.facets.object.callbacks.CallbackFacet;
import org.apache.isis.core.metamodel.facets.object.callbacks.CreatedCallbackFacet;
import org.apache.isis.core.metamodel.facets.object.callbacks.CreatedLifecycleEventFacet;
+import org.apache.isis.core.metamodel.facets.object.callbacks.LifecycleEventFacet;
import org.apache.isis.core.metamodel.facets.object.callbacks.LoadedCallbackFacet;
import org.apache.isis.core.metamodel.facets.object.callbacks.LoadedLifecycleEventFacet;
import org.apache.isis.core.metamodel.facets.object.callbacks.PersistedCallbackFacet;
@@ -51,10 +55,12 @@ import org.apache.isis.core.metamodel.facets.object.callbacks.UpdatingCallbackFa
import org.apache.isis.core.metamodel.facets.object.callbacks.UpdatingLifecycleEventFacet;
import org.apache.isis.core.metamodel.spec.ManagedObject;
import org.apache.isis.core.runtimeservices.IsisModuleCoreRuntimeServices;
-import org.apache.isis.core.transaction.changetracking.PersistenceCallbackHandlerAbstract;
import org.apache.isis.core.transaction.changetracking.events.PostStoreEvent;
import org.apache.isis.core.transaction.changetracking.events.PreStoreEvent;
+import lombok.RequiredArgsConstructor;
+import lombok.val;
+
/**
* Calls lifecycle callbacks for entities, ensuring that any given entity is only ever called once.
* @since 2.0 {@index}
@@ -62,97 +68,75 @@ import org.apache.isis.core.transaction.changetracking.events.PreStoreEvent;
@Component
@Named(IsisModuleCoreRuntimeServices.NAMESPACE + ".LifecycleCallbackNotifier")
@Priority(PriorityPrecedence.EARLY)
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
@Qualifier("Default")
-@InteractionScope
//@Log4j2
-public class LifecycleCallbackNotifier extends PersistenceCallbackHandlerAbstract {
-
- private final Set<ManagedObject> postCreated = new LinkedHashSet<>();
- private final Set<ManagedObject> postLoaded = new LinkedHashSet<>();
- private final Set<ManagedObject> prePersisted = new LinkedHashSet<>();
- private final Set<ManagedObject> postPersisted = new LinkedHashSet<>();
- private final Set<ManagedObject> preUpdated = new LinkedHashSet<>();
- private final Set<ManagedObject> postUpdated = new LinkedHashSet<>();
- private final Set<ManagedObject> preRemoved = new LinkedHashSet<>();
-
- @Inject
- public LifecycleCallbackNotifier(EventBusService eventBusService) {
- super(eventBusService);
- }
+public class LifecycleCallbackNotifier {
+
+ final EventBusService eventBusService;
public void postCreate(ManagedObject entity) {
- notify(entity,
- postCreated,
- e -> {
- CallbackFacet.callCallback(entity, CreatedCallbackFacet.class);
- postLifecycleEventIfRequired(entity, CreatedLifecycleEventFacet.class);
- });
+ CallbackFacet.callCallback(entity, CreatedCallbackFacet.class);
+ postLifecycleEventIfRequired(entity, CreatedLifecycleEventFacet.class);
}
public void postLoad(ManagedObject entity) {
- notify(entity,
- postLoaded,
- e -> {
- CallbackFacet.callCallback(entity, LoadedCallbackFacet.class);
- postLifecycleEventIfRequired(entity, LoadedLifecycleEventFacet.class);
- });
+ CallbackFacet.callCallback(entity, LoadedCallbackFacet.class);
+ postLifecycleEventIfRequired(entity, LoadedLifecycleEventFacet.class);
}
public void prePersist(ManagedObject entity) {
- notify(entity,
- prePersisted,
- e -> {
- eventBusService.post(PreStoreEvent.of(entity.getPojo()));
- CallbackFacet.callCallback(entity, PersistingCallbackFacet.class);
- postLifecycleEventIfRequired(entity, PersistingLifecycleEventFacet.class);
- });
+ eventBusService.post(PreStoreEvent.of(entity.getPojo()));
+ CallbackFacet.callCallback(entity, PersistingCallbackFacet.class);
+ postLifecycleEventIfRequired(entity, PersistingLifecycleEventFacet.class);
}
public void postPersist(ManagedObject entity) {
- notify(entity,
- postPersisted,
- e -> {
- eventBusService.post(PostStoreEvent.of(entity.getPojo()));
- CallbackFacet.callCallback(entity, PersistedCallbackFacet.class);
- postLifecycleEventIfRequired(entity, PersistedLifecycleEventFacet.class);
- });
+ eventBusService.post(PostStoreEvent.of(entity.getPojo()));
+ CallbackFacet.callCallback(entity, PersistedCallbackFacet.class);
+ postLifecycleEventIfRequired(entity, PersistedLifecycleEventFacet.class);
}
public void preUpdate(ManagedObject entity) {
- notify(entity,
- preUpdated,
- e -> {
- eventBusService.post(PreStoreEvent.of(entity.getPojo()));
- CallbackFacet.callCallback(entity, UpdatingCallbackFacet.class);
- postLifecycleEventIfRequired(entity, UpdatingLifecycleEventFacet.class);
- });
+ eventBusService.post(PreStoreEvent.of(entity.getPojo()));
+ CallbackFacet.callCallback(entity, UpdatingCallbackFacet.class);
+ postLifecycleEventIfRequired(entity, UpdatingLifecycleEventFacet.class);
}
public void postUpdate(ManagedObject entity) {
- notify(entity,
- postUpdated,
- e -> {
- CallbackFacet.callCallback(entity, UpdatedCallbackFacet.class);
- postLifecycleEventIfRequired(entity, UpdatedLifecycleEventFacet.class);
- });
+ CallbackFacet.callCallback(entity, UpdatedCallbackFacet.class);
+ postLifecycleEventIfRequired(entity, UpdatedLifecycleEventFacet.class);
}
public void preRemove(ManagedObject entity) {
- notify(entity,
- preRemoved,
- e -> {
- CallbackFacet.callCallback(entity, RemovingCallbackFacet.class);
- postLifecycleEventIfRequired(entity, RemovingLifecycleEventFacet.class);
- });
+ CallbackFacet.callCallback(entity, RemovingCallbackFacet.class);
+ postLifecycleEventIfRequired(entity, RemovingLifecycleEventFacet.class);
+ }
+
+
+ // -- HELPER
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ protected void postLifecycleEventIfRequired(
+ final ManagedObject adapter,
+ final Class<? extends LifecycleEventFacet> lifecycleEventFacetClass) {
+
+ val lifecycleEventFacet = adapter.getSpecification().getFacet(lifecycleEventFacetClass);
+ if(lifecycleEventFacet == null) {
+ return;
+ }
+ val eventInstance = (AbstractLifecycleEvent) _InstanceUtil
+ .createInstance(lifecycleEventFacet.getEventType());
+ val pojo = adapter.getPojo();
+ postEvent(eventInstance, pojo);
+
}
- private static void notify(ManagedObject entity, Set<ManagedObject> notified, Consumer<ManagedObject> notify) {
- Optional.of(entity)
- .filter(x -> !notified.contains(x))
- .ifPresent(x -> {
- notify.accept(entity);
- notified.add(x);
- });
+ protected void postEvent(final AbstractLifecycleEvent<Object> event, final Object pojo) {
+ if(eventBusService!=null) {
+ event.initSource(pojo);
+ eventBusService.post(event);
+ }
}
}
diff --git a/core/transaction/src/main/java/org/apache/isis/core/transaction/changetracking/PersistenceCallbackHandlerAbstract.java b/core/transaction/src/main/java/org/apache/isis/core/transaction/changetracking/PersistenceCallbackHandlerAbstract.java
deleted file mode 100644
index 88f17fcaa5..0000000000
--- a/core/transaction/src/main/java/org/apache/isis/core/transaction/changetracking/PersistenceCallbackHandlerAbstract.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.core.transaction.changetracking;
-
-import org.apache.isis.applib.events.lifecycle.AbstractLifecycleEvent;
-import org.apache.isis.applib.services.eventbus.EventBusService;
-import org.apache.isis.commons.internal.factory._InstanceUtil;
-import org.apache.isis.core.metamodel.facets.object.callbacks.LifecycleEventFacet;
-import org.apache.isis.core.metamodel.spec.ManagedObject;
-
-import lombok.AccessLevel;
-import lombok.RequiredArgsConstructor;
-import lombok.val;
-
-@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
-public abstract class PersistenceCallbackHandlerAbstract {
-
- protected final EventBusService eventBusService;
-
- // -- HELPER
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- protected void postLifecycleEventIfRequired(
- final ManagedObject adapter,
- final Class<? extends LifecycleEventFacet> lifecycleEventFacetClass) {
-
- val lifecycleEventFacet = adapter.getSpecification().getFacet(lifecycleEventFacetClass);
- if(lifecycleEventFacet == null) {
- return;
- }
- val eventInstance = (AbstractLifecycleEvent) _InstanceUtil
- .createInstance(lifecycleEventFacet.getEventType());
- val pojo = adapter.getPojo();
- postEvent(eventInstance, pojo);
-
- }
-
- protected void postEvent(final AbstractLifecycleEvent<Object> event, final Object pojo) {
- if(eventBusService!=null) {
- event.initSource(pojo);
- eventBusService.post(event);
- }
- }
-
-}
diff --git a/persistence/commons/src/main/java/org/apache/isis/persistence/jpa/integration/changetracking/EntityChangeTrackerDefault.java b/persistence/commons/src/main/java/org/apache/isis/persistence/jpa/integration/changetracking/EntityChangeTrackerDefault.java
index dbf8a49d21..8c9450a0c8 100644
--- a/persistence/commons/src/main/java/org/apache/isis/persistence/jpa/integration/changetracking/EntityChangeTrackerDefault.java
+++ b/persistence/commons/src/main/java/org/apache/isis/persistence/jpa/integration/changetracking/EntityChangeTrackerDefault.java
@@ -65,12 +65,12 @@ import org.apache.isis.core.transaction.changetracking.EntityChangeTracker;
import org.apache.isis.core.transaction.changetracking.EntityChangesPublisher;
import org.apache.isis.core.transaction.changetracking.EntityPropertyChangePublisher;
import org.apache.isis.core.transaction.changetracking.HasEnlistedEntityChanges;
-import org.apache.isis.core.transaction.changetracking.PersistenceCallbackHandlerAbstract;
import org.apache.isis.core.transaction.events.TransactionBeforeCompletionEvent;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
import lombok.val;
import lombok.extern.log4j.Log4j2;
@@ -82,9 +82,9 @@ import lombok.extern.log4j.Log4j2;
@Priority(PriorityPrecedence.EARLY)
@Qualifier("default")
@InteractionScope
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
@Log4j2
public class EntityChangeTrackerDefault
-extends PersistenceCallbackHandlerAbstract
implements
MetricsService,
EntityChangeTracker,
@@ -108,25 +108,13 @@ implements
@Getter(AccessLevel.PACKAGE)
private final Map<Bookmark, EntityChangeKind> changeKindByEnlistedAdapter = _Maps.newLinkedHashMap();
- private final EntityPropertyChangePublisher entityPropertyChangePublisher;
- private final EntityChangesPublisher entityChangesPublisher;
- private final Provider<InteractionProvider> interactionProviderProvider;
-
private final LongAdder numberEntitiesLoaded = new LongAdder();
private final LongAdder entityChangeEventCount = new LongAdder();
private final AtomicBoolean persistentChangesEncountered = new AtomicBoolean();
- @Inject
- public EntityChangeTrackerDefault(
- final EntityPropertyChangePublisher entityPropertyChangePublisher,
- final EntityChangesPublisher entityChangesPublisher,
- final EventBusService eventBusService,
- final Provider<InteractionProvider> interactionProviderProvider) {
- super(eventBusService);
- this.entityPropertyChangePublisher = entityPropertyChangePublisher;
- this.entityChangesPublisher = entityChangesPublisher;
- this.interactionProviderProvider = interactionProviderProvider;
- }
+ private final EntityPropertyChangePublisher entityPropertyChangePublisher;
+ private final EntityChangesPublisher entityChangesPublisher;
+ private final Provider<InteractionProvider> interactionProviderProvider;
Set<PropertyChangeRecord> snapshotPropertyChangeRecords() {
// this code path has side-effects, it locks the result for this transaction,
diff --git a/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingBadDomain.java b/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingBadDomain.java
index 5486678a75..09e698a575 100644
--- a/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingBadDomain.java
+++ b/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingBadDomain.java
@@ -46,6 +46,7 @@ import org.apache.isis.applib.annotation.Property;
import org.apache.isis.applib.annotation.PropertyLayout;
import org.apache.isis.applib.exceptions.unrecoverable.DomainModelException;
import org.apache.isis.applib.id.LogicalType;
+import org.apache.isis.applib.services.iactnlayer.InteractionService;
import org.apache.isis.commons.collections.Can;
import org.apache.isis.core.config.IsisConfiguration;
import org.apache.isis.core.config.environment.IsisSystemEnvironment;
@@ -91,6 +92,7 @@ import lombok.val;
class DomainModelTest_usingBadDomain {
@Inject private IsisConfiguration configuration;
+ @Inject private InteractionService interactionService;
@Inject private IsisSystemEnvironment isisSystemEnvironment;
@Inject private SpecificationLoader specificationLoader;
@Inject private DomainObjectTesterFactory testerFactory;
@@ -99,8 +101,10 @@ class DomainModelTest_usingBadDomain {
@BeforeEach
void setup() {
- validator = new DomainModelValidator(specificationLoader, configuration, isisSystemEnvironment);
- assertThrows(DomainModelException.class, validator::throwIfInvalid);
+ interactionService.runAnonymous(() -> {
+ validator = new DomainModelValidator(specificationLoader, configuration, isisSystemEnvironment);
+ assertThrows(DomainModelException.class, validator::throwIfInvalid);
+ });
}