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 2012/12/06 11:10:36 UTC
[36/51] [partial] ISIS-188: moving modules into core
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoAdapterHashMap.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoAdapterHashMap.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoAdapterHashMap.java
new file mode 100644
index 0000000..8fda6e9
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoAdapterHashMap.java
@@ -0,0 +1,184 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.adaptermanager;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.apache.commons.collections.map.IdentityMap;
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.commons.components.Resettable;
+import org.apache.isis.core.commons.components.SessionScopedComponent;
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.debug.DebuggableWithTitle;
+import org.apache.isis.core.commons.lang.ToString;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+
+/**
+ * TODO: an alternative might be to use {@link IdentityMap}.
+ */
+public class PojoAdapterHashMap implements DebuggableWithTitle, Iterable<ObjectAdapter>, SessionScopedComponent, Resettable {
+
+ private static class IdentityHashKey {
+ private final Object pojo;
+
+ public IdentityHashKey(final Object pojo) {
+ this.pojo = pojo;
+ }
+
+ @Override
+ public int hashCode() {
+ return System.identityHashCode(pojo);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return obj == this || (obj instanceof IdentityHashKey && ((IdentityHashKey) obj).pojo == pojo);
+ }
+ }
+
+ private static final Logger LOG = Logger.getLogger(PojoAdapterHashMap.class);
+ public static final int DEFAULT_POJO_ADAPTER_MAP_SIZE = OidAdapterHashMap.DEFAULT_OID_ADAPTER_MAP_SIZE;
+
+ protected final Map<Object, ObjectAdapter> adapterByPojoMap;
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // Constructors, finalize
+ // ///////////////////////////////////////////////////////////////////////////
+
+ public PojoAdapterHashMap() {
+ this(DEFAULT_POJO_ADAPTER_MAP_SIZE);
+ }
+
+ public PojoAdapterHashMap(final int capacity) {
+ adapterByPojoMap = Maps.newHashMapWithExpectedSize(capacity);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ LOG.debug("finalizing hash of pojos");
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // open, close
+ // ///////////////////////////////////////////////////////////////////////////
+
+ @Override
+ public void open() {
+ // nothing to do
+ }
+
+ @Override
+ public void close() {
+ LOG.debug("close");
+ adapterByPojoMap.clear();
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // reset
+ // ///////////////////////////////////////////////////////////////////////////
+
+ @Override
+ public void reset() {
+ LOG.debug("reset");
+ for (final Iterator<Map.Entry<Object, ObjectAdapter>> iterator = adapterByPojoMap.entrySet().iterator(); iterator.hasNext();) {
+ final Map.Entry<Object, ObjectAdapter> entry = iterator.next();
+ final ObjectAdapter adapter = entry.getValue();
+ if (!adapter.getSpecification().isService()) {
+ iterator.remove();
+ }
+ }
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // add, remove
+ // ///////////////////////////////////////////////////////////////////////////
+
+ public void add(final Object pojo, final ObjectAdapter adapter) {
+ adapterByPojoMap.put(key(pojo), adapter);
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("add adapter: #" + Long.toHexString(pojo.hashCode()) + " -> #" + Long.toHexString(adapter.hashCode()));
+ }
+ // log at end so that if toString needs adapters they're in maps.
+ if (adapter.isResolved()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("add " + new ToString(pojo) + " as " + adapter);
+ }
+ }
+ }
+
+ public void remove(final ObjectAdapter object) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("remove adapter: " + object);
+ }
+ adapterByPojoMap.remove(key(object.getObject()));
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // get, contains
+ // ///////////////////////////////////////////////////////////////////////////
+
+ public boolean containsPojo(final Object pojo) {
+ return adapterByPojoMap.containsKey(key(pojo));
+ }
+
+ public ObjectAdapter getAdapter(final Object pojo) {
+ return adapterByPojoMap.get(key(pojo));
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // elements
+ // ///////////////////////////////////////////////////////////////////////////
+
+ @Override
+ public Iterator<ObjectAdapter> iterator() {
+ return adapterByPojoMap.values().iterator();
+ }
+
+ private Object key(final Object pojo) {
+ return new IdentityHashKey(pojo);
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // Debugging
+ // ///////////////////////////////////////////////////////////////////////////
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ int count = 0;
+ for (final Object pojo : adapterByPojoMap.keySet()) {
+ final ObjectAdapter object = adapterByPojoMap.get(pojo);
+ debug.append(count++ + 1, 5);
+ debug.append(" '");
+ debug.append(pojo.toString(), 50);
+ debug.append("' ");
+ debug.appendln(object.toString());
+ }
+ }
+
+ @Override
+ public String debugTitle() {
+ return "POJO Adapter Hashtable";
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoRecreator.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoRecreator.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoRecreator.java
new file mode 100644
index 0000000..1ca876f
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoRecreator.java
@@ -0,0 +1,40 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.adaptermanager;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+
+public interface PojoRecreator {
+
+ Object recreatePojo(final TypedOid oid);
+
+ /**
+ * Return an adapter, if possible, for a pojo that was instantiated by the
+ * object store as a result of lazily loading, but which hasn't yet been seen
+ * by the Isis framework.
+ *
+ * <p>
+ * For example, in the case of JDO object store, downcast to <tt>PersistenceCapable</tt>
+ * and 'look inside' its state.
+ */
+
+ ObjectAdapter lazilyLoaded(Object pojo);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoRecreatorDefault.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoRecreatorDefault.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoRecreatorDefault.java
new file mode 100644
index 0000000..6eb7f82
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/PojoRecreatorDefault.java
@@ -0,0 +1,48 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.adaptermanager;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+
+public class PojoRecreatorDefault implements PojoRecreator {
+
+ public Object recreatePojo(final TypedOid oid) {
+ final ObjectSpecification spec = getSpecificationLoader().lookupBySpecId(oid.getObjectSpecId());
+ return spec.createObject();
+ }
+
+
+ protected SpecificationLoaderSpi getSpecificationLoader() {
+ return IsisContext.getSpecificationLoader();
+ }
+
+
+ /**
+ * Default implementation simply returns <tt>null</tt>.
+ */
+ @Override
+ public ObjectAdapter lazilyLoaded(Object pojo) {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/RootAndCollectionAdapters.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/RootAndCollectionAdapters.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/RootAndCollectionAdapters.java
new file mode 100644
index 0000000..64b4f73
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/RootAndCollectionAdapters.java
@@ -0,0 +1,121 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.adaptermanager;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import com.google.common.collect.Maps;
+
+import org.apache.isis.core.commons.ensure.Assert;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.CollectionOid;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+
+/**
+ * A root {@link ObjectAdapter adapter} along with aggregated {@link ObjectAdapter adapters}
+ * for any of its {@link OneToManyAssociation collection}s that are currently present in
+ * the {@link AdapterManager map}s.
+ *
+ * <p>
+ * Used for "impact analysis" when persisting transient root objects; all aggregated adapters
+ * must also be persisted.
+ */
+public class RootAndCollectionAdapters implements Iterable<ObjectAdapter> {
+
+ private final ObjectAdapter parentAdapter;
+ private final Oid rootAdapterOid;
+
+ private final Map<OneToManyAssociation, ObjectAdapter> collectionAdapters = Maps.newLinkedHashMap();
+
+ public RootAndCollectionAdapters(ObjectAdapter parentAdapter, AdapterManager objectAdapterLookup) {
+ Assert.assertNotNull(parentAdapter);
+ final Oid oid = parentAdapter.getOid();
+ this.parentAdapter = parentAdapter;
+ this.rootAdapterOid = (RootOid) oid;
+ addCollectionAdapters(objectAdapterLookup);
+ }
+
+ public ObjectAdapter getRootAdapter() {
+ return parentAdapter;
+ }
+
+ /**
+ * Iterate over the
+ * {@link #addCollectionAdapter(OneToManyAssociation, ObjectAdapter)
+ * collection adapter}s (does not include the {@link #getRootAdapter() root
+ * adapter}.
+ */
+ @Override
+ public Iterator<ObjectAdapter> iterator() {
+ return getCollectionAdapters().values().iterator();
+ }
+
+ /**
+ * Which collections are present?
+ * @return
+ */
+ public Set<OneToManyAssociation> getCollections() {
+ return getCollectionAdapters().keySet();
+ }
+
+ /**
+ * Corresponding adapter for each collection (values).
+ *
+ * @see #getCollections()
+ */
+ public ObjectAdapter getCollectionAdapter(final OneToManyAssociation otma) {
+ return collectionAdapters.get(otma);
+ }
+
+
+ ////////////////////////////////////////////////////////////////////////
+ // Helpers
+ ////////////////////////////////////////////////////////////////////////
+
+ private void addCollectionAdapters(AdapterManager objectAdapterLookup) {
+ for (final OneToManyAssociation otma : parentAdapter.getSpecification().getCollections()) {
+ final CollectionOid collectionOid = new CollectionOid((TypedOid) rootAdapterOid, otma);
+ final ObjectAdapter collectionAdapter = objectAdapterLookup.getAdapterFor(collectionOid);
+ if (collectionAdapter != null) {
+ // collection adapters are lazily created and so there may not be one.
+ addCollectionAdapter(otma, collectionAdapter);
+ }
+ }
+ }
+
+ private void addCollectionAdapter(final OneToManyAssociation otma, final ObjectAdapter collectionAdapter) {
+ Assert.assertNotNull(otma);
+ Assert.assertNotNull(collectionAdapter);
+ collectionAdapters.put(otma, collectionAdapter);
+ }
+
+ private Map<OneToManyAssociation, ObjectAdapter> getCollectionAdapters() {
+ return Collections.unmodifiableMap(collectionAdapters);
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/container/DomainObjectContainerObjectChanged.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/container/DomainObjectContainerObjectChanged.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/container/DomainObjectContainerObjectChanged.java
new file mode 100644
index 0000000..2944eba
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/container/DomainObjectContainerObjectChanged.java
@@ -0,0 +1,71 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.container;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManagerSpi;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+
+/**
+ * Helper class that encapsulates the processing performed by domain object
+ * containers that are performing an objectChanged.
+ *
+ * <p>
+ * Implementation note: rather than inject in its dependencies, we instead look
+ * up dependencies from the {@link IsisContext}. This is necessary, for the
+ * {@link PersistenceSession} at least, because class enhancers may hold a
+ * reference to the factory as part of the generated bytecode. Since the
+ * {@link PersistenceSession} could change over the lifetime of the instance (eg
+ * when using the {@link InMemoryObjectStore}), we must always look the
+ * {@link PersistenceSession} from the {@link IsisContext}. The same applies to
+ * the {@link ServicesInjectorSpi}.
+ */
+public class DomainObjectContainerObjectChanged {
+
+ public DomainObjectContainerObjectChanged() {
+ }
+
+ public void objectChanged(final Object object) {
+ if (object != null) {
+ final ObjectAdapter adapter = adapterFor(object);
+ getPersistenceSession().objectChanged(adapter);
+ }
+ }
+
+ private ObjectAdapter adapterFor(final Object object) {
+ return getAdapterManager().adapterFor(object);
+ }
+
+ // /////////////////////////////////////////////////////////////////
+ // Dependencies (looked up from context)
+ // /////////////////////////////////////////////////////////////////
+
+ protected PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+ protected AdapterManager getAdapterManager() {
+ return getPersistenceSession().getAdapterManager();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/container/DomainObjectContainerResolve.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/container/DomainObjectContainerResolve.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/container/DomainObjectContainerResolve.java
new file mode 100644
index 0000000..764cdb8
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/container/DomainObjectContainerResolve.java
@@ -0,0 +1,115 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.container;
+
+import org.apache.isis.applib.bookmarks.Bookmark;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManagerSpi;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+
+/**
+ * Helper class that encapsulates the processing performed by domain object
+ * containers that are performing a resolve.
+ *
+ * <p>
+ * Implementation note: rather than inject in its dependencies, we instead look
+ * up dependencies from the {@link IsisContext}. This is necessary, for the
+ * {@link PersistenceSession} at least, because class enhancers may hold a
+ * reference to the factory as part of the generated bytecode. Since the
+ * {@link PersistenceSession} could change over the lifetime of the instance (eg
+ * when using the {@link InMemoryObjectStore}), we must always look the
+ * {@link PersistenceSession} from the {@link IsisContext}. The same applies to
+ * the {@link ServicesInjectorSpi}.
+ */
+public class DomainObjectContainerResolve {
+
+ public DomainObjectContainerResolve() {
+ }
+
+ public Object lookup(final Bookmark bookmark) {
+ RootOid oid = RootOidDefault.create(bookmark);
+ final ObjectAdapter adapter = adapterFor(oid);
+ if(adapter == null) {
+ return null;
+ }
+ if (adapter.canTransitionToResolving()) {
+ getPersistenceSession().resolveImmediately(adapter);
+ }
+ return adapter.getObject();
+ }
+
+ public Bookmark bookmarkFor(Object domainObject) {
+ final ObjectAdapter adapter = adapterFor(domainObject);
+ final Oid oid = adapter.getOid();
+ if(oid == null) {
+ // values cannot be bookmarked
+ return null;
+ }
+ if(!(oid instanceof RootOid)) {
+ // must be root
+ return null;
+ }
+ final RootOid rootOid = (RootOid) oid;
+ return rootOid.asBookmark();
+ }
+
+ public void resolve(final Object parent) {
+ final ObjectAdapter adapter = adapterFor(parent);
+ if (adapter.canTransitionToResolving()) {
+ getPersistenceSession().resolveImmediately(adapter);
+ }
+ }
+
+ public void resolve(final Object parent, final Object field) {
+ if (field == null) {
+ resolve(parent);
+ }
+ }
+
+ private ObjectAdapter adapterFor(final Object object) {
+ return getAdapterManager().adapterFor(object);
+ }
+
+ private ObjectAdapter adapterFor(final RootOid oid) {
+ return getAdapterManager().adapterFor(oid);
+ }
+
+ // /////////////////////////////////////////////////////////////////
+ // Dependencies (looked up from context)
+ // /////////////////////////////////////////////////////////////////
+
+ protected PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+ protected AdapterManager getAdapterManager() {
+ return getPersistenceSession().getAdapterManager();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/internal/RuntimeContextFromSession.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/internal/RuntimeContextFromSession.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/internal/RuntimeContextFromSession.java
new file mode 100644
index 0000000..dedeba4
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/internal/RuntimeContextFromSession.java
@@ -0,0 +1,385 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.internal;
+
+import java.util.List;
+
+import org.apache.isis.applib.ApplicationException;
+import org.apache.isis.applib.bookmarks.Bookmark;
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.applib.query.Query;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
+import org.apache.isis.core.commons.authentication.AuthenticationSessionProviderAbstract;
+import org.apache.isis.core.metamodel.adapter.DomainObjectServices;
+import org.apache.isis.core.metamodel.adapter.DomainObjectServicesAbstract;
+import org.apache.isis.core.metamodel.adapter.LocalizationProviderAbstract;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ObjectDirtier;
+import org.apache.isis.core.metamodel.adapter.ObjectDirtierAbstract;
+import org.apache.isis.core.metamodel.adapter.ObjectPersistor;
+import org.apache.isis.core.metamodel.adapter.ObjectPersistorAbstract;
+import org.apache.isis.core.metamodel.adapter.QuerySubmitter;
+import org.apache.isis.core.metamodel.adapter.QuerySubmitterAbstract;
+import org.apache.isis.core.metamodel.adapter.ServicesProvider;
+import org.apache.isis.core.metamodel.adapter.ServicesProviderAbstract;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.deployment.DeploymentCategory;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacetUtils;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContextAbstract;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjectorAware;
+import org.apache.isis.core.metamodel.services.container.query.QueryCardinality;
+import org.apache.isis.core.metamodel.spec.ObjectInstantiationException;
+import org.apache.isis.core.metamodel.spec.ObjectInstantiator;
+import org.apache.isis.core.metamodel.spec.ObjectInstantiatorAbstract;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.runtimes.dflt.runtime.persistence.container.DomainObjectContainerObjectChanged;
+import org.apache.isis.runtimes.dflt.runtime.persistence.container.DomainObjectContainerResolve;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManagerSpi;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.runtime.system.session.IsisSession;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransactionManager;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.MessageBroker;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.UpdateNotifier;
+
+/**
+ * Provides services to the metamodel based on the currently running
+ * {@link IsisSession session} (primarily the {@link PersistenceSession}).
+ */
+public class RuntimeContextFromSession extends RuntimeContextAbstract {
+
+ private final AuthenticationSessionProvider authenticationSessionProvider;
+ private final AdapterManager adapterManager;
+ private final ObjectDirtier objectDirtier;
+ private final ObjectInstantiator objectInstantiator;
+ private final ObjectPersistor objectPersistor;
+ private final ServicesProvider servicesProvider;
+ private final ServicesInjector servicesInjector;
+ private final QuerySubmitter querySubmitter;
+ private final DomainObjectServices domainObjectServices;
+ private final LocalizationProviderAbstract localizationProvider;
+
+ // //////////////////////////////////////////////////////////////////
+ // Constructor
+ // //////////////////////////////////////////////////////////////////
+
+ public RuntimeContextFromSession() {
+ this.authenticationSessionProvider = new AuthenticationSessionProviderAbstract() {
+
+ @Override
+ public AuthenticationSession getAuthenticationSession() {
+ return IsisContext.getAuthenticationSession();
+ }
+ };
+ this.adapterManager = new AdapterManager() {
+
+ @Override
+ public ObjectAdapter getAdapterFor(Oid oid) {
+ return null;
+ }
+
+ @Override
+ public ObjectAdapter getAdapterFor(final Object pojo) {
+ return getRuntimeAdapterManager().getAdapterFor(pojo);
+ }
+
+ @Override
+ public ObjectAdapter adapterFor(final Object pojo) {
+ return getRuntimeAdapterManager().adapterFor(pojo);
+ }
+
+ @Override
+ public ObjectAdapter adapterFor(final Object pojo, final ObjectAdapter ownerAdapter) {
+ return getRuntimeAdapterManager().adapterFor(pojo, ownerAdapter);
+ }
+
+ @Override
+ public ObjectAdapter adapterFor(final Object pojo, final ObjectAdapter ownerAdapter, final OneToManyAssociation collection) {
+ return getRuntimeAdapterManager().adapterFor(pojo, ownerAdapter, collection);
+ }
+
+ @Override
+ public ObjectAdapter adapterFor(TypedOid oid) {
+ return getRuntimeAdapterManager().adapterFor(oid);
+ }
+
+ @Override
+ public ObjectAdapter adapterFor(TypedOid oid, ConcurrencyChecking concurrencyChecking) {
+ return getRuntimeAdapterManager().adapterFor(oid, concurrencyChecking);
+ }
+
+ @Override
+ public void injectInto(Object candidate) {
+ if (AdapterManagerAware.class.isAssignableFrom(candidate.getClass())) {
+ final AdapterManagerAware cast = AdapterManagerAware.class.cast(candidate);
+ cast.setAdapterManager(this);
+ }
+ }
+
+
+ };
+ this.objectInstantiator = new ObjectInstantiatorAbstract() {
+
+ @Override
+ public Object instantiate(final Class<?> cls) throws ObjectInstantiationException {
+ return getPersistenceSession().getObjectFactory().instantiate(cls);
+ }
+ };
+
+ this.objectDirtier = new ObjectDirtierAbstract() {
+
+ @Override
+ public void objectChanged(final ObjectAdapter adapter) {
+ getPersistenceSession().objectChanged(adapter);
+ }
+
+ @Override
+ public void objectChanged(final Object object) {
+ new DomainObjectContainerObjectChanged().objectChanged(object);
+ }
+ };
+ this.objectPersistor = new ObjectPersistorAbstract() {
+ @Override
+ public void makePersistent(final ObjectAdapter adapter) {
+ getPersistenceSession().makePersistent(adapter);
+ }
+
+ @Override
+ public void remove(final ObjectAdapter adapter) {
+ getUpdateNotifier().addDisposedObject(adapter);
+ getPersistenceSession().destroyObject(adapter);
+ }
+ };
+ this.servicesProvider = new ServicesProviderAbstract() {
+ @Override
+ public List<ObjectAdapter> getServices() {
+ return getPersistenceSession().getServices();
+ }
+ };
+ this.domainObjectServices = new DomainObjectServicesAbstract() {
+
+ @Override
+ public ObjectAdapter createTransientInstance(final ObjectSpecification spec) {
+ return getPersistenceSession().createTransientInstance(spec);
+ }
+
+ @Override
+ public ObjectAdapter createAggregatedInstance(final ObjectSpecification spec, final ObjectAdapter parent) {
+ return getPersistenceSession().createAggregatedInstance(spec, parent);
+ };
+
+ @Override
+ public Object lookup(Bookmark bookmark) {
+ return new DomainObjectContainerResolve().lookup(bookmark);
+ }
+
+
+ @Override
+ public Bookmark bookmarkFor(Object domainObject) {
+ return new DomainObjectContainerResolve().bookmarkFor(domainObject);
+ }
+
+ @Override
+ public void resolve(final Object parent) {
+ new DomainObjectContainerResolve().resolve(parent);
+ }
+
+ @Override
+ public void resolve(final Object parent, final Object field) {
+ new DomainObjectContainerResolve().resolve(parent, field);
+ }
+
+ @Override
+ public boolean flush() {
+ return getTransactionManager().flushTransaction();
+ }
+
+ @Override
+ public void commit() {
+ getTransactionManager().endTransaction();
+ }
+
+ @Override
+ public void informUser(final String message) {
+ getMessageBroker().addMessage(message);
+ }
+
+ @Override
+ public void warnUser(final String message) {
+ getMessageBroker().addWarning(message);
+ }
+
+ @Override
+ public void raiseError(final String message) {
+ throw new ApplicationException(message);
+ }
+
+ @Override
+ public String getProperty(final String name) {
+ return RuntimeContextFromSession.this.getProperty(name);
+ }
+
+ @Override
+ public List<String> getPropertyNames() {
+ return RuntimeContextFromSession.this.getPropertyNames();
+ }
+
+ };
+ this.querySubmitter = new QuerySubmitterAbstract() {
+
+ @Override
+ public <T> List<ObjectAdapter> allMatchingQuery(final Query<T> query) {
+ final ObjectAdapter instances = getPersistenceSession().findInstances(query, QueryCardinality.MULTIPLE);
+ return CollectionFacetUtils.convertToAdapterList(instances);
+ }
+
+ @Override
+ public <T> ObjectAdapter firstMatchingQuery(final Query<T> query) {
+ final ObjectAdapter instances = getPersistenceSession().findInstances(query, QueryCardinality.SINGLE);
+ final List<ObjectAdapter> list = CollectionFacetUtils.convertToAdapterList(instances);
+ return list.size() > 0 ? list.get(0) : null;
+ }
+ };
+ this.servicesInjector = new ServicesInjector() {
+
+ @Override
+ public void injectServicesInto(final Object object) {
+ getPersistenceSession().getServicesInjector().injectServicesInto(object);
+ }
+
+ @Override
+ public void injectServicesInto(List<Object> objects) {
+ getPersistenceSession().getServicesInjector().injectServicesInto(objects);
+ }
+
+ @Override
+ public Object lookupService(Class<?> serviceClass) {
+ return getPersistenceSession().getServicesInjector().lookupService(serviceClass);
+ }
+
+ @Override
+ public void injectInto(Object candidate) {
+ if (ServicesInjectorAware.class.isAssignableFrom(candidate.getClass())) {
+ final ServicesInjectorAware cast = ServicesInjectorAware.class.cast(candidate);
+ cast.setServicesInjector(this);
+ }
+ }
+ };
+ this.localizationProvider = new LocalizationProviderAbstract() {
+
+ @Override
+ public Localization getLocalization() {
+ return IsisContext.getLocalization();
+ }
+ };
+ }
+
+ // //////////////////////////////////////////////////////////////////
+ // Components
+ // //////////////////////////////////////////////////////////////////
+
+ @Override
+ public AuthenticationSessionProvider getAuthenticationSessionProvider() {
+ return authenticationSessionProvider;
+ }
+
+ @Override
+ public AdapterManager getAdapterManager() {
+ return adapterManager;
+ }
+
+ @Override
+ public ObjectInstantiator getObjectInstantiator() {
+ return objectInstantiator;
+ }
+
+ @Override
+ public DomainObjectServices getDomainObjectServices() {
+ return domainObjectServices;
+ }
+
+ @Override
+ public ServicesProvider getServicesProvider() {
+ return servicesProvider;
+ }
+
+ @Override
+ public LocalizationProviderAbstract getLocalizationProvider() {
+ return localizationProvider;
+ }
+
+ @Override
+ public ObjectDirtier getObjectDirtier() {
+ return objectDirtier;
+ }
+
+ @Override
+ public ObjectPersistor getObjectPersistor() {
+ return objectPersistor;
+ }
+
+ @Override
+ public ServicesInjector getDependencyInjector() {
+ return servicesInjector;
+ }
+
+ @Override
+ public QuerySubmitter getQuerySubmitter() {
+ return querySubmitter;
+ }
+
+ // ///////////////////////////////////////////
+ // Dependencies (from context)
+ // ///////////////////////////////////////////
+
+ @Override
+ public DeploymentCategory getDeploymentCategory() {
+ return IsisContext.getDeploymentType().getDeploymentCategory();
+ }
+
+ private static PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+ private static AdapterManager getRuntimeAdapterManager() {
+ return getPersistenceSession().getAdapterManager();
+ }
+
+ private static UpdateNotifier getUpdateNotifier() {
+ return IsisContext.getUpdateNotifier();
+ }
+
+ private static IsisTransactionManager getTransactionManager() {
+ return getPersistenceSession().getTransactionManager();
+ }
+
+ private static MessageBroker getMessageBroker() {
+ return IsisContext.getMessageBroker();
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/MethodUtils.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/MethodUtils.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/MethodUtils.java
new file mode 100644
index 0000000..99e8e5d
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/MethodUtils.java
@@ -0,0 +1,42 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectfactory;
+
+import java.lang.reflect.Method;
+
+public class MethodUtils {
+
+ public static boolean isGetter(final Method method) {
+ final String name = method.getName();
+ if (name.startsWith("get") && name.length() > 3) {
+ return true;
+ }
+ if (name.startsWith("is") && name.length() > 2) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isSetter(final Method method) {
+ final String name = method.getName();
+ return name.startsWith("set") && name.length() > 3;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectChanger.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectChanger.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectChanger.java
new file mode 100644
index 0000000..f9fad88
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectChanger.java
@@ -0,0 +1,26 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectfactory;
+
+public interface ObjectChanger {
+
+ void objectChanged(Object domainObject);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectFactoryAbstract.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectFactoryAbstract.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectFactoryAbstract.java
new file mode 100644
index 0000000..3bf9573
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectFactoryAbstract.java
@@ -0,0 +1,134 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectfactory;
+
+import java.lang.reflect.Modifier;
+
+import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
+import org.apache.isis.core.metamodel.spec.ObjectInstantiationException;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpiAware;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.ObjectFactory;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+
+/**
+ * Abstract adapter for {@link ObjectFactory}.
+ *
+ * <p>
+ * Implementation note: rather than use the <tt>*Aware</tt> interfaces, we
+ * instead look up dependencies from the {@link IsisContext}. This is necessary,
+ * for the {@link PersistenceSession} at least, because class enhancers may hold
+ * a reference to the factory as part of the generated bytecode. Since the
+ * {@link PersistenceSession} could change over the lifetime of the instance (eg
+ * when using the {@link InMemoryObjectStore}), we must always look the
+ * {@link PersistenceSession} from the {@link IsisContext}. The same applies to
+ * the {@link ServicesInjectorSpi}.
+ *
+ * <p>
+ * In theory it would be possible to cache the {@link SpecificationLoaderSpi} and
+ * inject using {@link SpecificationLoaderSpiAware}, but since we are already using
+ * the {@link IsisContext}, decided instead to use the same approach throughout.
+ */
+public abstract class ObjectFactoryAbstract implements ObjectFactory {
+
+ private final Mode mode;
+
+ public enum Mode {
+ /**
+ * Fail if no {@link ObjectAdapterPersistor} has been injected.
+ */
+ STRICT,
+ /**
+ * Ignore if no {@link ObjectAdapterPersistor} has been injected
+ * (intended for testing only).
+ */
+ RELAXED
+ }
+
+ public ObjectFactoryAbstract() {
+ this(Mode.STRICT);
+ }
+
+ public ObjectFactoryAbstract(final Mode mode) {
+ this.mode = mode;
+ }
+
+ @Override
+ public <T> T instantiate(final Class<T> cls) throws ObjectInstantiationException {
+
+ if (mode == Mode.STRICT && getServicesInjector() == null) {
+ throw new IllegalStateException("ServicesInjector has not been injected into ObjectFactory");
+ }
+ if (Modifier.isAbstract(cls.getModifiers())) {
+ throw new ObjectInstantiationException("Cannot create an instance of an abstract class: " + cls);
+ }
+ final T newInstance = doInstantiate(cls);
+
+ if (getServicesInjector() != null) {
+ getServicesInjector().injectServicesInto(newInstance);
+ }
+ return newInstance;
+ }
+
+ // /////////////////////////////////////////////////////////////////
+ // open, close
+ // /////////////////////////////////////////////////////////////////
+
+ /**
+ * Default implementation does nothing.
+ */
+ @Override
+ public void open() {
+ }
+
+ /**
+ * Default implementation does nothing.
+ */
+ @Override
+ public void close() {
+ }
+
+ // /////////////////////////////////////////////////////////////////
+ // doInstantiate
+ // /////////////////////////////////////////////////////////////////
+
+ /**
+ * Hook method for subclasses to override.
+ */
+ protected abstract <T> T doInstantiate(Class<T> cls) throws ObjectInstantiationException;
+
+ // /////////////////////////////////////////////////////////////////
+ // Dependencies (looked up from context)
+ // /////////////////////////////////////////////////////////////////
+
+ protected SpecificationLoaderSpi getSpecificationLoader() {
+ return IsisContext.getSpecificationLoader();
+ }
+
+ protected PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+ protected ServicesInjectorSpi getServicesInjector() {
+ return getPersistenceSession().getServicesInjector();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectResolver.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectResolver.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectResolver.java
new file mode 100644
index 0000000..da23d3a
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectfactory/ObjectResolver.java
@@ -0,0 +1,26 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectfactory;
+
+public interface ObjectResolver {
+
+ void resolve(Object domainObject, String propertyName);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/IsisObjectStoreDelegating.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/IsisObjectStoreDelegating.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/IsisObjectStoreDelegating.java
new file mode 100644
index 0000000..233c94f
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/IsisObjectStoreDelegating.java
@@ -0,0 +1,194 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectstore;
+
+import java.util.List;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.CreateObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.SaveObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceQuery;
+
+/**
+ * Implementation that simply delegates to underlying {@link ObjectStoreSpi}.
+ *
+ * <p>
+ * Useful for quickly writing decorating implementations.
+ */
+public class IsisObjectStoreDelegating implements ObjectStoreSpi {
+
+ private final ObjectStoreSpi underlying;
+ private final String name;
+
+ public IsisObjectStoreDelegating(final ObjectStoreSpi underlying, final String name) {
+ this.underlying = underlying;
+ this.name = name;
+ }
+
+ // ////////////////////////////////////////////////
+ // name
+ // ////////////////////////////////////////////////
+
+ @Override
+ public String name() {
+ return name + "(" + underlying.name() + ")";
+ }
+
+ // ////////////////////////////////////////////////
+ // init, shutdown, reset, isInitialized
+ // ////////////////////////////////////////////////
+
+ @Override
+ public void open() {
+ underlying.open();
+ }
+
+ @Override
+ public void close() {
+ underlying.close();
+ }
+
+ @Override
+ public void reset() {
+ underlying.reset();
+ }
+
+ @Override
+ public boolean isFixturesInstalled() {
+ return underlying.isFixturesInstalled();
+ }
+
+ // ////////////////////////////////////////////////
+ // createXxxCommands
+ // ////////////////////////////////////////////////
+
+ @Override
+ public CreateObjectCommand createCreateObjectCommand(final ObjectAdapter object) {
+ return underlying.createCreateObjectCommand(object);
+ }
+
+ @Override
+ public DestroyObjectCommand createDestroyObjectCommand(final ObjectAdapter object) {
+ return underlying.createDestroyObjectCommand(object);
+ }
+
+ @Override
+ public SaveObjectCommand createSaveObjectCommand(final ObjectAdapter object) {
+ return underlying.createSaveObjectCommand(object);
+ }
+
+ // ////////////////////////////////////////////////
+ // execute
+ // ////////////////////////////////////////////////
+
+ @Override
+ public void execute(final List<PersistenceCommand> commands) {
+ underlying.execute(commands);
+ }
+
+ // ////////////////////////////////////////////////
+ // TransactionManagement
+ // ////////////////////////////////////////////////
+
+ @Override
+ public void startTransaction() {
+ underlying.startTransaction();
+ }
+
+ @Override
+ public void endTransaction() {
+ underlying.endTransaction();
+ }
+
+ @Override
+ public void abortTransaction() {
+ underlying.abortTransaction();
+ }
+
+ // ////////////////////////////////////////////////
+ // getObject, resolveImmediately, resolveField
+ // ////////////////////////////////////////////////
+
+ @Override
+ public ObjectAdapter loadInstanceAndAdapt(final TypedOid oid) {
+ return underlying.loadInstanceAndAdapt(oid);
+ }
+
+ @Override
+ public void resolveField(final ObjectAdapter object, final ObjectAssociation field) {
+ underlying.resolveField(object, field);
+ }
+
+ @Override
+ public void resolveImmediately(final ObjectAdapter object) {
+ underlying.resolveImmediately(object);
+ }
+
+ // ////////////////////////////////////////////////
+ // getInstances, hasInstances
+ // ////////////////////////////////////////////////
+
+ @Override
+ public List<ObjectAdapter> loadInstancesAndAdapt(final PersistenceQuery persistenceQuery) {
+ return underlying.loadInstancesAndAdapt(persistenceQuery);
+ }
+
+ @Override
+ public boolean hasInstances(final ObjectSpecification specification) {
+ return underlying.hasInstances(specification);
+ }
+
+ // ////////////////////////////////////////////////
+ // services
+ // ////////////////////////////////////////////////
+
+ @Override
+ public RootOid getOidForService(ObjectSpecification serviceSpecification) {
+ return underlying.getOidForService(serviceSpecification);
+ }
+
+ @Override
+ public void registerService(final RootOid rootOid) {
+ underlying.registerService(rootOid);
+ }
+
+ // ////////////////////////////////////////////////
+ // debug
+ // ////////////////////////////////////////////////
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ underlying.debugData(debug);
+ }
+
+ @Override
+ public String debugTitle() {
+ return underlying.debugTitle();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/IsisObjectStoreLogger.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/IsisObjectStoreLogger.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/IsisObjectStoreLogger.java
new file mode 100644
index 0000000..eb4e1f4
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/IsisObjectStoreLogger.java
@@ -0,0 +1,204 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectstore;
+
+import java.util.List;
+
+import org.apache.isis.core.commons.config.IsisConfigurationException;
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.factory.InstanceCreationException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.logging.Logger;
+import org.apache.isis.runtimes.dflt.runtime.persistence.ObjectNotFoundException;
+import org.apache.isis.runtimes.dflt.runtime.persistence.ObjectPersistenceException;
+import org.apache.isis.runtimes.dflt.runtime.persistence.UnsupportedFindException;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.CreateObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.SaveObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceQuery;
+
+public class IsisObjectStoreLogger extends Logger implements ObjectStoreSpi {
+ private final ObjectStoreSpi underlying;
+
+ public IsisObjectStoreLogger(final ObjectStoreSpi decorated, final String level) {
+ super(level);
+ this.underlying = decorated;
+ }
+
+ public IsisObjectStoreLogger(final ObjectStoreSpi decorated) {
+ this.underlying = decorated;
+ }
+
+ @Override
+ public CreateObjectCommand createCreateObjectCommand(final ObjectAdapter object) {
+ log("create object " + object);
+ return underlying.createCreateObjectCommand(object);
+ }
+
+ @Override
+ public void registerService(final RootOid rootOid) {
+ log("registering service: " + rootOid.enString(getOidMarshaller()));
+ underlying.registerService(rootOid);
+ }
+
+ @Override
+ public DestroyObjectCommand createDestroyObjectCommand(final ObjectAdapter object) {
+ log("destroy object " + object);
+ return underlying.createDestroyObjectCommand(object);
+ }
+
+ @Override
+ public SaveObjectCommand createSaveObjectCommand(final ObjectAdapter object) {
+ log("save object " + object);
+ return underlying.createSaveObjectCommand(object);
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ underlying.debugData(debug);
+ }
+
+ @Override
+ public String debugTitle() {
+ return underlying.debugTitle();
+ }
+
+ @Override
+ protected Class<?> getDecoratedClass() {
+ return underlying.getClass();
+ }
+
+ @Override
+ public List<ObjectAdapter> loadInstancesAndAdapt(final PersistenceQuery criteria) throws ObjectPersistenceException, UnsupportedFindException {
+ log("get instances matching " + criteria);
+ return underlying.loadInstancesAndAdapt(criteria);
+ }
+
+
+ @Override
+ public ObjectAdapter loadInstanceAndAdapt(final TypedOid oid) throws ObjectNotFoundException, ObjectPersistenceException {
+ final ObjectAdapter adapter = underlying.loadInstanceAndAdapt(oid);
+ log("get object for " + oid + " (of type '" + oid.getObjectSpecId() + "')", adapter.getObject());
+ return adapter;
+ }
+
+ @Override
+ public RootOid getOidForService(ObjectSpecification serviceSpec) {
+ final RootOid serviceOid = underlying.getOidForService(serviceSpec);
+ if(serviceOid != null) {
+ log("get OID for service: " + serviceOid.enString(getOidMarshaller()));
+ } else {
+ log("get OID for service: null (presumably in the process of being registered for '" + serviceSpec.getSpecId() + "')");
+ }
+ return serviceOid;
+ }
+
+ @Override
+ public boolean hasInstances(final ObjectSpecification specification) throws ObjectPersistenceException {
+ final boolean hasInstances = underlying.hasInstances(specification);
+ log("has instances of " + specification.getShortIdentifier(), "" + hasInstances);
+ return hasInstances;
+ }
+
+ @Override
+ public boolean isFixturesInstalled() {
+ final boolean isInitialized = underlying.isFixturesInstalled();
+ log("is initialized: " + isInitialized);
+ return isInitialized;
+ }
+
+ @Override
+ public void open() throws IsisConfigurationException, InstanceCreationException, ObjectPersistenceException {
+ log("opening " + name());
+ underlying.open();
+ }
+
+ @Override
+ public String name() {
+ return underlying.name();
+ }
+
+ @Override
+ public void reset() {
+ log("reset");
+ underlying.reset();
+ }
+
+ @Override
+ public void resolveField(final ObjectAdapter object, final ObjectAssociation field) throws ObjectPersistenceException {
+ log("resolve eagerly object in field " + field + " of " + object);
+ underlying.resolveField(object, field);
+ }
+
+ @Override
+ public void resolveImmediately(final ObjectAdapter object) throws ObjectPersistenceException {
+ log("resolve immediately: " + object);
+ underlying.resolveImmediately(object);
+ }
+
+ @Override
+ public void execute(final List<PersistenceCommand> commands) throws ObjectPersistenceException {
+ log("execute commands");
+ int i = 0;
+ for (final PersistenceCommand command : commands) {
+ log(" " + (i++) + " " + command);
+ }
+ underlying.execute(commands);
+ }
+
+ @Override
+ public void close() throws ObjectPersistenceException {
+ log("closing " + underlying);
+ underlying.close();
+ }
+
+ @Override
+ public void startTransaction() {
+ underlying.startTransaction();
+ }
+
+ @Override
+ public void endTransaction() {
+ underlying.endTransaction();
+ }
+
+ @Override
+ public void abortTransaction() {
+ underlying.abortTransaction();
+ }
+
+
+ /////////////////////////////////////////////
+ // Dependencies (from context)
+ /////////////////////////////////////////////
+
+ protected OidMarshaller getOidMarshaller() {
+ return IsisContext.getOidMarshaller();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/ObjectStoreSpi.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/ObjectStoreSpi.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/ObjectStoreSpi.java
new file mode 100644
index 0000000..98a7484
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/ObjectStoreSpi.java
@@ -0,0 +1,27 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectstore;
+
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.TransactionalResource;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.ObjectStore;
+
+public interface ObjectStoreSpi extends ObjectStore, TransactionalResource {
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithm.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithm.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithm.java
new file mode 100644
index 0000000..ec80858
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithm.java
@@ -0,0 +1,29 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectstore.algorithm;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+
+public interface PersistAlgorithm {
+
+ public void makePersistent(final ObjectAdapter object, final ToPersistObjectSet adders);
+
+ public String name();
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmAbstract.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmAbstract.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmAbstract.java
new file mode 100644
index 0000000..a44a2ab
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmAbstract.java
@@ -0,0 +1,96 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectstore.algorithm;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.runtimes.dflt.runtime.persistence.NotPersistableException;
+
+public abstract class PersistAlgorithmAbstract implements PersistAlgorithm {
+
+ // ////////////////////////////////////////////////////////////////
+ // init, shutdown
+ // ////////////////////////////////////////////////////////////////
+
+ public void init() {
+ }
+
+ public void shutdown() {
+ }
+
+ // ////////////////////////////////////////////////////////////////
+ // helpers
+ // ////////////////////////////////////////////////////////////////
+
+ /**
+ * Whether the persist algorithm should skip over this object.
+ *
+ * <p>
+ * There are various reasons why an object should not be persisted:
+ * <ul>
+ * <li>it is already persisted
+ * <li>its {@link ObjectSpecification specification} indicates instances of
+ * its type should not be persisted.
+ * <li>it is {@link ResolveState#VALUE standalone}
+ * <li>it is a {@link ObjectSpecification#isService() service}.
+ * </ul>
+ *
+ * <p>
+ * Implementation note: the only reason that this method has not been
+ * combined with the weaker check in
+ * {@link #alreadyPersistedOrNotPersistable(ObjectAdapter)} is because of
+ * existing code that throws an exception if the latter is not fulfilled.
+ * <b><i>REVIEW: should try to combine and remove the other method</i></b>.
+ */
+ protected static boolean alreadyPersistedOrNotPersistableOrServiceOrStandalone(final ObjectAdapter adapter) {
+ return adapter.isValue() || objectSpecIsService(adapter) || alreadyPersistedOrNotPersistable(adapter);
+ }
+
+ /**
+ * If has a {@link ResolveState} that is already persisted or has a
+ * {@link ObjectSpecification specification} that indicates instances of its
+ * type should not be persisted.
+ *
+ * @see #alreadyPersistedOrNotPersistableOrServiceOrStandalone(ObjectAdapter)
+ */
+ protected static boolean alreadyPersistedOrNotPersistable(final ObjectAdapter adapter) {
+ return adapter.representsPersistent() || objectSpecNotPersistable(adapter);
+ }
+
+ /**
+ * As per {@link #alreadyPersistedOrNotPersistable(ObjectAdapter)}, ensures
+ * object can be persisted else throws {@link NotPersistableException}.
+ */
+ protected static void assertObjectNotPersistentAndPersistable(final ObjectAdapter object) {
+ if (alreadyPersistedOrNotPersistable(object)) {
+ throw new NotPersistableException("can't make object persistent - either already persistent, " + "or transient only: " + object);
+ }
+ }
+
+ private static boolean objectSpecNotPersistable(final ObjectAdapter adapter) {
+ return !adapter.getSpecification().persistability().isPersistable() || adapter.isParented();
+ }
+
+ private static boolean objectSpecIsService(final ObjectAdapter adapter) {
+ return adapter.getSpecification().isService();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmDefault.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmDefault.java b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmDefault.java
new file mode 100644
index 0000000..639f5e1
--- /dev/null
+++ b/framework/core/runtime/src/main/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmDefault.java
@@ -0,0 +1,118 @@
+/*
+ * 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.runtimes.dflt.runtime.persistence.objectstore.algorithm;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.commons.lang.ToString;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacetUtils;
+import org.apache.isis.core.metamodel.facets.object.callbacks.CallbackUtils;
+import org.apache.isis.core.metamodel.facets.object.callbacks.PersistedCallbackFacet;
+import org.apache.isis.core.metamodel.facets.object.callbacks.PersistingCallbackFacet;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.runtimes.dflt.runtime.persistence.ObjectPersistenceException;
+
+public class PersistAlgorithmDefault extends PersistAlgorithmAbstract {
+ private static final Logger LOG = Logger.getLogger(PersistAlgorithmDefault.class);
+
+ @Override
+ public String name() {
+ return "Simple Bottom Up Persistence Walker";
+ }
+
+ @Override
+ public void makePersistent(final ObjectAdapter adapter, final ToPersistObjectSet toPersistObjectSet) {
+ if (adapter.getSpecification().isParentedOrFreeCollection()) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("persist " + adapter);
+ }
+ if (adapter.isGhost()) {
+ adapter.changeState(ResolveState.RESOLVING);
+ adapter.changeState(ResolveState.RESOLVED);
+ } else if (adapter.isTransient()) {
+ adapter.changeState(ResolveState.RESOLVED);
+ }
+ final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(adapter);
+ for (final ObjectAdapter element : facet.iterable(adapter)) {
+ persist(element, toPersistObjectSet);
+ }
+ } else {
+ assertObjectNotPersistentAndPersistable(adapter);
+ persist(adapter, toPersistObjectSet);
+ }
+ }
+
+ protected void persist(final ObjectAdapter adapter, final ToPersistObjectSet toPersistObjectSet) {
+ if (alreadyPersistedOrNotPersistableOrServiceOrStandalone(adapter)) {
+ return;
+ }
+
+ final List<ObjectAssociation> associations = adapter.getSpecification().getAssociations();
+ if (!adapter.getSpecification().isEncodeable() && associations.size() > 0) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("make persistent " + adapter);
+ }
+ CallbackUtils.callCallback(adapter, PersistingCallbackFacet.class);
+ toPersistObjectSet.remapAsPersistent(adapter);
+
+ // was previously to SERIALIZING_RESOLVED, but
+ // after refactoring simplifications this is now equivalent to UPDATING
+ final ResolveState stateWhilePersisting = ResolveState.UPDATING;
+
+ adapter.changeState(stateWhilePersisting);
+
+ for (int i = 0; i < associations.size(); i++) {
+ final ObjectAssociation objectAssoc = associations.get(i);
+ if (objectAssoc.isNotPersisted()) {
+ continue;
+ }
+ if (objectAssoc.isOneToManyAssociation()) {
+ final ObjectAdapter collection = objectAssoc.get(adapter);
+ if (collection == null) {
+ throw new ObjectPersistenceException("Collection " + objectAssoc.getName() + " does not exist in " + adapter.getSpecification().getFullIdentifier());
+ }
+ makePersistent(collection, toPersistObjectSet);
+ } else {
+ final ObjectAdapter fieldValue = objectAssoc.get(adapter);
+ if (fieldValue == null) {
+ continue;
+ }
+ persist(fieldValue, toPersistObjectSet);
+ }
+ }
+ toPersistObjectSet.addCreateObjectCommand(adapter);
+ CallbackUtils.callCallback(adapter, PersistedCallbackFacet.class);
+ adapter.changeState(stateWhilePersisting.getEndState());
+ }
+
+ }
+
+ @Override
+ public String toString() {
+ final ToString toString = new ToString(this);
+ return toString.toString();
+ }
+
+}