You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/01/07 09:59:31 UTC
[isis] branch 2033-Spring_Data_Integration updated: ISIS-2033:
further simplify
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch 2033-Spring_Data_Integration
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/2033-Spring_Data_Integration by this push:
new 6c445ea ISIS-2033: further simplify
6c445ea is described below
commit 6c445ea944743a47a2674459e3655be4cb1b8c72
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Jan 7 10:59:13 2021 +0100
ISIS-2033: further simplify
---
.../changetracking/JdoEntityChangeEmitter.java | 108 --------------------
.../changetracking/JdoFetchResultHandler.java | 52 ----------
.../changetracking/JdoLifecycleListener.java | 113 ++++++++++++---------
3 files changed, 64 insertions(+), 209 deletions(-)
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoEntityChangeEmitter.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoEntityChangeEmitter.java
deleted file mode 100644
index 1d421be..0000000
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoEntityChangeEmitter.java
+++ /dev/null
@@ -1,108 +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.persistence.jdo.integration.changetracking;
-
-import org.datanucleus.enhancement.Persistable;
-
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.context.MetaModelContext;
-import org.apache.isis.core.metamodel.spec.ManagedObject;
-import org.apache.isis.core.transaction.changetracking.EntityChangeTracker;
-import org.apache.isis.persistence.jdo.datanucleus.entities.DnEntityStateProvider;
-
-import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
-import lombok.val;
-
-@RequiredArgsConstructor
-public class JdoEntityChangeEmitter implements JdoLifecycleListener.EntityChangeEmitter {
-
- private final MetaModelContext metaModelContext;
- private final EntityChangeTracker entityChangeTracker;
-
- @Override
- public ManagedObject adaptEntityAndInjectServices(final @NonNull Persistable pojo) {
- return _Utils.adaptEntityAndInjectServices(metaModelContext, pojo);
- }
-
- @Override
- public void enlistDeletingAndInvokeIsisRemovingCallbackFacet(final Persistable pojo) {
- val entity = adaptEntityAndInjectServices(pojo);
- entityChangeTracker.enlistDeleting(entity);
- }
-
- /**
- * Called either when an entity is initially persisted, or when an entity is updated; fires the appropriate
- * lifecycle callback.
- *
- * <p>
- * The implementation therefore uses Isis' {@link Oid#isTransient() oid}
- * to determine which callback to fire.
- */
- @Override
- public void invokeIsisPersistingCallback(final Persistable pojo) {
- if (DnEntityStateProvider.entityState(pojo).isDetached()) {
- val entity = ManagedObject.of(
- metaModelContext.getSpecificationLoader()::loadSpecification,
- pojo);
-
- entityChangeTracker.recognizePersisting(entity);
-
- } else {
- // updating
-
- // don't call here, already called in preDirty.
-
- // CallbackFacet.Util.callCallback(adapter, UpdatingCallbackFacet.class);
- }
- }
-
- /**
- * Called either when an entity is initially persisted, or when an entity is updated;
- * fires the appropriate lifecycle callback
- *
- * <p>
- * The implementation therefore uses Isis' {@link Oid#isTransient() oid}
- * to determine which callback to fire.
- */
- @Override
- public void enlistCreatedAndInvokeIsisPersistedCallback(final Persistable pojo) {
- val entity = adaptEntityAndInjectServices(pojo);
- entityChangeTracker.enlistCreated(entity);
- }
-
- @Override
- public void enlistUpdatingAndInvokeIsisUpdatingCallback(final Persistable pojo) {
- val entity = ManagedObject.of(
- metaModelContext.getSpecificationLoader()::loadSpecification,
- pojo);
- entityChangeTracker.enlistUpdating(entity);
- }
-
- @Override
- public void invokeIsisUpdatedCallback(Persistable pojo) {
- val entity = ManagedObject.of(
- metaModelContext.getSpecificationLoader()::loadSpecification,
- pojo);
- // the callback and transaction.enlist are done in the preStore callback
- // (can't be done here, as the enlist requires to capture the 'before' values)
- entityChangeTracker.recognizeUpdating(entity);
- }
-
-}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoFetchResultHandler.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoFetchResultHandler.java
deleted file mode 100644
index a552b9c..0000000
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoFetchResultHandler.java
+++ /dev/null
@@ -1,52 +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.persistence.jdo.integration.changetracking;
-
-import javax.annotation.Nullable;
-import javax.jdo.PersistenceManager;
-
-import org.datanucleus.enhancement.Persistable;
-
-import org.apache.isis.core.metamodel.context.MetaModelContext;
-import org.apache.isis.core.metamodel.spec.ManagedObject;
-import org.apache.isis.core.transaction.changetracking.EntityChangeTracker;
-
-import lombok.RequiredArgsConstructor;
-
-@RequiredArgsConstructor
-public class JdoFetchResultHandler {
-
- private final MetaModelContext metaModelContext;
- private final PersistenceManager persistenceManager;
- private final EntityChangeTracker entityChangeTracker;
-
- public ManagedObject initializeEntityAfterFetched(final Persistable pojo) {
-
- final ManagedObject entity = _Utils
- .identify(metaModelContext, persistenceManager, pojo);
-
- entityChangeTracker.recognizeLoaded(entity);
-
- return entity;
- }
-
- public ManagedObject initializeValueAfterFetched(final @Nullable Object pojo) {
- return _Utils.adaptNullableAndInjectServices(metaModelContext, pojo);
- }
-}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoLifecycleListener.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoLifecycleListener.java
index 47fc0c6..69b8dfb 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoLifecycleListener.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/changetracking/JdoLifecycleListener.java
@@ -18,8 +18,6 @@
*/
package org.apache.isis.persistence.jdo.integration.changetracking;
-import java.util.Map;
-
import javax.enterprise.inject.Vetoed;
import javax.jdo.listener.AttachLifecycleListener;
import javax.jdo.listener.ClearLifecycleListener;
@@ -34,12 +32,13 @@ import javax.jdo.listener.StoreLifecycleListener;
import org.datanucleus.enhancement.Persistable;
import org.apache.isis.applib.services.eventbus.EventBusService;
-import org.apache.isis.commons.internal.collections._Maps;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
import org.apache.isis.core.metamodel.context.MetaModelContext;
import org.apache.isis.core.metamodel.spec.ManagedObject;
import org.apache.isis.core.transaction.changetracking.EntityChangeTracker;
import org.apache.isis.core.transaction.changetracking.events.PostStoreEvent;
import org.apache.isis.core.transaction.changetracking.events.PreStoreEvent;
+import org.apache.isis.persistence.jdo.datanucleus.entities.DnEntityStateProvider;
import org.apache.isis.persistence.jdo.integration.metamodel.JdoMetamodelUtil;
import lombok.Getter;
@@ -53,23 +52,6 @@ public class JdoLifecycleListener
implements AttachLifecycleListener, ClearLifecycleListener, CreateLifecycleListener, DeleteLifecycleListener,
DetachLifecycleListener, DirtyLifecycleListener, LoadLifecycleListener, StoreLifecycleListener {
- /**
- * The internal contract between PersistenceSession and this class.
- */
- public interface EntityChangeEmitter {
-
- ManagedObject adaptEntityAndInjectServices(Persistable pojo);
-
- void invokeIsisPersistingCallback(Persistable pojo);
- void enlistCreatedAndInvokeIsisPersistedCallback(Persistable pojo);
-
- void enlistUpdatingAndInvokeIsisUpdatingCallback(Persistable pojo);
- void invokeIsisUpdatedCallback(Persistable pojo);
-
- void enlistDeletingAndInvokeIsisRemovingCallbackFacet(Persistable pojo);
-
- }
-
private final @NonNull MetaModelContext metaModelContext;
private final @NonNull EventBusService eventBusService;
@@ -95,7 +77,7 @@ DetachLifecycleListener, DirtyLifecycleListener, LoadLifecycleListener, StoreLif
@Override
public void postLoad(final InstanceLifecycleEvent event) {
final Persistable pojo = _Utils.persistableFor(event);
- getEntityChangeEmitter().adaptEntityAndInjectServices(pojo);
+ adaptEntityAndInjectServices(pojo);
getEntityChangeTracker().incrementLoaded();
}
@@ -112,7 +94,7 @@ DetachLifecycleListener, DirtyLifecycleListener, LoadLifecycleListener, StoreLif
final Persistable pojo = _Utils.persistableFor(event);
if(pojo.dnGetStateManager().isNew(pojo)) {
- getEntityChangeEmitter().invokeIsisPersistingCallback(pojo);
+ invokeIsisPersistingCallback(pojo);
}
}
@@ -130,9 +112,9 @@ DetachLifecycleListener, DirtyLifecycleListener, LoadLifecycleListener, StoreLif
final Persistable pojo = _Utils.persistableFor(event);
if(pojo.dnGetStateManager().isNew(pojo)) {
- getEntityChangeEmitter().enlistCreatedAndInvokeIsisPersistedCallback(pojo);
+ enlistCreatedAndInvokeIsisPersistedCallback(pojo);
} else {
- getEntityChangeEmitter().invokeIsisUpdatedCallback(pojo);
+ invokeIsisUpdatedCallback(pojo);
}
}
@@ -141,7 +123,7 @@ DetachLifecycleListener, DirtyLifecycleListener, LoadLifecycleListener, StoreLif
@Override
public void preDirty(InstanceLifecycleEvent event) {
final Persistable pojo = _Utils.persistableFor(event);
- getEntityChangeEmitter().enlistUpdatingAndInvokeIsisUpdatingCallback(pojo);
+ enlistUpdatingAndInvokeIsisUpdatingCallback(pojo);
}
@Override
@@ -157,7 +139,7 @@ DetachLifecycleListener, DirtyLifecycleListener, LoadLifecycleListener, StoreLif
@Override
public void preDelete(InstanceLifecycleEvent event) {
final Persistable pojo = _Utils.persistableFor(event);
- getEntityChangeEmitter().enlistDeletingAndInvokeIsisRemovingCallbackFacet(pojo);
+ enlistDeletingAndInvokeIsisRemovingCallbackFacet(pojo);
}
@Override
@@ -196,42 +178,75 @@ DetachLifecycleListener, DirtyLifecycleListener, LoadLifecycleListener, StoreLif
public void postDetach(InstanceLifecycleEvent event) {
// no-op
}
+
+ // -- HELPER
+
+ private ManagedObject adaptEntityAndInjectServices(final @NonNull Persistable pojo) {
+ return _Utils.adaptEntityAndInjectServices(metaModelContext, pojo);
+ }
- // /////////////////////////////////////////////////////////
- // Logging
- // /////////////////////////////////////////////////////////
+ private void enlistDeletingAndInvokeIsisRemovingCallbackFacet(final Persistable pojo) {
+ val entity = adaptEntityAndInjectServices(pojo);
+ getEntityChangeTracker().enlistDeleting(entity);
+ }
- // private enum Phase {
- // PRE, POST
- // }
+ /**
+ * Called either when an entity is initially persisted, or when an entity is updated; fires the appropriate
+ * lifecycle callback.
+ *
+ * <p>
+ * The implementation therefore uses Isis' {@link Oid#isTransient() oid}
+ * to determine which callback to fire.
+ */
+ private void invokeIsisPersistingCallback(final Persistable pojo) {
+ if (DnEntityStateProvider.entityState(pojo).isDetached()) {
+ val entity = ManagedObject.of(
+ metaModelContext.getSpecificationLoader()::loadSpecification,
+ pojo);
- private static Map<Integer, LifecycleEventType> events = _Maps.newHashMap();
+ getEntityChangeTracker().recognizePersisting(entity);
- private enum LifecycleEventType {
- CREATE(0), LOAD(1), STORE(2), CLEAR(3), DELETE(4), DIRTY(5), DETACH(6), ATTACH(7);
+ } else {
+ // updating
- private LifecycleEventType(int code) {
- events.put(code, this);
+ // don't call here, already called in preDirty.
+
+ // CallbackFacet.Util.callCallback(adapter, UpdatingCallbackFacet.class);
}
+ }
- // public static LifecycleEventType lookup(int code) {
- // return events.get(code);
- // }
+ /**
+ * Called either when an entity is initially persisted, or when an entity is updated;
+ * fires the appropriate lifecycle callback
+ *
+ * <p>
+ * The implementation therefore uses Isis' {@link Oid#isTransient() oid}
+ * to determine which callback to fire.
+ */
+ private void enlistCreatedAndInvokeIsisPersistedCallback(final Persistable pojo) {
+ val entity = adaptEntityAndInjectServices(pojo);
+ getEntityChangeTracker().enlistCreated(entity);
+ }
+
+ private void enlistUpdatingAndInvokeIsisUpdatingCallback(final Persistable pojo) {
+ val entity = ManagedObject.of(
+ metaModelContext.getSpecificationLoader()::loadSpecification,
+ pojo);
+ getEntityChangeTracker().enlistUpdating(entity);
}
- // private String logString(Phase phase, LoggingLocation location, InstanceLifecycleEvent event) {
- // final Persistable pojo = Utils.persistenceCapableFor(event);
- // final ObjectAdapter adapter = persistenceSession.getAdapterFor(pojo);
- // return phase + " " + location.prefix + " " + LifecycleEventType.lookup(event.getEventType()) + ": oid=" + (adapter !=null? adapter.getOid(): "(null)") + " ,pojo " + pojo;
- // }
+ private void invokeIsisUpdatedCallback(Persistable pojo) {
+ val entity = ManagedObject.of(
+ metaModelContext.getSpecificationLoader()::loadSpecification,
+ pojo);
+ // the callback and transaction.enlist are done in the preStore callback
+ // (can't be done here, as the enlist requires to capture the 'before' values)
+ getEntityChangeTracker().recognizeUpdating(entity);
+ }
// -- DEPENDENCIES
@Getter(lazy = true)
- private final EntityChangeEmitter entityChangeEmitter =
- new JdoEntityChangeEmitter(metaModelContext, getEntityChangeTracker());
-
- @Getter(lazy = true)
private final EntityChangeTracker entityChangeTracker =
metaModelContext.getServiceRegistry()
.lookupServiceElseFail(EntityChangeTracker.class);