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 2014/10/28 17:16:59 UTC
[56/56] [abbrv] git commit: ISIS-936: moved
isis-core-objectstore-inmemory into isis-core-runtime.
ISIS-936: moved isis-core-objectstore-inmemory into isis-core-runtime.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/f4b90213
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/f4b90213
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/f4b90213
Branch: refs/heads/master
Commit: f4b902133bd4c298b7752435ad4583bc1106dfde
Parents: bf1bc5b
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Tue Oct 28 16:10:45 2014 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Tue Oct 28 16:10:45 2014 +0000
----------------------------------------------------------------------
component/viewer/scimpi/tck/pom.xml | 2 +-
core/integtestsupport/pom.xml | 5 -
core/objectstore-inmemory/pom.xml | 86 ---
.../core/objectstore/InMemoryObjectStore.java | 517 -------------------
.../InMemoryPersistenceMechanismInstaller.java | 110 ----
.../InMemoryPersistenceSessionFactory.java | 93 ----
.../AbstractInMemoryPersistenceCommand.java | 65 ---
.../commands/InMemoryCreateObjectCommand.java | 50 --
.../commands/InMemoryDestroyObjectCommand.java | 50 --
.../commands/InMemorySaveObjectCommand.java | 49 --
.../internal/ObjectStoreInstances.java | 249 ---------
.../internal/ObjectStorePersistedObjects.java | 50 --
.../ObjectStorePersistedObjectsDefault.java | 102 ----
...bjectStoreInstances_findInstancesAndAdd.java | 115 -----
.../internal/ObjectStoreInstances_init.java | 69 ---
.../internal/ObjectStoreInstances_save.java | 121 -----
...tStorePersistedObjectsDefault_instances.java | 93 ----
...jectsDefault_savesOidGeneratorAsMemento.java | 60 ---
...ctStorePersistedObjectsDefault_services.java | 76 ---
core/objectstore-inmemory/test.data | 4 -
core/pom.xml | 16 -
.../core/objectstore/InMemoryObjectStore.java | 517 +++++++++++++++++++
.../InMemoryPersistenceMechanismInstaller.java | 110 ++++
.../InMemoryPersistenceSessionFactory.java | 93 ++++
.../AbstractInMemoryPersistenceCommand.java | 65 +++
.../commands/InMemoryCreateObjectCommand.java | 50 ++
.../commands/InMemoryDestroyObjectCommand.java | 50 ++
.../commands/InMemorySaveObjectCommand.java | 49 ++
.../internal/ObjectStoreInstances.java | 249 +++++++++
.../internal/ObjectStorePersistedObjects.java | 50 ++
.../ObjectStorePersistedObjectsDefault.java | 102 ++++
...bjectStoreInstances_findInstancesAndAdd.java | 115 +++++
.../internal/ObjectStoreInstances_init.java | 69 +++
.../internal/ObjectStoreInstances_save.java | 121 +++++
...tStorePersistedObjectsDefault_instances.java | 93 ++++
...jectsDefault_savesOidGeneratorAsMemento.java | 60 +++
...ctStorePersistedObjectsDefault_services.java | 76 +++
tck/tck-viewer-restfulobjects/pom.xml | 2 +-
tck/tck-viewer-wicket/pom.xml | 2 +-
39 files changed, 1872 insertions(+), 1983 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/component/viewer/scimpi/tck/pom.xml
----------------------------------------------------------------------
diff --git a/component/viewer/scimpi/tck/pom.xml b/component/viewer/scimpi/tck/pom.xml
index cb8c2ae..f1f56d7 100644
--- a/component/viewer/scimpi/tck/pom.xml
+++ b/component/viewer/scimpi/tck/pom.xml
@@ -78,7 +78,7 @@
<!-- isis runtime -->
<dependency>
<groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-objectstore</artifactId>
+ <artifactId>isis-core-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.apache.isis.core</groupId>
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/integtestsupport/pom.xml
----------------------------------------------------------------------
diff --git a/core/integtestsupport/pom.xml b/core/integtestsupport/pom.xml
index bfbcb70..0f7d08f 100644
--- a/core/integtestsupport/pom.xml
+++ b/core/integtestsupport/pom.xml
@@ -93,11 +93,6 @@
<dependency>
<groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-objectstore</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.isis.core</groupId>
<artifactId>isis-core-runtime</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/pom.xml
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/pom.xml b/core/objectstore-inmemory/pom.xml
deleted file mode 100644
index 88eadf5..0000000
--- a/core/objectstore-inmemory/pom.xml
+++ /dev/null
@@ -1,86 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis</artifactId>
- <version>1.8.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>isis-core-objectstore</artifactId>
- <name>Isis Core (In-Memory) ObjectStore</name>
-
- <properties>
- <siteBaseDir>..</siteBaseDir>
- <relativeUrl>objectstore-inmemory/</relativeUrl>
- </properties>
-
- <!-- used in Site generation for relative references. -->
- <url>http://isis.apache.org/${relativeUrl}</url>
-
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <inherited>false</inherited>
- <configuration>
- <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
- </configuration>
- <reportSets>
- <reportSet>
- <inherited>false</inherited>
- <reports>
- <report>dependencies</report>
- <report>dependency-convergence</report>
- <report>plugins</report>
- <report>summary</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- </plugins>
- </reporting>
-
- <dependencies>
-
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-unittestsupport</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-metamodel</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-runtime</artifactId>
- </dependency>
-
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryObjectStore.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryObjectStore.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryObjectStore.java
deleted file mode 100644
index 5ae36cf..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryObjectStore.java
+++ /dev/null
@@ -1,517 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore;
-
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import com.google.common.collect.Lists;
-
-import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.commons.debug.DebugUtils;
-import org.apache.isis.core.commons.exceptions.IsisException;
-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.TypedOid;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-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.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.SpecificationLoader;
-import org.apache.isis.core.metamodel.spec.feature.Contributed;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.objectstore.commands.InMemoryCreateObjectCommand;
-import org.apache.isis.core.objectstore.commands.InMemoryDestroyObjectCommand;
-import org.apache.isis.core.objectstore.commands.InMemorySaveObjectCommand;
-import org.apache.isis.core.objectstore.internal.ObjectStoreInstances;
-import org.apache.isis.core.objectstore.internal.ObjectStorePersistedObjects;
-import org.apache.isis.core.objectstore.internal.ObjectStorePersistedObjectsDefault;
-import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
-import org.apache.isis.core.runtime.persistence.UnsupportedFindException;
-import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.CreateObjectCommand;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.SaveObjectCommand;
-import org.apache.isis.core.runtime.persistence.query.PersistenceQueryBuiltIn;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.PersistenceQuery;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
-
-public class InMemoryObjectStore implements ObjectStoreSpi {
-
- private final static Logger LOG = LoggerFactory.getLogger(InMemoryObjectStore.class);
-
- protected ObjectStorePersistedObjects persistedObjects;
-
- public InMemoryObjectStore() {
- LOG.info("creating memory object store");
- }
-
- // ///////////////////////////////////////////////////////
- // Name
- // ///////////////////////////////////////////////////////
-
- @Override
- public String name() {
- return "In-Memory Object Store";
- }
-
- // ///////////////////////////////////////////////////////
- // open, close, shutdown
- // ///////////////////////////////////////////////////////
-
- @Override
- public void open() {
- // TODO: all a bit hacky, but is to keep tests running. Should really
- // sort out using mocks.
- final InMemoryPersistenceSessionFactory inMemoryPersistenceSessionFactory = getInMemoryPersistenceSessionFactory();
- persistedObjects = inMemoryPersistenceSessionFactory == null ? null : inMemoryPersistenceSessionFactory.getPersistedObjects();
- if (persistedObjects == null) {
- if (inMemoryPersistenceSessionFactory != null) {
- persistedObjects = inMemoryPersistenceSessionFactory.createPersistedObjects();
- } else {
- persistedObjects = new ObjectStorePersistedObjectsDefault();
- }
- } else {
- recreateAdapters();
- }
- }
-
- protected void recreateAdapters() {
- for (final ObjectSpecId noSpec : persistedObjects.specifications()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("recreating adapters for: " + noSpec.asString());
- }
- recreateAdapters(persistedObjects.instancesFor(noSpec));
- }
- }
-
- private void recreateAdapters(final ObjectStoreInstances objectStoreInstances) {
- for (final Oid oid : objectStoreInstances.getOids()) {
-
- // it's important not to "touch" the pojo, not even in log messages.
- // That's because
- // the toString() will cause bytecode enhancement to try to resolve
- // references.
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("recreating adapter: oid=" + oid);
- }
- final Object pojo = objectStoreInstances.getPojo(oid);
-
- final ObjectAdapter existingAdapterLookedUpByPojo = getAdapterManager().getAdapterFor(pojo);
- if (existingAdapterLookedUpByPojo != null) {
- // this could happen if we rehydrate a persisted object that
- // depends on another persisted object
- // not yet rehydrated.
- getPersistenceSession().removeAdapter(existingAdapterLookedUpByPojo);
- }
-
- final ObjectAdapter existingAdapterLookedUpByOid = getAdapterManager().getAdapterFor(oid);
- if (existingAdapterLookedUpByOid != null) {
- throw new IsisException("A mapping already exists for " + oid + ": " + existingAdapterLookedUpByOid);
- }
-
- final ObjectAdapter recreatedAdapter = getPersistenceSession().mapRecreatedPojo(oid, pojo);
-
- final Version version = objectStoreInstances.getVersion(oid);
- recreatedAdapter.setVersion(version);
- }
- }
-
- @Override
- public void close() {
- final InMemoryPersistenceSessionFactory inMemoryPersistenceSessionFactory = getInMemoryPersistenceSessionFactory();
- // TODO: this is hacky, only here to keep tests running. Should sort out
- // using mocks
- if (inMemoryPersistenceSessionFactory != null) {
- inMemoryPersistenceSessionFactory.attach(getPersistenceSession(), persistedObjects);
- persistedObjects = null;
- }
- }
-
- // ///////////////////////////////////////////////////////
- // fixtures
- // ///////////////////////////////////////////////////////
-
- /**
- * No permanent persistence, so must always install fixtures.
- */
- @Override
- public boolean isFixturesInstalled() {
- return false;
- }
-
- // ///////////////////////////////////////////////////////
- // reset
- // ///////////////////////////////////////////////////////
-
- @Override
- public void reset() {
- }
-
- // ///////////////////////////////////////////////////////
- // Transaction management
- // ///////////////////////////////////////////////////////
-
- @Override
- public void startTransaction() {
- }
-
- @Override
- public void endTransaction() {
- }
-
- @Override
- public void abortTransaction() {
- }
-
- // ///////////////////////////////////////////////////////
- // Command Creation
- // ///////////////////////////////////////////////////////
-
- @Override
- public CreateObjectCommand createCreateObjectCommand(final ObjectAdapter object) {
- if (object.getSpecification().isParented()) {
- return null;
- }
- return new InMemoryCreateObjectCommand(object, persistedObjects);
- }
-
- @Override
- public SaveObjectCommand createSaveObjectCommand(final ObjectAdapter object) {
- if (object.getSpecification().isParented()) {
- return null;
- }
- return new InMemorySaveObjectCommand(object, persistedObjects);
- }
-
- @Override
- public DestroyObjectCommand createDestroyObjectCommand(final ObjectAdapter object) {
- return new InMemoryDestroyObjectCommand(object, persistedObjects);
- }
-
- // ///////////////////////////////////////////////////////
- // Command Execution
- // ///////////////////////////////////////////////////////
-
- @Override
- public void execute(final List<PersistenceCommand> commands) throws ObjectPersistenceException {
- if (LOG.isInfoEnabled()) {
- LOG.info("execute commands");
- }
- for (final PersistenceCommand command : commands) {
- command.execute(null);
- }
- LOG.info("end execution");
- }
-
- // ///////////////////////////////////////////////////////
- // getObject, resolveField, resolveImmediately
- // ///////////////////////////////////////////////////////
-
- @Override
- public ObjectAdapter loadInstanceAndAdapt(final TypedOid oid) throws ObjectNotFoundException, ObjectPersistenceException {
- if(LOG.isDebugEnabled()) {
- LOG.debug("getObject " + oid);
- }
- final ObjectSpecification objectSpec = getSpecificationLookup().lookupBySpecId(oid.getObjectSpecId());
- final ObjectStoreInstances ins = instancesFor(objectSpec.getSpecId());
- final ObjectAdapter adapter = ins.getObjectAndMapIfRequired(oid);
- if (adapter == null) {
- throw new ObjectNotFoundException(oid);
- }
- return adapter;
- }
-
- @Override
- public void resolveImmediately(final ObjectAdapter adapter) throws ObjectPersistenceException {
-
- // these diagnostics are because, even though this method is called by
- // PersistenceSessionObjectStore#resolveImmediately which has a check,
- // seem to be hitting a race condition with another thread that is
- // resolving the object before I get here.
- if (adapter.canTransitionToResolving()) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("resolve " + adapter);
- }
- } else {
- LOG.warn("resolveImmediately ignored, " + "adapter's current state is: " + adapter.getResolveState() + " ; oid: " + adapter.getOid());
- }
-
- adapter.markAsResolvedIfPossible();
- }
-
- @Override
- public void resolveField(final ObjectAdapter object, final ObjectAssociation field) throws ObjectPersistenceException {
- final ObjectAdapter referenceAdapter = field.get(object);
- referenceAdapter.markAsResolvedIfPossible();
- }
-
-
-
- // ///////////////////////////////////////////////////////
- // getInstances, hasInstances
- // ///////////////////////////////////////////////////////
-
- @Override
- public List<ObjectAdapter> loadInstancesAndAdapt(final PersistenceQuery persistenceQuery) throws ObjectPersistenceException, UnsupportedFindException {
-
- if (!(persistenceQuery instanceof PersistenceQueryBuiltIn)) {
- throw new IllegalArgumentException(MessageFormat.format("Provided PersistenceQuery not supported; was {0}; " + "the in-memory object store only supports {1}", persistenceQuery.getClass().getName(), PersistenceQueryBuiltIn.class.getName()));
- }
- final PersistenceQueryBuiltIn builtIn = (PersistenceQueryBuiltIn) persistenceQuery;
-
- final List<ObjectAdapter> instances = Lists.newArrayList();
- final ObjectSpecification spec = persistenceQuery.getSpecification();
- findInstances(spec, builtIn, instances);
- return resolved(instances);
- }
-
- @Override
- public boolean hasInstances(final ObjectSpecification spec) {
- if (instancesFor(spec.getSpecId()).hasInstances()) {
- return true;
- }
-
- // includeSubclasses
- final List<ObjectSpecification> subclasses = spec.subclasses();
- for (int i = 0; i < subclasses.size(); i++) {
- if (hasInstances(subclasses.get(i))) {
- return true;
- }
- }
-
- return false;
- }
-
- private void findInstances(final ObjectSpecification spec, final PersistenceQueryBuiltIn persistenceQuery, final List<ObjectAdapter> foundInstances) {
-
- instancesFor(spec.getSpecId()).findInstancesAndAdd(persistenceQuery, foundInstances);
-
- // include subclasses
- final List<ObjectSpecification> subclasses = spec.subclasses();
- for (int i = 0; i < subclasses.size(); i++) {
- findInstances(subclasses.get(i), persistenceQuery, foundInstances);
- }
- }
-
- private static List<ObjectAdapter> resolved(final List<ObjectAdapter> instances) {
- for (ObjectAdapter adapter: instances) {
- adapter.markAsResolvedIfPossible();
- }
- return instances;
- }
-
- // ///////////////////////////////////////////////////////
- // Services
- // ///////////////////////////////////////////////////////
-
- @Override
- public RootOid getOidForService(ObjectSpecification serviceSpec) {
- return (RootOid) persistedObjects.getService(serviceSpec.getSpecId());
- }
-
- @Override
- public void registerService(final RootOid rootOid) {
- persistedObjects.registerService(rootOid.getObjectSpecId(), rootOid);
- }
-
- private ObjectStoreInstances instancesFor(final ObjectSpecId spec) {
- return persistedObjects.instancesFor(spec);
- }
-
- // ///////////////////////////////////////////////////////
- // Debugging
- // ///////////////////////////////////////////////////////
-
- @Override
- public String debugTitle() {
- return name();
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendTitle("Domain Objects");
- for (final ObjectSpecId specId : persistedObjects.specifications()) {
- debug.appendln(specId.asString());
- final ObjectStoreInstances instances = instancesFor(specId);
- instances.debugData(debug);
- }
- debug.unindent();
- debug.appendln();
- }
-
- private String debugCollectionGraph(final ObjectAdapter collection, final int level, final Vector<ObjectAdapter> recursiveElements) {
- final StringBuffer s = new StringBuffer();
-
- if (recursiveElements.contains(collection)) {
- s.append("*\n");
- } else {
- recursiveElements.addElement(collection);
-
- final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(collection);
- final Iterator<ObjectAdapter> e = facet.iterator(collection);
-
- while (e.hasNext()) {
- indent(s, level);
-
- ObjectAdapter element;
- try {
- element = e.next();
- } catch (final ClassCastException ex) {
- LOG.error(ex.getMessage(), ex);
- return s.toString();
- }
-
- s.append(element);
- s.append(debugGraph(element, level + 1, recursiveElements));
- }
- }
-
- return s.toString();
- }
-
- private String debugGraph(final ObjectAdapter object, final int level, final Vector<ObjectAdapter> recursiveElements) {
- if (level > 3) {
- return "...\n"; // only go 3 levels?
- }
-
- Vector<ObjectAdapter> elements;
- if (recursiveElements == null) {
- elements = new Vector<ObjectAdapter>(25, 10);
- } else {
- elements = recursiveElements;
- }
-
- if (object.getSpecification().isParentedOrFreeCollection()) {
- return "\n" + debugCollectionGraph(object, level, elements);
- } else {
- return "\n" + debugObjectGraph(object, level, elements);
- }
- }
-
- private String debugObjectGraph(final ObjectAdapter object, final int level, final Vector<ObjectAdapter> recursiveElements) {
- final StringBuffer s = new StringBuffer();
-
- recursiveElements.addElement(object);
-
- // work through all its fields
- final List<ObjectAssociation> fields = object.getSpecification().getAssociations(Contributed.EXCLUDED);
-
- for (int i = 0; i < fields.size(); i++) {
- final ObjectAssociation field = fields.get(i);
- final Object obj = field.get(object);
-
- final String id = field.getId();
- indent(s, level);
-
- if (field.isOneToManyAssociation()) {
- s.append(id + ": \n" + debugCollectionGraph((ObjectAdapter) obj, level + 1, recursiveElements));
- } else {
- if (recursiveElements.contains(obj)) {
- s.append(id + ": " + obj + "*\n");
- } else {
- s.append(id + ": " + obj);
- s.append(debugGraph((ObjectAdapter) obj, level + 1, recursiveElements));
- }
- }
- }
-
- return s.toString();
- }
-
- private void indent(final StringBuffer s, final int level) {
- for (int indent = 0; indent < level; indent++) {
- s.append(DebugUtils.indentString(4) + "|");
- }
-
- s.append(DebugUtils.indentString(4) + "+--");
- }
-
- // ///////////////////////////////////////////////////////
- // Dependencies (from context)
- // ///////////////////////////////////////////////////////
-
- /**
- * Must use {@link IsisContext context}, because although this object is
- * recreated with each {@link PersistenceSession session}, the persisted
- * objects that get
- * {@link #attachPersistedObjects(ObjectStorePersistedObjects) attached} to
- * it span multiple sessions.
- *
- * <p>
- * The alternative design would be to laboriously inject the session into
- * not only this object but also the {@link ObjectStoreInstances} that do
- * the work.
- */
- protected PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- /**
- * Must use {@link IsisContext context}, because although this object is
- * recreated with each {@link PersistenceSession session}, the persisted
- * objects that get
- * {@link #attachPersistedObjects(ObjectStorePersistedObjects) attached} to
- * it span multiple sessions.
- *
- * <p>
- * The alternative design would be to laboriously inject the session into
- * not only this object but also the {@link ObjectStoreInstances} that do
- * the work.
- */
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
- protected SpecificationLoader getSpecificationLookup() {
- return IsisContext.getSpecificationLoader();
- }
-
-
- /**
- * Downcasts the {@link PersistenceSessionFactory} to
- * {@link InMemoryPersistenceSessionFactory}.
- */
- protected InMemoryPersistenceSessionFactory getInMemoryPersistenceSessionFactory() {
- final PersistenceSessionFactory persistenceSessionFactory = getPersistenceSession().getPersistenceSessionFactory();
-
- if (!(persistenceSessionFactory instanceof InMemoryPersistenceSessionFactory)) {
- // for testing support
- return null;
- }
- return (InMemoryPersistenceSessionFactory) persistenceSessionFactory;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryPersistenceMechanismInstaller.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryPersistenceMechanismInstaller.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryPersistenceMechanismInstaller.java
deleted file mode 100644
index e23b93f..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryPersistenceMechanismInstaller.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore;
-
-import java.lang.reflect.Modifier;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapterFactory;
-import org.apache.isis.core.metamodel.spec.ObjectInstantiationException;
-import org.apache.isis.core.metamodel.specloader.classsubstitutor.ClassSubstitutor;
-import org.apache.isis.core.runtime.bytecode.dflt.ClassSubstitutorDefault;
-import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
-import org.apache.isis.core.runtime.persistence.objectfactory.ObjectFactoryAbstract;
-import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
-import org.apache.isis.core.runtime.system.DeploymentType;
-import org.apache.isis.core.runtime.system.persistence.AdapterManagerSpi;
-import org.apache.isis.core.runtime.system.persistence.ObjectFactory;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
-
-/**
- * Installs the in-memory object store.
- */
-public class InMemoryPersistenceMechanismInstaller extends PersistenceMechanismInstallerAbstract {
-
- public static final String NAME = "in-memory";
-
- public InMemoryPersistenceMechanismInstaller() {
- super(NAME);
- }
-
- // ///////////////////////////////////////////////////////////////
- // createPersistenceSessionFactory
- // ///////////////////////////////////////////////////////////////
-
- @Override
- public PersistenceSessionFactory createPersistenceSessionFactory(final DeploymentType deploymentType) {
- return new InMemoryPersistenceSessionFactory(deploymentType, getConfiguration(), this);
- }
-
- // ///////////////////////////////////////////////////////////////
- // Hook methods
- // ///////////////////////////////////////////////////////////////
-
- /**
- * Hook method to return {@link ObjectStoreSpi}.
- */
- @Override
- protected ObjectStoreSpi createObjectStore(final IsisConfiguration configuration, final ObjectAdapterFactory adapterFactory, final AdapterManagerSpi adapterManager) {
- return new InMemoryObjectStore();
- }
-
-
- @Override
- public ObjectFactory createObjectFactory(IsisConfiguration configuration) {
- return new ObjectFactoryBasic();
- }
-
- @Override
- public ClassSubstitutor createClassSubstitutor(IsisConfiguration configuration) {
- return new ClassSubstitutorDefault();
- }
-
-
-}
-
-
-class ObjectFactoryBasic extends ObjectFactoryAbstract {
-
- public ObjectFactoryBasic() {
- }
-
- public ObjectFactoryBasic(final Mode mode) {
- super(mode);
- }
-
- /**
- * Simply instantiates reflectively, does not enhance bytecode etc in any
- * way.
- */
- @Override
- protected <T> T doInstantiate(final Class<T> cls) throws ObjectInstantiationException {
- if (Modifier.isAbstract(cls.getModifiers())) {
- throw new ObjectInstantiationException("Cannot create an instance of an abstract class: " + cls);
- }
- try {
- return cls.newInstance();
- } catch (final IllegalAccessException e) {
- throw new ObjectInstantiationException(e);
- } catch (final InstantiationException e) {
- throw new ObjectInstantiationException(e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryPersistenceSessionFactory.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryPersistenceSessionFactory.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryPersistenceSessionFactory.java
deleted file mode 100644
index b1a38b6..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/InMemoryPersistenceSessionFactory.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.objectstore.internal.ObjectStoreInstances;
-import org.apache.isis.core.objectstore.internal.ObjectStorePersistedObjects;
-import org.apache.isis.core.objectstore.internal.ObjectStorePersistedObjectsDefault;
-import org.apache.isis.core.runtime.persistence.PersistenceSessionFactoryDelegate;
-import org.apache.isis.core.runtime.persistence.PersistenceSessionFactoryDelegating;
-import org.apache.isis.core.runtime.system.DeploymentType;
-import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
-import org.apache.isis.core.runtime.system.persistence.IdentifierGeneratorDefault;
-import org.apache.isis.core.runtime.system.persistence.OidGenerator;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-
-public class InMemoryPersistenceSessionFactory extends PersistenceSessionFactoryDelegating {
-
- private ObjectStorePersistedObjects persistedObjects;
-
- public InMemoryPersistenceSessionFactory(final DeploymentType deploymentType, final IsisConfiguration configuration, final PersistenceSessionFactoryDelegate persistenceSessionFactoryDelegate) {
- super(deploymentType, configuration, persistenceSessionFactoryDelegate);
- }
-
- ObjectStorePersistedObjects getPersistedObjects() {
- return persistedObjects;
- }
-
- @Override
- public PersistenceSession createPersistenceSession() {
- final PersistenceSession persistenceSession = super.createPersistenceSession();
- if (persistedObjects != null) {
- final OidGenerator oidGenerator = persistenceSession.getOidGenerator();
- final IdentifierGenerator identifierGenerator = oidGenerator.getIdentifierGenerator();
- if (identifierGenerator instanceof IdentifierGeneratorDefault) {
- final IdentifierGeneratorDefault identifierGeneratorDefault = (IdentifierGeneratorDefault) identifierGenerator;
- identifierGeneratorDefault.resetTo(persistedObjects.getOidGeneratorMemento());
- }
- }
-
- return persistenceSession;
- }
-
- /**
- * Not API - called when {@link InMemoryObjectStore} first
- * {@link InMemoryObjectStore#open() open}ed.
- */
- public ObjectStorePersistedObjects createPersistedObjects() {
- return new ObjectStorePersistedObjectsDefault();
- }
-
- /**
- * Not API - called when {@link InMemoryObjectStore} is
- * {@link InMemoryObjectStore#close() close}d.
- */
- public void attach(final PersistenceSession persistenceSession, final ObjectStorePersistedObjects persistedObjects) {
- final OidGenerator oidGenerator = persistenceSession.getOidGenerator();
- final IdentifierGenerator identifierGenerator = oidGenerator.getIdentifierGenerator();
- if (identifierGenerator instanceof IdentifierGeneratorDefault) {
- final IdentifierGeneratorDefault identifierGeneratorDefault = (IdentifierGeneratorDefault) identifierGenerator;
- persistedObjects.saveOidGeneratorMemento(identifierGeneratorDefault.getMemento());
- }
- this.persistedObjects = persistedObjects;
- }
-
- @Override
- protected void doShutdown() {
- if (persistedObjects != null) {
- for (final ObjectStoreInstances inst : persistedObjects.instances()) {
- inst.shutdown();
- }
- persistedObjects.clear();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/AbstractInMemoryPersistenceCommand.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/AbstractInMemoryPersistenceCommand.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/AbstractInMemoryPersistenceCommand.java
deleted file mode 100644
index 6937cf6..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/AbstractInMemoryPersistenceCommand.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.core.objectstore.commands;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.objectstore.internal.ObjectStoreInstances;
-import org.apache.isis.core.objectstore.internal.ObjectStorePersistedObjects;
-import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandAbstract;
-
-public abstract class AbstractInMemoryPersistenceCommand extends PersistenceCommandAbstract {
-
- private final static Logger LOG = LoggerFactory.getLogger(AbstractInMemoryPersistenceCommand.class);
-
- private final ObjectStorePersistedObjects persistedObjects;
-
- public AbstractInMemoryPersistenceCommand(final ObjectAdapter adapter, final ObjectStorePersistedObjects persistedObjects) {
- super(adapter);
- this.persistedObjects = persistedObjects;
- }
-
- protected void save(final ObjectAdapter adapter) throws ObjectPersistenceException {
- final ObjectSpecification specification = adapter.getSpecification();
- if (LOG.isDebugEnabled()) {
- LOG.debug(" saving object " + adapter + " as instance of " + specification.getShortIdentifier());
- }
- final ObjectStoreInstances ins = instancesFor(specification.getSpecId());
- ins.save(adapter); // also sets the version
- }
-
- protected void destroy(final ObjectAdapter adapter) {
- final ObjectSpecification specification = adapter.getSpecification();
- if (LOG.isDebugEnabled()) {
- LOG.debug(" destroy object " + adapter + " as instance of " + specification.getShortIdentifier());
- }
- final ObjectStoreInstances ins = instancesFor(specification.getSpecId());
- ins.remove(adapter.getOid());
- }
-
- private ObjectStoreInstances instancesFor(final ObjectSpecId spec) {
- return persistedObjects.instancesFor(spec);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemoryCreateObjectCommand.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemoryCreateObjectCommand.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemoryCreateObjectCommand.java
deleted file mode 100644
index efab9de..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemoryCreateObjectCommand.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.commands;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.objectstore.internal.ObjectStorePersistedObjects;
-import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.CreateObjectCommand;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-
-public final class InMemoryCreateObjectCommand extends AbstractInMemoryPersistenceCommand implements CreateObjectCommand {
- private final static Logger LOG = LoggerFactory.getLogger(InMemoryCreateObjectCommand.class);
-
- public InMemoryCreateObjectCommand(final ObjectAdapter object, final ObjectStorePersistedObjects persistedObjects) {
- super(object, persistedObjects);
- }
-
- @Override
- public void execute(final PersistenceCommandContext context) throws ObjectPersistenceException {
- if (LOG.isDebugEnabled()) {
- LOG.debug(" create object " + onAdapter());
- }
- save(onAdapter());
- }
-
- @Override
- public String toString() {
- return "CreateObjectCommand [object=" + onAdapter() + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemoryDestroyObjectCommand.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemoryDestroyObjectCommand.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemoryDestroyObjectCommand.java
deleted file mode 100644
index 18d6b0c..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemoryDestroyObjectCommand.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.commands;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.objectstore.internal.ObjectStorePersistedObjects;
-import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-
-public final class InMemoryDestroyObjectCommand extends AbstractInMemoryPersistenceCommand implements DestroyObjectCommand {
- private final static Logger LOG = LoggerFactory.getLogger(InMemoryDestroyObjectCommand.class);
-
- public InMemoryDestroyObjectCommand(final ObjectAdapter adapter, final ObjectStorePersistedObjects persistedObjects) {
- super(adapter, persistedObjects);
- }
-
- @Override
- public void execute(final PersistenceCommandContext context) throws ObjectPersistenceException {
- if (LOG.isInfoEnabled()) {
- LOG.info(" delete object '" + onAdapter() + "'");
- }
- destroy(onAdapter());
- }
-
- @Override
- public String toString() {
- return "DestroyObjectCommand [object=" + onAdapter() + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemorySaveObjectCommand.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemorySaveObjectCommand.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemorySaveObjectCommand.java
deleted file mode 100644
index 789b86f..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/commands/InMemorySaveObjectCommand.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.commands;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.objectstore.internal.ObjectStorePersistedObjects;
-import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.SaveObjectCommand;
-
-public final class InMemorySaveObjectCommand extends AbstractInMemoryPersistenceCommand implements SaveObjectCommand {
-
- @SuppressWarnings("unused")
- private final static Logger LOG = LoggerFactory.getLogger(InMemorySaveObjectCommand.class);
-
- public InMemorySaveObjectCommand(final ObjectAdapter object, final ObjectStorePersistedObjects persistedObjects) {
- super(object, persistedObjects);
- }
-
- @Override
- public void execute(final PersistenceCommandContext context) throws ObjectPersistenceException {
- save(onAdapter());
- }
-
- @Override
- public String toString() {
- return "SaveObjectCommand [object=" + onAdapter() + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances.java
deleted file mode 100644
index 3a6ea23..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.internal;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.isis.applib.clock.Clock;
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.debug.DebugBuilder;
-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.version.SerialNumberVersion;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.objectstore.InMemoryObjectStore;
-import org.apache.isis.core.runtime.persistence.query.PersistenceQueryBuiltIn;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.AdapterManagerSpi;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-
-/*
- * The objects need to store in a repeatable sequence so the elements and instances method return the same data for any repeated
- * call, and so that one subset of instances follows on the previous. This is done by keeping the objects in the order that they
- * where created.
- */
-public class ObjectStoreInstances {
-
- private final Map<Oid, Object> pojoByOidMap = new HashMap<Oid, Object>();
- private final Map<Oid, Version> versionByOidMap = new HashMap<Oid, Version>();
-
- @SuppressWarnings("unused")
- private final ObjectSpecId spec;
-
- // ///////////////////////////////////////////////////////
- // Constructors
- // ///////////////////////////////////////////////////////
-
- public ObjectStoreInstances(final ObjectSpecId spec) {
- this.spec = spec;
- }
-
- // ///////////////////////////////////////////////////////
- // Object Instances
- // ///////////////////////////////////////////////////////
-
- /**
- * TODO: shouldn't really be exposing this directly.
- */
- public Map<Oid, Object> getObjectInstances() {
- return pojoByOidMap;
- }
-
- public Set<Oid> getOids() {
- return Collections.unmodifiableSet(pojoByOidMap.keySet());
- }
-
- public Object getPojo(final Oid oid) {
- return pojoByOidMap.get(oid);
- }
-
- public Version getVersion(final Oid oid) {
- return versionByOidMap.get(oid);
- }
-
- // ///////////////////////////////////////////////////////
- // shutdown
- // ///////////////////////////////////////////////////////
-
- public void shutdown() {
- pojoByOidMap.clear();
- versionByOidMap.clear();
- }
-
- // ///////////////////////////////////////////////////////
- // save, remove
- // ///////////////////////////////////////////////////////
-
- public void save(final ObjectAdapter adapter) {
- pojoByOidMap.put(adapter.getOid(), adapter.getObject());
-
- final Version version = versionByOidMap.get(adapter.getOid());
- final Version nextVersion = nextVersion(version);
- versionByOidMap.put(adapter.getOid(), nextVersion);
- adapter.setVersion(nextVersion);
- }
-
- private synchronized Version nextVersion(final Version version) {
- final long sequence = (version != null ? version.getSequence() : 0) + 1;
- return SerialNumberVersion.create(sequence, getAuthenticationSession().getUserName(), new Date(Clock.getTime()));
- }
-
- public void remove(final Oid oid) {
- pojoByOidMap.remove(oid);
- versionByOidMap.remove(oid);
- }
-
- // ///////////////////////////////////////////////////////
- // retrieveObject
- // ///////////////////////////////////////////////////////
-
- /**
- * If the pojo exists in the object store, then looks up the
- * {@link ObjectAdapter adapter} from the {@link AdapterManagerSpi}, and only
- * if none found does it
- * {@link PersistenceSessionHydrator#mapRecreatedPojo(Object, Object) recreate}
- * a new {@link ObjectAdapter adapter}.
- */
- public ObjectAdapter getObjectAndMapIfRequired(final Oid oid) {
- final Object pojo = getObjectInstances().get(oid);
- if (pojo == null) {
- return null;
- }
- final ObjectAdapter adapterLookedUpByPojo = getAdapterManager().getAdapterFor(pojo);
- if (adapterLookedUpByPojo != null) {
- return adapterLookedUpByPojo;
- }
- final ObjectAdapter adapterLookedUpByOid = getAdapterManager().getAdapterFor(oid);
- if (adapterLookedUpByOid != null) {
- return adapterLookedUpByOid;
- }
- return getPersistenceSession().mapRecreatedPojo(oid, pojo);
- }
-
- // ///////////////////////////////////////////////////////
- // instances, numberOfInstances, hasInstances
- // ///////////////////////////////////////////////////////
-
- /**
- * Not API, but <tt>public</tt> so can be called by
- * {@link InMemoryObjectStore}.
- */
- public void findInstancesAndAdd(final PersistenceQueryBuiltIn persistenceQuery, final List<ObjectAdapter> foundInstances) {
- for (final ObjectAdapter element : elements()) {
- if (persistenceQuery.matches(element)) {
- foundInstances.add(element);
- }
- }
- }
-
- public int numberOfInstances() {
- return getObjectInstances().size();
- }
-
- public boolean hasInstances() {
- return numberOfInstances() > 0;
- }
-
- private List<ObjectAdapter> elements() {
- final List<ObjectAdapter> v = new ArrayList<ObjectAdapter>(getObjectInstances().size());
- for (final Oid oid : getObjectInstances().keySet()) {
- v.add(getObjectAndMapIfRequired(oid));
- }
- return v;
- }
-
- // ///////////////////////////////////////////////////////
- // Debugging
- // ///////////////////////////////////////////////////////
-
- public void debugData(final DebugBuilder debug) {
- debug.indent();
- if (getObjectInstances().size() == 0) {
- debug.appendln("no instances");
- }
- for (final Oid oid : getObjectInstances().keySet()) {
- final ObjectAdapter objectAdapter = getObjectAndMapIfRequired(oid);
- final String title = objectAdapter.titleString();
- final Object object = getObjectInstances().get(oid);
- debug.appendln(oid.toString(), object + " (" + title + ")");
- }
- debug.appendln();
- debug.unindent();
- }
-
- // ///////////////////////////////////////////////////////
- // Dependencies (from context)
- // ///////////////////////////////////////////////////////
-
- /**
- * Must use {@link IsisContext context}, because although this object is
- * recreated with each {@link PersistenceSession session}, the persisted
- * objects that get
- * {@link #attachPersistedObjects(MemoryObjectStorePersistedObjects)
- * attached} to it span multiple sessions.
- *
- * <p>
- * The alternative design would be to laboriously inject this object via the
- * {@link InMemoryObjectStore}.
- */
- protected PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- /**
- * Must use {@link IsisContext context}, because although this object is
- * recreated with each {@link PersistenceSession session}, the persisted
- * objects that get
- * {@link #attachPersistedObjects(MemoryObjectStorePersistedObjects)
- * attached} to it span multiple sessions.
- *
- * <p>
- * The alternative design would be to laboriously inject this object via the
- * {@link InMemoryObjectStore}.
- */
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
- /**
- * Must use {@link IsisContext context}, because although this object is
- * recreated with each {@link PersistenceSession session}, the persisted
- * objects that get
- * {@link #attachPersistedObjects(MemoryObjectStorePersistedObjects)
- * attached} to it span multiple sessions.
- *
- * <p>
- * The alternative design would be to laboriously inject this object via the
- * {@link InMemoryObjectStore}.
- */
- protected AuthenticationSession getAuthenticationSession() {
- return IsisContext.getAuthenticationSession();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjects.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjects.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjects.java
deleted file mode 100644
index 85dffcb..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjects.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.internal;
-
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.runtime.system.persistence.IdentifierGeneratorDefault;
-
-/**
- * Represents the persisted objects.
- *
- * Attached and detached to each session.
- */
-public interface ObjectStorePersistedObjects {
-
- public IdentifierGeneratorDefault.Memento getOidGeneratorMemento();
-
- public void saveOidGeneratorMemento(IdentifierGeneratorDefault.Memento memento);
-
- public void registerService(ObjectSpecId objectSpecId, Oid oid);
-
- public Oid getService(ObjectSpecId objectSpecId);
-
- public Iterable<ObjectSpecId> specifications();
-
- public ObjectStoreInstances instancesFor(ObjectSpecId spec);
-
- public Iterable<ObjectStoreInstances> instances();
-
- public void clear();
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault.java b/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault.java
deleted file mode 100644
index 33d06a0..0000000
--- a/core/objectstore-inmemory/src/main/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.internal;
-
-import java.util.Map;
-import java.util.Set;
-
-import com.google.common.collect.Maps;
-
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.runtime.system.persistence.IdentifierGeneratorDefault;
-
-/**
- * Represents the persisted objects.
- *
- * Attached and detached to each session.
- */
-public class ObjectStorePersistedObjectsDefault implements ObjectStorePersistedObjects {
-
- private final Map<ObjectSpecId, ObjectStoreInstances> instancesBySpecMap = Maps.newHashMap();
- private final Map<ObjectSpecId, Oid> serviceOidByIdMap = Maps.newHashMap();
-
- private IdentifierGeneratorDefault.Memento oidGeneratorMemento;
-
-
- @Override
- public IdentifierGeneratorDefault.Memento getOidGeneratorMemento() {
- return oidGeneratorMemento;
- }
-
- @Override
- public void saveOidGeneratorMemento(final IdentifierGeneratorDefault.Memento memento) {
- this.oidGeneratorMemento = memento;
- }
-
- @Override
- public Oid getService(final ObjectSpecId objectSpecId) {
- return serviceOidByIdMap.get(objectSpecId);
- }
-
- @Override
- public void registerService(final ObjectSpecId objectSpecId, final Oid oid) {
- final Oid oidLookedUpByName = serviceOidByIdMap.get(objectSpecId);
- if (oidLookedUpByName != null) {
- if (oidLookedUpByName.equals(oid)) {
- throw new IsisException("Already another service registered as name: " + objectSpecId + " (existing Oid: " + oidLookedUpByName + ", " + "intended: " + oid + ")");
- }
- } else {
- serviceOidByIdMap.put(objectSpecId, oid);
- }
- }
-
- // TODO: this is where the clever logic needs to go to determine how to save
- // into our custom Map.
- // also think we shouldn't surface the entire Map, just the API we require
- // (keySet, values etc).
- @Override
- public ObjectStoreInstances instancesFor(final ObjectSpecId specId) {
- ObjectStoreInstances ins = instancesBySpecMap.get(specId);
- if (ins == null) {
- ins = new ObjectStoreInstances(specId);
- instancesBySpecMap.put(specId, ins);
- }
- return ins;
- }
-
- @Override
- public Iterable<ObjectSpecId> specifications() {
- return instancesBySpecMap.keySet();
- }
-
- @Override
- public void clear() {
- instancesBySpecMap.clear();
- }
-
- @Override
- public Iterable<ObjectStoreInstances> instances() {
- return instancesBySpecMap.values();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_findInstancesAndAdd.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_findInstancesAndAdd.java b/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_findInstancesAndAdd.java
deleted file mode 100644
index e1835b6..0000000
--- a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_findInstancesAndAdd.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.internal;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.List;
-
-import com.google.common.collect.Lists;
-
-import org.jmock.Expectations;
-import org.jmock.auto.Mock;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.matchers.IsisMatchers;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.runtime.persistence.query.PersistenceQueryBuiltIn;
-import org.apache.isis.core.runtime.system.persistence.AdapterManagerSpi;
-import org.apache.isis.core.unittestsupport.jmocking.IsisActions;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
-
-public class ObjectStoreInstances_findInstancesAndAdd {
-
- private ObjectStoreInstances instances;
-
- @Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
-
- @Mock
- private ObjectSpecId mockSpecId;
- @Mock
- private PersistenceQueryBuiltIn mockPersistenceQueryBuiltIn;
- @Mock
- private AuthenticationSession mockAuthSession;
- @Mock
- private AdapterManagerSpi mockAdapterManager;
-
- @Mock
- private ObjectAdapter mockAdapter1;
- @Mock
- private ObjectAdapter mockAdapter2;
-
- @Before
- public void setUp() throws Exception {
- instances = new ObjectStoreInstances(mockSpecId) {
- @Override
- protected AuthenticationSession getAuthenticationSession() {
- return mockAuthSession;
- }
- @Override
- protected AdapterManagerSpi getAdapterManager() {
- return mockAdapterManager;
- }
- };
- context.ignoring(mockAuthSession);
- }
-
- @Test
- public void findInstancesAndAdd_whenEmpty() throws Exception {
- context.never(mockPersistenceQueryBuiltIn);
- final List<ObjectAdapter> foundInstances = Lists.newArrayList();
- instances.findInstancesAndAdd(mockPersistenceQueryBuiltIn, foundInstances);
- }
-
- @Test
- public void findInstancesAndAdd_whenNotEmpty() throws Exception {
- context.ignoring(mockAdapter1, mockAdapter2);
- context.checking(new Expectations() {
- {
- one(mockPersistenceQueryBuiltIn).matches(mockAdapter1);
- will(returnValue(false));
-
- one(mockPersistenceQueryBuiltIn).matches(mockAdapter2);
- will(returnValue(true));
-
- allowing(mockAdapterManager).getAdapterFor(with(any(Object.class)));
- will(IsisActions.returnEach(mockAdapter1, mockAdapter2));
- }
- });
-
- instances.save(mockAdapter1);
- instances.save(mockAdapter2);
-
- final List<ObjectAdapter> foundInstances = Lists.newArrayList();
- instances.findInstancesAndAdd(mockPersistenceQueryBuiltIn, foundInstances);
-
- assertThat(foundInstances.size(), is(1));
- assertThat(foundInstances, IsisMatchers.listContaining(mockAdapter2));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_init.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_init.java b/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_init.java
deleted file mode 100644
index cd2c384..0000000
--- a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_init.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.internal;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-
-/**
- * Tested in style of <i>Working Effectively with Legacy Code</i> (Feathers) and
- * <i>Growing Object-Oriented Software</i> (Freeman & Pryce).
- */
-@RunWith(JMock.class)
-public class ObjectStoreInstances_init {
-
- private ObjectStoreInstances instances;
-
- private final Mockery context = new JUnit4Mockery();
-
- private ObjectSpecId mockSpecId;
-
- @Before
- public void setUp() throws Exception {
- mockSpecId = context.mock(ObjectSpecId.class);
- instances = new ObjectStoreInstances(mockSpecId);
- }
-
- @Test
- public void initiallyEmpty() throws Exception {
- final Map<Oid, Object> objectInstances = instances.getObjectInstances();
- assertThat(objectInstances.size(), is(0));
-
- final Set<Oid> oids = instances.getOids();
- assertThat(oids.size(), is(0));
-
- assertThat(instances.hasInstances(), is(false));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_save.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_save.java b/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_save.java
deleted file mode 100644
index 9d93d54..0000000
--- a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStoreInstances_save.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.internal;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-
-@RunWith(JMock.class)
-public class ObjectStoreInstances_save {
-
- private ObjectStoreInstances instances;
-
- private final Mockery context = new JUnit4Mockery();
-
- private ObjectSpecId mockSpecId;
- private ObjectAdapter mockAdapter;
- private AuthenticationSession mockAuthSession;
-
- @Before
- public void setUp() throws Exception {
- mockSpecId = context.mock(ObjectSpecId.class);
- mockAdapter = context.mock(ObjectAdapter.class);
- mockAuthSession = context.mock(AuthenticationSession.class);
- instances = new ObjectStoreInstances(mockSpecId) {
- @Override
- protected AuthenticationSession getAuthenticationSession() {
- return mockAuthSession;
- }
- };
- ignoreAuthenticationSession();
- }
-
- private void ignoreAuthenticationSession() {
- context.checking(new Expectations() {
- {
- ignoring(mockAuthSession);
- }
- });
- }
-
- @Test
- public void saveUpdatesTheOptimisticLock() throws Exception {
- allowingGetOidAndGetObjectAndTitleStringFromAdapter();
- context.checking(new Expectations() {
- {
- one(mockAdapter).setVersion(with(any(Version.class)));
- }
- });
- instances.save(mockAdapter);
-
- }
-
- @Test
- public void saveStoresObject() throws Exception {
- allowingGetOidAndGetObjectAndTitleStringFromAdapter();
- ignoringInteractionsWithAdapter();
- instances.save(mockAdapter);
-
- final Map<Oid, Object> objectInstances = instances.getObjectInstances();
- assertThat(objectInstances.size(), is(1));
-
- final Set<Oid> oids = instances.getOids();
- assertThat(oids.size(), is(1));
-
- assertThat(instances.hasInstances(), is(true));
-
- }
-
- private void ignoringInteractionsWithAdapter() {
- context.checking(new Expectations() {
- {
- ignoring(mockAdapter);
- }
- });
- }
-
- private void allowingGetOidAndGetObjectAndTitleStringFromAdapter() {
- context.checking(new Expectations() {
- {
- allowing(mockAdapter).getOid();
- allowing(mockAdapter).getObject();
- allowing(mockAdapter).titleString();
- }
- });
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault_instances.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault_instances.java b/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault_instances.java
deleted file mode 100644
index 9227c14..0000000
--- a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault_instances.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.internal;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-
-@RunWith(JMock.class)
-public class ObjectStorePersistedObjectsDefault_instances {
-
- private ObjectStorePersistedObjectsDefault persistedObjects;
-
- private final Mockery context = new JUnit4Mockery();
-
- private ObjectSpecId mockSpec;
-
- @Before
- public void setUp() throws Exception {
- persistedObjects = new ObjectStorePersistedObjectsDefault();
- mockSpec = context.mock(ObjectSpecId.class);
- }
-
- @Test
- public void instancesLazilyPopulatedWhenAskForThem() throws Exception {
- neverInteractsWithSpec();
-
- // no instances
- final Iterable<ObjectStoreInstances> instancesBefore = persistedObjects.instances();
- assertThat(instancesBefore.iterator().hasNext(), is(false));
-
- ensureThereAreSomeInstances();
-
- // now there are
- final Iterable<ObjectStoreInstances> instancesAfter = persistedObjects.instances();
- assertThat(instancesAfter.iterator().hasNext(), is(true));
- }
-
- @Test
- public void clearZapsTheInstances() throws Exception {
- neverInteractsWithSpec();
-
- ensureThereAreSomeInstances();
- final Iterable<ObjectStoreInstances> instancesAfter = persistedObjects.instances();
- assertThat(instancesAfter.iterator().hasNext(), is(true));
-
- persistedObjects.clear();
-
- // now there are no more instances
- final Iterable<ObjectStoreInstances> instancesBefore = persistedObjects.instances();
- assertThat(instancesBefore.iterator().hasNext(), is(false));
- }
-
- private void ensureThereAreSomeInstances() {
- persistedObjects.instancesFor(mockSpec);
- }
-
- private void neverInteractsWithSpec() {
- context.checking(new Expectations() {
- {
- never(mockSpec);
- }
- });
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/f4b90213/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault_savesOidGeneratorAsMemento.java
----------------------------------------------------------------------
diff --git a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault_savesOidGeneratorAsMemento.java b/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault_savesOidGeneratorAsMemento.java
deleted file mode 100644
index e41d2f8..0000000
--- a/core/objectstore-inmemory/src/test/java/org/apache/isis/core/objectstore/internal/ObjectStorePersistedObjectsDefault_savesOidGeneratorAsMemento.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.objectstore.internal;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.apache.isis.core.runtime.system.persistence.IdentifierGeneratorDefault;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-
-public class ObjectStorePersistedObjectsDefault_savesOidGeneratorAsMemento {
-
- private ObjectStorePersistedObjectsDefault persistedObjects;
-
- @Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES);
-
- private IdentifierGeneratorDefault.Memento mockMemento;
-
- @Before
- public void setUp() throws Exception {
- persistedObjects = new ObjectStorePersistedObjectsDefault();
- mockMemento = context.mock(IdentifierGeneratorDefault.Memento.class);
- }
-
- @Test
- public void noOidGeneratorInitially() throws Exception {
- final IdentifierGeneratorDefault.Memento oidGeneratorMemento = persistedObjects.getOidGeneratorMemento();
- assertThat(oidGeneratorMemento, is(nullValue()));
- }
-
- @Test
- public void oidGeneratorStoredOnceSaved() throws Exception {
- persistedObjects.saveOidGeneratorMemento(mockMemento);
- final IdentifierGeneratorDefault.Memento oidGeneratorMemento = persistedObjects.getOidGeneratorMemento();
- assertThat(oidGeneratorMemento, is(mockMemento));
- }
-
-}