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 2018/09/10 04:43:58 UTC
[isis] 01/02: ISIS-1976: cleanup unreachable code paths
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch ISIS-1976-rethink-object-adapters
in repository https://gitbox.apache.org/repos/asf/isis.git
commit fe0c9c5f43677a102bc139b0abdbd3a6f9a4cd4a
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun Sep 9 07:38:14 2018 +0200
ISIS-1976: cleanup unreachable code paths
Task-Url: https://issues.apache.org/jira/browse/ISIS-1976
---
.../adaptermanager/ObjectAdapterContext.java | 20 +------
.../ObjectAdapterContext_Factories.java | 5 --
.../ObjectAdapterContext_NewIdentifier.java | 70 ++++------------------
.../adaptermanager/OidAdapterHashMap.java | 4 +-
.../persistence/adaptermanager/OidProviders.java | 18 ++++++
5 files changed, 34 insertions(+), 83 deletions(-)
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
index c43ec56..6f5df49 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
@@ -223,12 +223,8 @@ public class ObjectAdapterContext {
// -- NEW IDENTIFIER
- RootOid createTransientOrViewModelOid(final Object pojo) {
- return newIdentifierMixin.createTransientOrViewModelOid(pojo);
- }
-
public RootOid createPersistentOrViewModelOid(Object pojo) {
- return newIdentifierMixin.createPersistentOrViewModelOid(pojo);
+ return newIdentifierMixin.createPersistentOid(pojo);
}
// -- SERVICE LOOKUP
@@ -251,20 +247,6 @@ public class ObjectAdapterContext {
*/
ObjectAdapter createRootAdapter(Object pojo, RootOid rootOid);
- /**
- * Creates a {@link ObjectAdapter adapter} with no {@link Oid}.
- *
- * <p>
- * Standalone adapters are never {@link #mapAndInjectServices(ObjectAdapter) mapped}
- * (they have no {@link Oid}, after all).
- *
- * <p>
- * Should only be called if the pojo is known not to be
- * {@link #lookupAdapterFor(Object) mapped}, and for immutable value types
- * referenced.
- */
- ObjectAdapter createStandaloneAdapter(Object pojo);
-
ObjectAdapter createCollectionAdapter(Object pojo, ParentedCollectionOid collectionOid);
/**
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_Factories.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_Factories.java
index e1d77db..e488aba 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_Factories.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_Factories.java
@@ -53,11 +53,6 @@ class ObjectAdapterContext_Factories implements ObjectAdapterFactories {
}
@Override
- public ObjectAdapter createStandaloneAdapter(final Object pojo) {
- return createAdapter(pojo, null);
- }
-
- @Override
public ObjectAdapter createRootAdapter(final Object pojo, RootOid rootOid) {
assert rootOid != null;
return createAdapter(pojo, rootOid);
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_NewIdentifier.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_NewIdentifier.java
index 5199d79..5aad3c1 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_NewIdentifier.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext_NewIdentifier.java
@@ -57,25 +57,6 @@ class ObjectAdapterContext_NewIdentifier {
this.specificationLoader = servicesInjector.getSpecificationLoader();
}
-// RootOid rootOidFor(Object pojo) {
-// final RootOid rootOid = servicesInjector.isRegisteredServiceInstance(pojo)
-// ? createPersistentOrViewModelOid(pojo)
-// : createTransientOrViewModelOid(pojo);
-//
-//
-// return rootOid;
-// }
-
-
- // -- create...Oid (main API)
- /**
- * Create a new {@link Oid#isTransient() transient} {@link Oid} for the
- * supplied pojo, uniquely distinguishable from any other {@link Oid}.
- */
- final RootOid createTransientOrViewModelOid(final Object pojo) {
- return newIdentifier(pojo, Oid.State.TRANSIENT);
- }
-
/**
* Return an equivalent {@link RootOid}, but being persistent.
*
@@ -87,46 +68,21 @@ class ObjectAdapterContext_NewIdentifier {
*
* @param pojo - being persisted
*/
- final RootOid createPersistentOrViewModelOid(Object pojo) {
- return newIdentifier(pojo, Oid.State.PERSISTENT);
- }
-
- RootOid newIdentifier(final Object pojo, final Oid.State type) {
- final ObjectSpecification spec = objectSpecFor(pojo);
- //FIXME[ISIS-1976] remove guard
- if(spec.isService()) {
- //_Exceptions.throwUnexpectedCodeReach();
- return newRootId(spec, PersistenceSession.SERVICE_IDENTIFIER, Oid.State.PERSISTENT); // services are always persistent
- }
-
+ final RootOid createPersistentOid(Object pojo) {
+ final Oid.State type = Oid.State.PERSISTENT;
+
+ final ObjectSpecification spec = specificationLoader.loadSpecification(pojo.getClass());
+
+ //FIXME[ISIS-1976] remove guard
final ViewModelFacet recreatableObjectFacet = spec.getFacet(ViewModelFacet.class);
- final String identifier =
- recreatableObjectFacet != null
- ? recreatableObjectFacet.memento(pojo)
- : persistenceSession.identifierFor(pojo, type);
-
- return newRootId(spec, identifier, type);
- }
-
-
- private RootOid newRootId(final ObjectSpecification spec, final String identifier, final Oid.State type) {
- final Oid.State state =
- spec.containsDoOpFacet(ViewModelFacet.class)
- ? Oid.State.VIEWMODEL
- : type == Oid.State.TRANSIENT
- ? Oid.State.TRANSIENT
- : Oid.State.PERSISTENT;
+ if(spec.isService() || recreatableObjectFacet!=null || spec.containsDoOpFacet(ViewModelFacet.class)) {
+ _Exceptions.throwUnexpectedCodeReach();
+ }
+
+ final String identifier = persistenceSession.identifierFor(pojo, type);
+
final ObjectSpecId objectSpecId = spec.getSpecId();
- return new RootOid(objectSpecId, identifier, state);
+ return new RootOid(objectSpecId, identifier, type);
}
- // -- HELPER
-
- private ObjectSpecification objectSpecFor(final Object pojo) {
- final Class<?> pojoClass = pojo.getClass();
- return specificationLoader.loadSpecification(pojoClass);
- }
-
-
-
}
\ No newline at end of file
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidAdapterHashMap.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidAdapterHashMap.java
index ea99b7b..928ea05 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidAdapterHashMap.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidAdapterHashMap.java
@@ -65,7 +65,7 @@ class OidAdapterHashMap implements Iterable<Oid>, SessionScopedComponent {
* Add an adapter for a given oid
*/
public void add(@Nullable final Oid oid, final ObjectAdapter adapter) {
- if(oid==null) { // eg. value objects don't have an Oid
+ if(oid.isValue()) { // not stored for value
return;
}
adapterByOidMap.put(oid, adapter);
@@ -85,7 +85,7 @@ class OidAdapterHashMap implements Iterable<Oid>, SessionScopedComponent {
* @return <tt>true</tt> if an adapter was removed.
*/
public boolean remove(@Nullable final Oid oid) {
- if(oid==null) { // eg. value objects don't have an Oid
+ if(oid.isValue()) { // not stored for value
return false;
}
LOG.debug("remove oid: {}", oid);
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidProviders.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidProviders.java
index afcd193..63cce83 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidProviders.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidProviders.java
@@ -1,3 +1,21 @@
+/*
+ * 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.runtime.system.persistence.adaptermanager;
import org.apache.isis.core.metamodel.IsisJdoMetamodelPlugin;