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 2020/12/22 19:12:22 UTC
[isis] 04/04: ISIS-2033: remove ObjectAdapterContext (OMG YES!)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit e224d885a7b9e59e30cd6b2818ad735238b0d4e3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Dec 22 20:12:05 2020 +0100
ISIS-2033: remove ObjectAdapterContext (OMG YES!)
---
.../objectadapter/ObjectAdapterContext.java | 150 ---------------------
.../ObjectAdapterContext_NewIdentifier.java | 64 ---------
...ObjectAdapterContext_ObjectAdapterProvider.java | 65 ---------
.../objectadapter/ObjectAdapterProvider.java | 37 -----
.../persistence/IsisPersistenceSessionJdo.java | 3 +-
.../persistence/PersistenceSession.java | 8 ++
.../persistence/PersistenceSession5.java | 19 +--
.../jdo/integration/persistence/_Utils.java | 91 ++++++++++---
8 files changed, 89 insertions(+), 348 deletions(-)
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterContext.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterContext.java
deleted file mode 100644
index c793907..0000000
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterContext.java
+++ /dev/null
@@ -1,150 +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.objectadapter;
-
-import org.apache.isis.applib.services.inject.ServiceInjector;
-import org.apache.isis.commons.internal.exceptions._Exceptions;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.context.MetaModelContext;
-import org.apache.isis.core.metamodel.spec.ManagedObject;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
-import org.apache.isis.core.runtime.context.RuntimeContextBase;
-import org.apache.isis.persistence.jdo.integration.persistence.IsisPersistenceSessionJdo;
-
-import lombok.Getter;
-import lombok.NonNull;
-import lombok.val;
-import lombok.extern.log4j.Log4j2;
-
-/**
- * Encapsulate ObjectAdpater life-cycling.
- *
- * @since 2.0
- */
-@Log4j2
-final public class ObjectAdapterContext {
-
- public static ObjectAdapterContext openContext(
- MetaModelContext mmc,
- IsisPersistenceSessionJdo persistenceSession) {
-
- val objectAdapterContext =
- new ObjectAdapterContext(mmc, persistenceSession);
- objectAdapterContext.open();
- return objectAdapterContext;
- }
-
- private final IsisPersistenceSessionJdo persistenceSession;
- @Getter private final SpecificationLoader specificationLoader;
- private final ObjectAdapterContext_ObjectAdapterProvider objectAdapterProviderMixin;
- private final ObjectAdapterContext_NewIdentifier newIdentifierMixin;
- private final ServiceInjector serviceInjector;
-
- private ObjectAdapterContext(
- MetaModelContext mmc,
- IsisPersistenceSessionJdo persistenceSession) {
-
- val runtimeContext = new RuntimeContextBase(mmc) {};
-
- this.objectAdapterProviderMixin = new ObjectAdapterContext_ObjectAdapterProvider(this, runtimeContext);
- this.newIdentifierMixin = new ObjectAdapterContext_NewIdentifier(persistenceSession, runtimeContext.getSpecificationLoader());
-
- this.persistenceSession = persistenceSession;
- this.specificationLoader = mmc.getSpecificationLoader();
- this.serviceInjector = mmc.getServiceInjector();
- }
-
- // -- DEBUG
-
- void printContextInfo(String msg) {
- if(log.isDebugEnabled()) {
- String id = Integer.toHexString(this.hashCode());
- String session = ""+persistenceSession;
- log.debug(String.format("%s id=%s session='%s'", msg, id, session));
- }
- }
-
- // -- LIFE-CYCLING
-
- private void open() {
- printContextInfo("OPEN_");
- }
-
- public void close() {
- printContextInfo("CLOSE");
- }
-
- // -- NEW IDENTIFIER
-
- public RootOid createPersistentOrViewModelOid(Object pojo) {
- return newIdentifierMixin.createPersistentOid(pojo);
- }
-
- // -- ADAPTER MANAGER LEGACY
-
- public ManagedObject fetchPersistent(final Object pojo) {
- if (persistenceSession.getJdoPersistenceManager().getObjectId(pojo) == null) {
- return null;
- }
- final RootOid oid = createPersistentOrViewModelOid(pojo);
- final ManagedObject adapter = recreatePojo(oid, pojo);
- return adapter;
- }
-
- public ManagedObject recreatePojo(RootOid oid, Object recreatedPojo) {
-
- val spec = getSpecificationLoader().loadSpecification(recreatedPojo.getClass());
-
- final ManagedObject createdAdapter = createRootOrAggregatedAdapter(spec, oid, recreatedPojo);
- return injectServices(createdAdapter);
- }
-
- // package private
- ManagedObject injectServices(final @NonNull ManagedObject adapter) {
- val spec = adapter.getSpecification();
- if(spec==null
- || spec.isValue()) {
- return adapter; // guard against value objects
- }
- val pojo = adapter.getPojo();
- serviceInjector.injectServicesInto(pojo);
- return adapter;
- }
-
- private ManagedObject createRootOrAggregatedAdapter(
- final @NonNull ObjectSpecification spec,
- final RootOid oid,
- final Object pojo) {
-
- if(oid instanceof RootOid) {
- final RootOid rootOid = (RootOid) oid;
- return ManagedObject.identified(spec, pojo, rootOid);
- }
- throw _Exceptions.illegalArgument("Parented Oids are no longer supported, or cannot use Value Oid.");
- }
-
- // -- OBJECT ADAPTER PROVIDER SUPPORT
-
- public ObjectAdapterProvider getObjectAdapterProvider() {
- return objectAdapterProviderMixin;
- }
-
-
-}
\ No newline at end of file
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterContext_NewIdentifier.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterContext_NewIdentifier.java
deleted file mode 100644
index 1fc6b2b..0000000
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterContext_NewIdentifier.java
+++ /dev/null
@@ -1,64 +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.objectadapter;
-
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
-import org.apache.isis.persistence.jdo.integration.persistence.PersistenceSession;
-
-import lombok.RequiredArgsConstructor;
-
-/**
- * package private mixin for ObjectAdapterContext
- * <p>
- * Responsibility: creates RootOids
- * </p>
- * @since 2.0
- */
-@RequiredArgsConstructor
-class ObjectAdapterContext_NewIdentifier {
-
- private final PersistenceSession persistenceSession;
- private final SpecificationLoader specificationLoader;
-
- /**
- * Return an equivalent {@link RootOid}, but being persistent.
- *
- * <p>
- * It is the responsibility of the implementation to determine the new unique identifier.
- * For example, the generator may simply assign a new value from a sequence, or a GUID;
- * or, the generator may use the oid to look up the object and inspect the object in order
- * to obtain an application-defined value.
- *
- * @param pojo - being persisted
- */
- final RootOid createPersistentOid(Object pojo) {
-
- final ObjectSpecification spec = specificationLoader.loadSpecification(pojo.getClass());
-
- final String identifier = persistenceSession.identifierFor(pojo);
-
- final ObjectSpecId objectSpecId = spec.getSpecId();
- return Oid.Factory.root(objectSpecId, identifier);
- }
-
-}
\ No newline at end of file
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterContext_ObjectAdapterProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterContext_ObjectAdapterProvider.java
deleted file mode 100644
index 3eb8b0a..0000000
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterContext_ObjectAdapterProvider.java
+++ /dev/null
@@ -1,65 +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.objectadapter;
-
-import org.apache.isis.commons.internal.assertions._Assert;
-import org.apache.isis.core.metamodel.objectmanager.ObjectManager;
-import org.apache.isis.core.metamodel.spec.ManagedObject;
-import org.apache.isis.core.runtime.context.RuntimeContext;
-
-import lombok.val;
-
-/**
- * package private mixin for ObjectAdapterContext
- * <p>
- * Responsibility: provides ObjectAdapterProvider implementation
- * </p>
- * @since 2.0
- */
-class ObjectAdapterContext_ObjectAdapterProvider implements ObjectAdapterProvider {
-
- private final ObjectAdapterContext objectAdapterContext;
- private final ObjectManager objectManager;
-
- ObjectAdapterContext_ObjectAdapterProvider(
- ObjectAdapterContext objectAdapterContext,
- RuntimeContext runtimeContext) {
-
- this.objectAdapterContext = objectAdapterContext;
- this.objectManager = runtimeContext.getMetaModelContext().getObjectManager();
- }
-
- @Override
- public ManagedObject adapterFor(Object pojo) {
-
- if(pojo == null) {
- return null;
- }
-
- val adapter = objectManager.adapt(pojo);
- val rootOid = objectManager.identifyObject(adapter);
- //val newAdapter = PojoAdapter.of(pojo, rootOid, objectAdapterContext.getSpecificationLoader());
-
- _Assert.assertEquals(rootOid, adapter.getRootOid().orElse(null));
-
- return objectAdapterContext.injectServices(adapter);
- }
-
-
-}
\ No newline at end of file
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterProvider.java
deleted file mode 100644
index 71d9297..0000000
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/objectadapter/ObjectAdapterProvider.java
+++ /dev/null
@@ -1,37 +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.objectadapter;
-
-import javax.annotation.Nullable;
-
-import org.apache.isis.core.metamodel.spec.ManagedObject;
-
-/**
- *
- * @since 2.0
- *
- */
-public interface ObjectAdapterProvider {
-
- /**
- * @return standalone (value) or root adapter
- */
- @Nullable ManagedObject adapterFor(@Nullable Object pojo);
-
-}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/IsisPersistenceSessionJdo.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/IsisPersistenceSessionJdo.java
index b75e310..be12b30 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/IsisPersistenceSessionJdo.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/IsisPersistenceSessionJdo.java
@@ -20,7 +20,6 @@ package org.apache.isis.persistence.jdo.integration.persistence;
import java.util.List;
-import org.apache.isis.persistence.jdo.integration.objectadapter.ObjectAdapterProvider;
import org.apache.isis.persistence.jdo.integration.persistence.command.PersistenceCommand;
/**
@@ -28,7 +27,7 @@ import org.apache.isis.persistence.jdo.integration.persistence.command.Persisten
* @since 2.0
*/
public interface IsisPersistenceSessionJdo
-extends PersistenceSession, ObjectAdapterProvider {
+extends PersistenceSession {
void execute(List<PersistenceCommand> persistenceCommandList);
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/PersistenceSession.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/PersistenceSession.java
index c49890d..6e0c62b 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/PersistenceSession.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/PersistenceSession.java
@@ -21,10 +21,13 @@ package org.apache.isis.persistence.jdo.integration.persistence;
import java.rmi.NoSuchObjectException;
import java.util.Optional;
+import javax.annotation.Nullable;
+
import org.apache.isis.applib.query.Query;
import org.apache.isis.applib.services.repository.EntityState;
import org.apache.isis.applib.services.xactn.TransactionService;
import org.apache.isis.commons.collections.Can;
+import org.apache.isis.core.metamodel.context.MetaModelContext;
import org.apache.isis.core.metamodel.spec.ManagedObject;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
@@ -35,6 +38,7 @@ public interface PersistenceSession {
// -------------------------------------------------------------------------------------------------
TransactionService getTransactionService();
+ MetaModelContext getMetaModelContext();
void open();
void close();
@@ -43,6 +47,10 @@ public interface PersistenceSession {
getTransactionService().flushTransaction();
}
+ default ManagedObject adapterFor(@Nullable Object pojo) {
+ return _Utils.adapterFor(getMetaModelContext(), pojo);
+ }
+
/**
* Forces a reload (refresh in JDO terminology) of the domain object
*/
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/PersistenceSession5.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/PersistenceSession5.java
index 94874bf..b71fc03 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/PersistenceSession5.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/PersistenceSession5.java
@@ -50,7 +50,6 @@ import org.apache.isis.persistence.jdo.applib.exceptions.UnsupportedFindExceptio
import org.apache.isis.persistence.jdo.applib.fixturestate.FixturesInstalledStateHolder;
import org.apache.isis.persistence.jdo.integration.lifecycles.JdoStoreLifecycleListenerForIsis;
import org.apache.isis.persistence.jdo.integration.lifecycles.LoadLifecycleListenerForIsis;
-import org.apache.isis.persistence.jdo.integration.objectadapter.ObjectAdapterContext;
import org.apache.isis.persistence.jdo.integration.oid.JdoObjectIdSerializer;
import org.apache.isis.persistence.jdo.integration.persistence.command.CreateObjectCommand;
import org.apache.isis.persistence.jdo.integration.persistence.command.DestroyObjectCommand;
@@ -76,7 +75,6 @@ import lombok.extern.log4j.Log4j2;
public class PersistenceSession5 extends IsisPersistenceSessionJdoBase
implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
- private ObjectAdapterContext objectAdapterContext;
@Getter private final TransactionService transactionService;
private Runnable unregisterLifecycleListeners;
@@ -121,8 +119,6 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
PersistenceQueryFindUsingApplibQueryDefault.class,
new PersistenceQueryFindUsingApplibQueryProcessor(this));
- objectAdapterContext = ObjectAdapterContext.openContext(super.metaModelContext, this);
-
// install JDO specific entity change listeners ...
val loadLifecycleListener = new LoadLifecycleListenerForIsis();
@@ -174,8 +170,6 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
"close: failed to close JDO persistenceManager; continuing to avoid memory leakage");
}
- objectAdapterContext.close();
-
this.state = State.CLOSED;
}
@@ -575,8 +569,8 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
// // viewModel's #viewModelMemento might need to use services
// serviceInjector.injectServicesInto(pojo); //redundant
- final RootOid originalOid = objectAdapterContext.createPersistentOrViewModelOid(pojo);
- final ManagedObject entity = objectAdapterContext.recreatePojo(originalOid, pojo);
+ final RootOid originalOid = _Utils.createRootOid(getMetaModelContext(), this, pojo);
+ final ManagedObject entity = _Utils.recreatePojo(getMetaModelContext(), originalOid, pojo);
getEntityChangeTracker().recognizeLoaded(entity);
@@ -629,7 +623,7 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
@Override
public void enlistUpdatingAndInvokeIsisUpdatingCallback(final Persistable pojo) {
- val entity = objectAdapterContext.fetchPersistent(pojo);
+ val entity = _Utils.fetchPersistent(getMetaModelContext(), this, pojo);
if (entity == null) {
throw _Exceptions
.noSuchElement("DN could not find objectId for pojo (unexpected); pojo=[%s]", pojo);
@@ -639,7 +633,7 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
@Override
public void invokeIsisUpdatedCallback(Persistable pojo) {
- val entity = objectAdapterContext.fetchPersistent(pojo);
+ val entity = _Utils.fetchPersistent(getMetaModelContext(), this, pojo);
if (entity == null) {
throw _Exceptions
.noSuchElement("DN could not find objectId for pojo (unexpected); pojo=[%s]", pojo);
@@ -682,11 +676,6 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
}
return false;
}
-
- @Override
- public ManagedObject adapterFor(Object pojo) {
- return objectAdapterContext.getObjectAdapterProvider().adapterFor(pojo);
- }
// -- HELPER
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/_Utils.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/_Utils.java
index 549f6d0..dfb3878 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/_Utils.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/_Utils.java
@@ -23,31 +23,25 @@ import javax.jdo.listener.InstanceLifecycleEvent;
import org.datanucleus.enhancement.Persistable;
-import org.apache.isis.applib.services.inject.ServiceInjector;
+import org.apache.isis.commons.internal.exceptions._Exceptions;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.context.MetaModelContext;
import org.apache.isis.core.metamodel.spec.ManagedObject;
import org.apache.isis.core.metamodel.spec.ManagedObjects;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import lombok.NonNull;
import lombok.val;
final class _Utils {
- @SuppressWarnings("unused")
- private static Object jdoObjectIdFor(InstanceLifecycleEvent event) {
- Persistable persistenceCapable = _Utils.persistableFor(event);
- Object jdoObjectId = persistenceCapable.dnGetObjectId();
- return jdoObjectId;
- }
-
static Persistable persistableFor(InstanceLifecycleEvent event) {
return (Persistable)event.getSource();
}
static boolean ensureRootObject(final Persistable pojo) {
-// final Oid oid = adapterFor(pojo).getOid();
-// if (!(oid instanceof RootOid)) {
-// throw new IsisException(MessageFormat.format("Not a RootOid: oid={0}, for {1}", oid, pojo));
-// }
return pojo!=null; // why would a Persistable ever be something different?
}
@@ -60,11 +54,23 @@ final class _Utils {
return false;
}
- // -- LOW LEVEL
+ @Nullable
+ static ManagedObject adapterFor(
+ final MetaModelContext mmc,
+ final Object pojo) {
+
+ if(pojo == null) {
+ return null;
+ }
+
+ val objectManager = mmc.getObjectManager();
+ val adapter = objectManager.adapt(pojo);
+ return injectServices(mmc, adapter);
+ }
@Nullable
static ManagedObject injectServices(
- final @NonNull ServiceInjector serviceInjector,
+ final @NonNull MetaModelContext mmc,
final @Nullable ManagedObject adapter) {
if(ManagedObjects.isNullOrUnspecifiedOrEmpty(adapter)) {
@@ -76,8 +82,63 @@ final class _Utils {
|| spec.isValue()) {
return adapter; // guard against value objects
}
- serviceInjector.injectServicesInto(adapter.getPojo());
+ mmc.getServiceInjector().injectServicesInto(adapter.getPojo());
+ return adapter;
+ }
+
+ static RootOid createRootOid(
+ final @NonNull MetaModelContext mmc,
+ final @NonNull IsisPersistenceSessionJdo persistenceSession, // TODO don't depend on session
+ final @NonNull Object pojo) {
+
+ val spec = mmc.getSpecification(pojo.getClass());
+
+ final String identifier = persistenceSession.identifierFor(pojo);
+
+ final ObjectSpecId objectSpecId = spec.getSpecId();
+ return Oid.Factory.root(objectSpecId, identifier);
+ }
+
+ static ManagedObject recreatePojo(
+ final @NonNull MetaModelContext mmc,
+ final @NonNull RootOid oid,
+ final @NonNull Object recreatedPojo) {
+
+ val spec = mmc.getSpecification(recreatedPojo.getClass());
+
+ final ManagedObject createdAdapter = createRootOrAggregatedAdapter(spec, oid, recreatedPojo);
+ return injectServices(mmc, createdAdapter);
+ }
+
+ static ManagedObject fetchPersistent(
+ final @NonNull MetaModelContext mmc,
+ final @NonNull IsisPersistenceSessionJdo persistenceSession, // TODO don't depend on session
+ final Object pojo) {
+ if (persistenceSession.getJdoPersistenceManager().getObjectId(pojo) == null) {
+ return null;
+ }
+ final RootOid oid = createRootOid(mmc, persistenceSession, pojo);
+ final ManagedObject adapter = recreatePojo(mmc, oid, pojo);
return adapter;
}
+ private static ManagedObject createRootOrAggregatedAdapter(
+ final @NonNull ObjectSpecification spec,
+ final RootOid oid,
+ final Object pojo) {
+
+ if(oid instanceof RootOid) {
+ final RootOid rootOid = (RootOid) oid;
+ return ManagedObject.identified(spec, pojo, rootOid);
+ }
+ throw _Exceptions.illegalArgument("Parented Oids are no longer supported, or cannot use Value Oid.");
+ }
+
+// @SuppressWarnings("unused")
+// private static Object jdoObjectIdFor(InstanceLifecycleEvent event) {
+// final Persistable persistable = persistableFor(event);
+// final Object jdoObjectId = persistable.dnGetObjectId();
+// return jdoObjectId;
+// }
+
}