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/13 01:01:06 UTC

[14/52] [partial] ISIS-188: renaming packages in line with groupId:artifactId

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/object/persistencecapable/GivenJdoPersistenceCapableAnnotationFacetFactoryTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/object/persistencecapable/GivenJdoPersistenceCapableAnnotationFacetFactoryTest.java b/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/object/persistencecapable/GivenJdoPersistenceCapableAnnotationFacetFactoryTest.java
deleted file mode 100644
index c6984ff..0000000
--- a/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/object/persistencecapable/GivenJdoPersistenceCapableAnnotationFacetFactoryTest.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.apache.isis.runtimes.dflt.objectstores.jdo.metamodel.facets.object.persistencecapable;
-
-import java.util.List;
-
-import javax.jdo.annotations.IdentityType;
-import javax.jdo.annotations.PersistenceCapable;
-
-import junit.framework.Assert;
-
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.FeatureType;
-import org.apache.isis.core.metamodel.facets.FacetFactory;
-import org.apache.isis.core.progmodel.facets.AbstractFacetFactoryTest;
-import org.apache.isis.runtimes.dflt.objectstores.jdo.metamodel.facets.object.persistencecapable.JdoPersistenceCapableAnnotationFacetFactory;
-import org.apache.isis.runtimes.dflt.objectstores.jdo.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacet;
-import org.apache.isis.runtimes.dflt.objectstores.jdo.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacetAnnotation;
-
-
-public class GivenJdoPersistenceCapableAnnotationFacetFactoryTest extends
-        AbstractFacetFactoryTest {
-
-    private JdoPersistenceCapableAnnotationFacetFactory facetFactory;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        facetFactory = new JdoPersistenceCapableAnnotationFacetFactory();
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        facetFactory = null;
-        super.tearDown();
-    }
-
-    public void testFeatureTypes() {
-        final List<FeatureType> featureTypes = facetFactory
-                .getFeatureTypes();
-        Assert
-                .assertTrue(contains(featureTypes,
-                FeatureType.OBJECT));
-        assertFalse(contains(featureTypes,
-                FeatureType.PROPERTY));
-        assertFalse(contains(featureTypes,
-                FeatureType.COLLECTION));
-        Assert
-                .assertFalse(contains(featureTypes,
-                FeatureType.ACTION));
-        assertFalse(contains(featureTypes,
-                FeatureType.ACTION_PARAMETER));
-    }
-
-    public void testPersistenceCapableAnnotationPickedUpOnClass() {
-        @PersistenceCapable
-        class Customer {
-        }
-
-        facetFactory.process(new FacetFactory.ProcessClassContext(Customer.class, methodRemover, facetHolder));
-
-        final Facet facet = facetHolder.getFacet(JdoPersistenceCapableFacet.class);
-        assertNotNull(facet);
-        assertTrue(facet instanceof JdoPersistenceCapableFacetAnnotation);
-    }
-
-    public void testIfNoPersistenceCapableAnnotationThenNoFacet() {
-
-        class Customer {
-        }
-
-        facetFactory.process(new FacetFactory.ProcessClassContext(Customer.class, methodRemover, facetHolder));
-
-        final Facet facet = facetHolder.getFacet(JdoPersistenceCapableFacet.class);
-        assertNull(facet);
-    }
-
-    public void testEntityAnnotationWithNoExplicitNameDefaultsToClassName() {
-        @PersistenceCapable()
-        class Customer {
-        }
-        facetFactory.process(new FacetFactory.ProcessClassContext(Customer.class, methodRemover, facetHolder));
-
-        final JdoPersistenceCapableFacet entityFacet = facetHolder
-                .getFacet(JdoPersistenceCapableFacet.class);
-        assertEquals("Customer", entityFacet.getTable());
-    }
-
-    public void testPersistenceCapableAnnotationWithNoExplicitIdentityTypeDefaultsToUnspecified() {
-        @PersistenceCapable()
-        class Customer {
-        }
-        facetFactory.process(new FacetFactory.ProcessClassContext(Customer.class, methodRemover, facetHolder));
-
-        final JdoPersistenceCapableFacet entityFacet = facetHolder
-                .getFacet(JdoPersistenceCapableFacet.class);
-        assertEquals(IdentityType.UNSPECIFIED, entityFacet.getIdentityType());
-    }
-
-    public void testPersistenceCapableAnnotationWithExplicitNameAttributeProvided() {
-        @PersistenceCapable(table = "CUS_CUSTOMER")
-        class Customer {
-        }
-
-        facetFactory.process(new FacetFactory.ProcessClassContext(Customer.class, methodRemover, facetHolder));
-
-        final JdoPersistenceCapableFacet entityFacet = facetHolder
-                .getFacet(JdoPersistenceCapableFacet.class);
-        assertEquals("CUS_CUSTOMER", entityFacet.getTable());
-    }
-
-    public void testPersistenceCapableAnnotationWithExplicitIdentityTypeAttributeProvided() {
-        @PersistenceCapable(identityType=IdentityType.DATASTORE)
-        class Customer {
-        }
-
-        facetFactory.process(new FacetFactory.ProcessClassContext(Customer.class, methodRemover, facetHolder));
-
-        final JdoPersistenceCapableFacet entityFacet = facetHolder
-                .getFacet(JdoPersistenceCapableFacet.class);
-        assertEquals(IdentityType.DATASTORE, entityFacet.getIdentityType());
-    }
-
-    public void testNoMethodsRemoved() {
-        @PersistenceCapable
-        class Customer {
-        }
-
-        facetFactory.process(new FacetFactory.ProcessClassContext(Customer.class, methodRemover, facetHolder));
-
-        assertNoMethodsRemoved();
-    }
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/prop/primarykey/GivenJdoPrimaryKeyAnnotationFacetFactoryTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/prop/primarykey/GivenJdoPrimaryKeyAnnotationFacetFactoryTest.java b/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/prop/primarykey/GivenJdoPrimaryKeyAnnotationFacetFactoryTest.java
deleted file mode 100644
index fe0f5e7..0000000
--- a/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/prop/primarykey/GivenJdoPrimaryKeyAnnotationFacetFactoryTest.java
+++ /dev/null
@@ -1,138 +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.runtimes.dflt.objectstores.jdo.metamodel.facets.prop.primarykey;
-
-import java.lang.reflect.Method;
-import java.util.List;
-
-import javax.jdo.annotations.PrimaryKey;
-
-import junit.framework.Assert;
-
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.FeatureType;
-import org.apache.isis.core.metamodel.facets.FacetFactory;
-import org.apache.isis.core.metamodel.facets.mandatory.MandatoryFacet;
-import org.apache.isis.core.progmodel.facets.AbstractFacetFactoryTest;
-import org.apache.isis.core.progmodel.facets.members.disabled.DisabledFacet;
-
-public class GivenJdoPrimaryKeyAnnotationFacetFactoryTest extends AbstractFacetFactoryTest {
-
-    private JdoPrimaryKeyAnnotationFacetFactory facetFactory;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        facetFactory = new JdoPrimaryKeyAnnotationFacetFactory();
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        facetFactory = null;
-        super.tearDown();
-    }
-
-    public void testFeatureTypes() {
-        final List<FeatureType> featureTypes = facetFactory.getFeatureTypes();
-        Assert.assertFalse(contains(featureTypes, FeatureType.OBJECT));
-        assertTrue(contains(featureTypes, FeatureType.PROPERTY));
-        assertFalse(contains(featureTypes, FeatureType.COLLECTION));
-        Assert.assertFalse(contains(featureTypes, FeatureType.ACTION));
-        assertFalse(contains(featureTypes, FeatureType.ACTION_PARAMETER));
-    }
-
-    public void testIdAnnotationPickedUpOnProperty() throws Exception {
-        final Class<?> cls = SimpleObjectWithPrimaryKey.class;
-        final Method method = cls.getMethod("getId");
-        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, method, methodRemover, facetedMethod));
-
-        final Facet facet = facetedMethod.getFacet(JdoPrimaryKeyFacet.class);
-        assertNotNull(facet);
-        assertTrue(facet instanceof JdoPrimaryKeyFacet);
-    }
-
-    public void testOptionalDerivedFromId() throws Exception {
-        final Class<?> cls = SimpleObjectWithPrimaryKey.class;
-        final Method method = cls.getMethod("getId");
-        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, method, methodRemover, facetedMethod));
-
-        final Facet facet = facetedMethod.getFacet(MandatoryFacet.class);
-        assertNotNull(facet);
-        Assert.assertTrue(facet instanceof OptionalFacetDerivedFromJdoPrimaryKeyAnnotation);
-    }
-
-    public void testDisabledDerivedFromId() throws Exception {
-        final Class<?> cls = SimpleObjectWithPrimaryKey.class;
-        final Method method = cls.getMethod("getId");
-        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, method, methodRemover, facetedMethod));
-
-        final Facet facet = facetedMethod.getFacet(DisabledFacet.class);
-        assertNotNull(facet);
-        Assert.assertTrue(facet instanceof DisabledFacetDerivedFromJdoPrimaryKeyAnnotation);
-    }
-
-    public void testIfNoIdAnnotationThenNoFacet() throws Exception {
-
-        class Customer {
-            private Long id;
-
-            // @Id missing
-            @SuppressWarnings("unused")
-            public Long getId() {
-                return id;
-            }
-
-            @SuppressWarnings("unused")
-            public void setId(final Long id) {
-                this.id = id;
-            }
-        }
-
-        final Class<?> cls = Customer.class;
-        final Method method = cls.getMethod("getId");
-        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, method, methodRemover, facetedMethod));
-
-        final Facet facet = facetedMethod.getFacet(JdoPrimaryKeyFacet.class);
-        assertNull(facet);
-    }
-
-    public void testNoMethodsRemoved() throws Exception {
-        class Customer {
-            private Long id;
-
-            @SuppressWarnings("unused")
-            @PrimaryKey
-            public Long getId() {
-                return id;
-            }
-
-            @SuppressWarnings("unused")
-            public void setId(final Long id) {
-                this.id = id;
-            }
-        }
-
-        final Class<?> cls = Customer.class;
-        final Method method = cls.getMethod("getId");
-        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, method, methodRemover, facetedMethod));
-
-        assertNoMethodsRemoved();
-    }
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/prop/primarykey/SimpleObjectWithPrimaryKey.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/prop/primarykey/SimpleObjectWithPrimaryKey.java b/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/prop/primarykey/SimpleObjectWithPrimaryKey.java
deleted file mode 100644
index dc69b32..0000000
--- a/component/objectstore/jdo/jdo-metamodel/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/metamodel/facets/prop/primarykey/SimpleObjectWithPrimaryKey.java
+++ /dev/null
@@ -1,36 +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.runtimes.dflt.objectstores.jdo.metamodel.facets.prop.primarykey;
-
-import javax.jdo.annotations.PrimaryKey;
-
-
-public class SimpleObjectWithPrimaryKey {
-
-    private Long id;
-
-    @PrimaryKey
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(final Long id) {
-        this.id = id;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlCommandContext.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlCommandContext.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlCommandContext.java
new file mode 100644
index 0000000..f95de8b
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlCommandContext.java
@@ -0,0 +1,35 @@
+/*
+ *  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.objectstore.nosql;
+
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+import org.apache.isis.objectstore.nosql.db.StateWriter;
+
+public interface NoSqlCommandContext extends PersistenceCommandContext {
+
+    StateWriter createStateWriter(ObjectSpecId objectSpecId);
+
+    void insert(StateWriter writer);
+    void update(StateWriter writer);
+
+    void delete(ObjectSpecId objectSpecId, String key, String version, Oid oid);
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlCreateObjectCommand.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlCreateObjectCommand.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlCreateObjectCommand.java
new file mode 100644
index 0000000..2be121b
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlCreateObjectCommand.java
@@ -0,0 +1,32 @@
+/*
+ *  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.objectstore.nosql;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.CreateObjectCommand;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+import org.apache.isis.objectstore.nosql.versions.VersionCreator;
+
+final class NoSqlCreateObjectCommand extends WriteObjectCommand implements CreateObjectCommand {
+
+    public NoSqlCreateObjectCommand(final VersionCreator versionCreator, final DataEncryption dataEncrypter, final ObjectAdapter object) {
+        super(Mode.NON_UPDATE, versionCreator, dataEncrypter, object);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlDestroyObjectCommand.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlDestroyObjectCommand.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlDestroyObjectCommand.java
new file mode 100644
index 0000000..3cdd318
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlDestroyObjectCommand.java
@@ -0,0 +1,64 @@
+/*
+ *  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.objectstore.nosql;
+
+import org.apache.isis.core.commons.lang.ToString;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+import org.apache.isis.objectstore.nosql.keys.KeyCreatorDefault;
+import org.apache.isis.objectstore.nosql.versions.VersionCreator;
+
+final class NoSqlDestroyObjectCommand implements DestroyObjectCommand {
+    
+    private final KeyCreatorDefault keyCreator = new KeyCreatorDefault();
+    
+    private final ObjectAdapter adapter;
+    private final VersionCreator versionCreator;
+
+    public NoSqlDestroyObjectCommand(final VersionCreator versionCreator, final ObjectAdapter adapter) {
+        this.versionCreator = versionCreator;
+        this.adapter = adapter;
+    }
+
+    @Override
+    public void execute(final PersistenceCommandContext context) {
+        final String key = keyCreator.getIdentifierForPersistentRoot(adapter.getOid());
+        final String version = versionCreator.versionString(adapter.getVersion());
+        final ObjectSpecification objectSpec = adapter.getSpecification();
+
+        final NoSqlCommandContext noSqlCommandContext = (NoSqlCommandContext) context;
+        noSqlCommandContext.delete(objectSpec.getSpecId(), key, version, adapter.getOid());
+    }
+
+    @Override
+    public ObjectAdapter onAdapter() {
+        return adapter;
+    }
+
+    @Override
+    public String toString() {
+        final ToString toString = new ToString(this);
+        toString.append("spec", adapter.getSpecification().getFullIdentifier());
+        toString.append("oid", adapter.getOid());
+        return toString.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlIdentifierGenerator.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlIdentifierGenerator.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlIdentifierGenerator.java
new file mode 100644
index 0000000..a07dd2d
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlIdentifierGenerator.java
@@ -0,0 +1,147 @@
+/*
+ *  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.objectstore.nosql;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.ensure.Assert;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
+import org.apache.isis.objectstore.nosql.db.NoSqlDataDatabase;
+
+public class NoSqlIdentifierGenerator implements IdentifierGenerator {
+    
+    private static int INITIAL_TRANSIENT_ID = -9999999;
+    private static int DEFAULT_BATCH_SIZE = 50;
+
+    private final NoSqlDataDatabase database;
+    private final IdNumbers ids;
+
+    
+    //////////////////////////////////////////////////////////////////
+    // constructor
+    //////////////////////////////////////////////////////////////////
+
+    public NoSqlIdentifierGenerator(final NoSqlDataDatabase database) {
+        this(database, INITIAL_TRANSIENT_ID, DEFAULT_BATCH_SIZE);
+    }
+
+    public NoSqlIdentifierGenerator(final NoSqlDataDatabase database, final int initialTransientId, final int batchSize) {
+        this.database = database;
+        ids = new IdNumbers(initialTransientId, batchSize);
+    }
+
+    
+    //////////////////////////////////////////////////////////////////
+    // API
+    //////////////////////////////////////////////////////////////////
+
+    @Override
+    public String createTransientIdentifierFor(ObjectSpecId objectSpecId, Object pojo) {
+        final String identifier = "" + ids.nextTransientId();
+        return identifier;
+    }
+
+    @Override
+    public String createAggregateLocalId(ObjectSpecId objectSpecId, final Object pojo, final ObjectAdapter parentAdapter) {
+        Assert.assertNotNull("No connection set up", database);
+        return Long.toHexString(ids.nextSubId(database));
+    }
+
+    @Override
+    public String createPersistentIdentifierFor(ObjectSpecId objectSpecId, Object pojo, RootOid transientRootOid) {
+        return "" + ids.nextPersistentId(database);
+    }
+
+    
+    //////////////////////////////////////////////////////////////////
+    // debug
+    //////////////////////////////////////////////////////////////////
+    
+    @Override
+    public void debugData(final DebugBuilder debug) {
+        debug.appendln(this.toString());
+        debug.indent();
+        ids.debugData(debug);
+        debug.unindent();
+    }
+
+    @Override
+    public String debugTitle() {
+        return "NoSql OID Generator";
+    }
+}
+
+class IdNumbers {
+
+    private static final Logger LOG = Logger.getLogger(IdNumbers.class);
+
+    private final int batchSize;
+    
+    private long transientNumber;
+    private long nextId = 0;
+    private long newIdBatchAt = 0;
+    private long nextSubId = 0;
+    private long newSubIdBatchAt = 0;
+    
+    public IdNumbers(final int initialTransientId, final int batchSize) {
+        transientNumber = initialTransientId;
+        this.batchSize = batchSize;
+    }
+
+    public synchronized long nextTransientId() {
+        return transientNumber++;
+    }
+
+    public synchronized long nextSubId(final NoSqlDataDatabase connectionPool) {
+        if (nextSubId > newSubIdBatchAt) {
+            final String message = "ID exception, last id (" + nextSubId + ") past new batch boundary (" + newSubIdBatchAt + ")";
+            throw new NoSqlStoreException(message);
+        }
+        if (nextSubId == newSubIdBatchAt) {
+            nextSubId = connectionPool.nextSerialNumberBatch(ObjectSpecId.of("_sub-id"), batchSize);
+            newSubIdBatchAt = nextSubId + batchSize;
+            LOG.debug("New Sub-ID batch created, from " + nextSubId + " to " + newSubIdBatchAt);
+        }
+        return nextSubId++;
+    }
+
+    public synchronized long nextPersistentId(final NoSqlDataDatabase connectionPool) {
+        if (nextId > newIdBatchAt) {
+            final String message = "ID exception, last id (" + nextId + ") past new batch boundary (" + newIdBatchAt + ")";
+            throw new NoSqlStoreException(message);
+        }
+        if (nextId == newIdBatchAt) {
+            nextId = connectionPool.nextSerialNumberBatch(ObjectSpecId.of("_id"), batchSize);
+            newIdBatchAt = nextId + batchSize;
+            LOG.debug("New ID batch created, from " + nextId + " to " + newIdBatchAt);
+        }
+        return nextId++;
+    }
+
+    public void debugData(final DebugBuilder debug) {
+        debug.appendln("id", nextId);
+        debug.appendln("sub-id", nextSubId);
+        debug.appendln("transient id", transientNumber);
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlObjectStore.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlObjectStore.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlObjectStore.java
new file mode 100644
index 0000000..062fcbc
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlObjectStore.java
@@ -0,0 +1,338 @@
+/*
+ *  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.objectstore.nosql;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+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.AggregatedOid;
+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.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.ObjectAssociation;
+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.persistence.query.PersistenceQueryFindAllInstances;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByPattern;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByTitle;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
+import org.apache.isis.core.runtime.system.persistence.OidGenerator;
+import org.apache.isis.core.runtime.system.persistence.PersistenceQuery;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.objectstore.nosql.db.NoSqlDataDatabase;
+import org.apache.isis.objectstore.nosql.db.StateReader;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+import org.apache.isis.objectstore.nosql.keys.KeyCreatorDefault;
+import org.apache.isis.objectstore.nosql.versions.VersionCreator;
+
+public class NoSqlObjectStore implements ObjectStoreSpi {
+    
+    private final KeyCreatorDefault keyCreator = new KeyCreatorDefault();
+    private final Map<ObjectSpecId, RootOid> servicesByObjectSpecId = Maps.newHashMap();
+    
+    private final NoSqlDataDatabase database;
+    private final VersionCreator versionCreator;
+    private final ObjectReader objectReader = new ObjectReader();
+    private final OidGenerator oidGenerator;
+    private final DataEncryption wrtingDataEncrypter;
+    private final Map<String, DataEncryption> availableDataEncrypters;
+    private final boolean isDataLoaded;
+
+    public NoSqlObjectStore(final NoSqlDataDatabase db, final OidGenerator oidGenerator, final VersionCreator versionCreator, final DataEncryption writingDataEncrypter, final Map<String, DataEncryption> availableDataEncrypters) {
+        this.database = db;
+        this.oidGenerator = oidGenerator;
+        this.versionCreator = versionCreator;
+        this.wrtingDataEncrypter = writingDataEncrypter;
+        this.availableDataEncrypters = availableDataEncrypters;
+
+        db.open();
+        isDataLoaded = db.containsData();
+        db.close();
+    }
+
+    public IdentifierGenerator getIdentifierGenerator() {
+        return oidGenerator.getIdentifierGenerator();
+    }
+
+    @Override
+    public CreateObjectCommand createCreateObjectCommand(final ObjectAdapter object) {
+        // TODO should this be done at a higher level so it is applicable for
+        // all OSes
+        if (object.getSpecification().isParented()) {
+            // throw new
+            // UnexpectedCallException("Aggregated objects should not be created outside of their owner");
+            return null;
+        } else {
+            return new NoSqlCreateObjectCommand(versionCreator, wrtingDataEncrypter, object);
+        }
+    }
+
+    @Override
+    public DestroyObjectCommand createDestroyObjectCommand(final ObjectAdapter adapter) {
+        if (adapter.getSpecification().isParented()) {
+            throw new NoSqlStoreException("Can't delete an aggregated object");
+        } else {
+            return new NoSqlDestroyObjectCommand(versionCreator, adapter);
+        }
+    }
+
+    @Override
+    public SaveObjectCommand createSaveObjectCommand(final ObjectAdapter adapter) {
+        
+        // TODO should this be done at a higher level 
+        // so it is applicable for all object stores?
+        
+        final ObjectAdapter rootAdapter = adapter.getAggregateRoot();
+        if (!(rootAdapter.getOid() instanceof RootOid)) {
+            throw new NoSqlStoreException("Unexpected aggregated object to save: " + rootAdapter + " (" + adapter + ")");
+        }
+        return new NoSqlSaveObjectCommand(versionCreator, wrtingDataEncrypter, rootAdapter);
+    }
+
+    @Override
+    public void execute(final List<PersistenceCommand> commands) {
+        database.write(commands);
+    }
+    
+    @Override
+    public List<ObjectAdapter> loadInstancesAndAdapt(final PersistenceQuery persistenceQuery) {
+        if (persistenceQuery instanceof PersistenceQueryFindByTitle) {
+            return getAllInstances((PersistenceQueryFindByTitle) persistenceQuery);
+        } else if (persistenceQuery instanceof PersistenceQueryFindAllInstances) {
+            return getAllInstances((PersistenceQueryFindAllInstances) persistenceQuery);
+        } else if (persistenceQuery instanceof PersistenceQueryFindByPattern) {
+            return findByPattern((PersistenceQueryFindByPattern) persistenceQuery);
+        } else {
+            return findDefaultr(persistenceQuery);
+        }
+    }
+
+    private List<ObjectAdapter> findDefaultr(PersistenceQuery persistenceQuery) {
+        final List<ObjectAdapter> instances = Lists.newArrayList();
+        final ObjectSpecification specification = persistenceQuery.getSpecification();
+        final Iterator<StateReader> instanceData = database.instancesOf(specification.getSpecId());
+        while (instanceData.hasNext()) {
+            final StateReader reader = instanceData.next();
+            final ObjectAdapter instance = objectReader.load(reader, versionCreator, availableDataEncrypters);
+            instances.add(instance);
+        }
+        return instances;
+    }
+
+    private List<ObjectAdapter> findByPattern(PersistenceQueryFindByPattern query) {
+        final ObjectSpecification specification = query.getSpecification();
+        final List<ObjectAdapter> instances = Lists.newArrayList();
+        appendPatternInstances(query, specification, instances);
+        return instances;
+    }
+    
+    private void appendPatternInstances(final PersistenceQueryFindByPattern persistenceQuery, final ObjectSpecification specification, final List<ObjectAdapter> instances) {      
+        final Iterator<StateReader> instanceData = database.instancesOf(specification.getSpecId(), persistenceQuery.getPattern());
+        while (instanceData.hasNext()) {
+            final StateReader reader = instanceData.next();
+            final ObjectAdapter instance = objectReader.load(reader, versionCreator, availableDataEncrypters);
+            instances.add(instance);
+        }
+        for (final ObjectSpecification spec : specification.subclasses()) {
+            appendPatternInstances(persistenceQuery, spec, instances);
+        }
+    }
+
+
+    private List<ObjectAdapter> getAllInstances(PersistenceQuery query) {
+        final ObjectSpecification specification = query.getSpecification();
+        final List<ObjectAdapter> instances = Lists.newArrayList();
+        appendInstances(query, specification, instances);
+        return instances;
+    }
+
+    private void appendInstances(final PersistenceQuery persistenceQuery, final ObjectSpecification specification, final List<ObjectAdapter> instances) {      
+        final Iterator<StateReader> instanceData = database.instancesOf(specification.getSpecId());
+        while (instanceData.hasNext()) {
+            final StateReader reader = instanceData.next();
+            final ObjectAdapter instance = objectReader.load(reader, versionCreator, availableDataEncrypters);
+            
+            // TODO deal with this natively
+            if (persistenceQuery instanceof PersistenceQueryBuiltIn) {
+                if (!((PersistenceQueryBuiltIn) persistenceQuery).matches(instance)) {
+                    continue;
+                }
+            }
+            instances.add(instance);
+        }
+        for (final ObjectSpecification spec : specification.subclasses()) {
+            appendInstances(persistenceQuery, spec, instances);
+        }
+    }
+
+
+
+    @Override
+    public ObjectAdapter loadInstanceAndAdapt(final TypedOid oid) {
+        final String key = keyCreator.getIdentifierForPersistentRoot(oid);
+        final ObjectSpecification objectSpec = getSpecificationLookup().lookupBySpecId(oid.getObjectSpecId());
+        final StateReader reader = database.getInstance(key, objectSpec.getSpecId());
+        return objectReader.load(reader, versionCreator, availableDataEncrypters);
+    }
+
+    @Override
+    public boolean hasInstances(final ObjectSpecification specification) {
+        return database.hasInstances(specification.getSpecId());
+    }
+
+    @Override
+    public boolean isFixturesInstalled() {
+        return isDataLoaded;
+    }
+
+    @Override
+    public void reset() {
+    }
+
+    @Override
+    public void resolveField(final ObjectAdapter object, final ObjectAssociation field) {
+        final ObjectAdapter fieldValue = field.get(object);
+        if (fieldValue != null && !fieldValue.isResolved() && !fieldValue.getSpecification().isParented()) {
+            resolveImmediately(fieldValue);
+        }
+    }
+
+    @Override
+    public void resolveImmediately(final ObjectAdapter adapter) {
+        final Oid oid = adapter.getOid();
+        if (!(oid instanceof AggregatedOid)) {
+            final ObjectSpecification objectSpec = adapter.getSpecification();
+            final String key = keyCreator.getIdentifierForPersistentRoot(oid);
+            final StateReader reader = database.getInstance(key, objectSpec.getSpecId());
+            objectReader.update(reader, versionCreator, availableDataEncrypters, adapter);
+        }
+    }
+
+    @Override
+    public void debugData(final DebugBuilder debug) {
+        // TODO show details
+    }
+
+    // ////////////////////////////////////////////////////////////////
+    // open, close
+    // ////////////////////////////////////////////////////////////////
+
+    @Override
+    public void close() {
+        database.close();
+    }
+
+    @Override
+    public void open() {
+        database.open();
+    }
+
+    @Override
+    public String name() {
+        return "nosql";
+    }
+
+    
+    // ////////////////////////////////////////////////////////////////
+    // Services
+    // ////////////////////////////////////////////////////////////////
+    
+    @Override
+    public void registerService(final RootOid rootOid) {
+        final String key = keyCreator.getIdentifierForPersistentRoot(rootOid);
+        database.addService(rootOid.getObjectSpecId(), key);
+    }
+
+    @Override
+    public RootOid getOidForService(ObjectSpecification serviceSpec) {
+        final ObjectSpecId objectSpecId = serviceSpec.getSpecId();
+        RootOid oid = servicesByObjectSpecId.get(objectSpecId);
+        if (oid == null) {
+            final String id = database.getService(objectSpecId);
+            if (id == null) {
+                oid = null;
+            } else {
+                oid = keyCreator.createRootOid(serviceSpec, id);
+            }
+            servicesByObjectSpecId.put(objectSpecId, oid);
+        }
+        return oid;
+    }
+
+
+    // ////////////////////////////////////////////////////////////////
+    // Transaction Mgmt
+    // ////////////////////////////////////////////////////////////////
+
+    @Override
+    public void abortTransaction() {
+    }
+
+    @Override
+    public void endTransaction() {
+    }
+
+    @Override
+    public void startTransaction() {
+    }
+
+    
+    // ////////////////////////////////////////////////////////////////
+    // debugging
+    // ////////////////////////////////////////////////////////////////
+
+    @Override
+    public String debugTitle() {
+        return "NoSql Object Store";
+    }
+
+
+    // ////////////////////////////////////////////////////////////////
+    // Dependencies (from context)
+    // ////////////////////////////////////////////////////////////////
+
+    protected AdapterManager getAdapterManager() {
+        return getPersistenceSession().getAdapterManager();
+    }
+
+    protected PersistenceSession getPersistenceSession() {
+        return IsisContext.getPersistenceSession();
+    }
+
+    protected SpecificationLoader getSpecificationLookup() {
+        return IsisContext.getSpecificationLoader();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlSaveObjectCommand.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlSaveObjectCommand.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlSaveObjectCommand.java
new file mode 100644
index 0000000..aeca21e
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlSaveObjectCommand.java
@@ -0,0 +1,32 @@
+/*
+ *  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.objectstore.nosql;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.SaveObjectCommand;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+import org.apache.isis.objectstore.nosql.versions.VersionCreator;
+
+final class NoSqlSaveObjectCommand extends WriteObjectCommand implements SaveObjectCommand {
+
+    public NoSqlSaveObjectCommand(final VersionCreator versionCreator, final DataEncryption dataEncrypter, final ObjectAdapter object) {
+        super(Mode.UPDATE, versionCreator, dataEncrypter, object);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlStoreException.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlStoreException.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlStoreException.java
new file mode 100644
index 0000000..3bdf720
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/NoSqlStoreException.java
@@ -0,0 +1,47 @@
+/*
+ *  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.objectstore.nosql;
+
+import org.apache.isis.core.commons.exceptions.IsisException;
+
+public class NoSqlStoreException extends IsisException {
+    private static final long serialVersionUID = 1L;
+
+    public NoSqlStoreException() {
+        super();
+    }
+
+    public NoSqlStoreException(final String messageFormat, final Object... args) {
+        super(messageFormat, args);
+    }
+
+    public NoSqlStoreException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+
+    public NoSqlStoreException(final String message) {
+        super(message);
+    }
+
+    public NoSqlStoreException(final Throwable cause) {
+        super(cause);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/ObjectReader.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/ObjectReader.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/ObjectReader.java
new file mode 100644
index 0000000..4ed0ba8
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/ObjectReader.java
@@ -0,0 +1,249 @@
+/*
+ *  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.objectstore.nosql;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.AggregatedOid;
+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.adapter.version.Version;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociationContainer;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.Persistor;
+import org.apache.isis.objectstore.nosql.db.StateReader;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+import org.apache.isis.objectstore.nosql.keys.KeyCreatorDefault;
+import org.apache.isis.objectstore.nosql.versions.VersionCreator;
+import org.apache.log4j.Logger;
+
+public class ObjectReader {
+
+    private static final Logger LOG = Logger.getLogger(ObjectReader.class);
+    
+    private final KeyCreatorDefault keyCreator = new KeyCreatorDefault();
+
+    public ObjectAdapter load(final StateReader reader, final VersionCreator versionCreator, final Map<String, DataEncryption> dataEncrypters) {
+        
+        final String oidStr = reader.readOid();
+        final RootOid rootOid = getOidMarshaller().unmarshal(oidStr, RootOid.class);
+        
+        final ObjectAdapter adapter = getAdapter(rootOid);
+        if (adapter.isResolved()) {
+            Version version = null;
+            final String versionString = reader.readVersion();
+            if (!versionString.equals("")) {
+                final String user = reader.readUser();
+                final String time = reader.readTime();
+                version = versionCreator.version(versionString, user, time);
+            }
+            if (version.different(adapter.getVersion())) {
+                // TODO - do we need to CHECK version and update
+                LOG.warn("while reading data into " + oidStr + " version was " + version + " when existing adapter was already " + adapter.getVersion());
+            }
+            
+        } else {
+            
+            // TODO move lock to common method
+            // object.setOptimisticLock(version);
+            loadState(reader, versionCreator, dataEncrypters, adapter);
+        }
+
+        return adapter;
+    }
+
+    public void update(final StateReader reader, final VersionCreator versionCreator, final Map<String, DataEncryption> dataEncrypters, final ObjectAdapter object) {
+        loadState(reader, versionCreator, dataEncrypters, object);
+    }
+
+    private void loadState(final StateReader reader, final VersionCreator versionCreator, final Map<String, DataEncryption> dataEncrypters, final ObjectAdapter object) {
+        final ResolveState resolveState = ResolveState.RESOLVING;
+        object.changeState(resolveState);
+        Version version = null;
+        final String versionString = reader.readVersion();
+        if (!versionString.equals("")) {
+            final String user = reader.readUser();
+            final String time = reader.readTime();
+            version = versionCreator.version(versionString, user, time);
+        }
+        final String encryptionType = reader.readEncrytionType();
+        readFields(reader, object, dataEncrypters.get(encryptionType));
+        object.setVersion(version);
+        object.changeState(resolveState.getEndState());
+    }
+
+    private void readFields(final StateReader reader, final ObjectAdapter object, final DataEncryption dataEncrypter) {
+        final ObjectAssociationContainer specification = object.getSpecification();
+        final List<ObjectAssociation> associations = specification.getAssociations();
+        for (final ObjectAssociation association : associations) {
+            if (association.isNotPersisted()) {
+                continue;
+            }
+            if (association.isOneToManyAssociation()) {
+                readCollection(reader, dataEncrypter, (OneToManyAssociation) association, object);
+            } else if (association.getSpecification().isValue()) {
+                readValue(reader, dataEncrypter, (OneToOneAssociation) association, object);
+            } else if (association.getSpecification().isParented()) {
+                readAggregate(reader, dataEncrypter, (OneToOneAssociation) association, object);
+            } else {
+                readReference(reader, (OneToOneAssociation) association, object);
+            }
+        }
+    }
+
+    private void readAggregate(final StateReader reader, final DataEncryption dataEncrypter, final OneToOneAssociation association, final ObjectAdapter parentAdapter) {
+        final String id = association.getId();
+        final StateReader aggregateReader = reader.readAggregate(id);
+        
+        final ObjectAdapter fieldObject;
+        if (aggregateReader != null) {
+            final String oidStr = aggregateReader.readOid();
+            final AggregatedOid aggregatedOid = getOidMarshaller().unmarshal(oidStr, AggregatedOid.class);
+            fieldObject = restoreAggregatedObject(aggregateReader, aggregatedOid, dataEncrypter);
+        } else {
+            fieldObject = null;
+        }
+        
+        association.initAssociation(parentAdapter, fieldObject);
+    }
+
+    private ObjectAdapter restoreAggregatedObject(final StateReader aggregateReader, final AggregatedOid aggregatedOid, final DataEncryption dataEncrypter) {
+        final ObjectAdapter fieldObject = getAdapter(aggregatedOid);
+        final ResolveState resolveState = ResolveState.RESOLVING;
+        fieldObject.changeState(resolveState);
+        readFields(aggregateReader, fieldObject, dataEncrypter);
+        fieldObject.changeState(resolveState.getEndState());
+
+        return fieldObject;
+    }
+
+    private void readValue(final StateReader reader, final DataEncryption dataEncrypter, final OneToOneAssociation association, final ObjectAdapter object) {
+        final String fieldData = reader.readField(association.getId());
+        if (fieldData != null) {
+            if (fieldData.equals("null")) {
+                association.initAssociation(object, null);
+            } else {
+                final EncodableFacet encodeableFacet = association.getSpecification().getFacet(EncodableFacet.class);
+                final String decryptedData = dataEncrypter.decrypt(fieldData);
+                final ObjectAdapter value = encodeableFacet.fromEncodedString(decryptedData);
+                association.initAssociation(object, value);
+            }
+        }
+    }
+
+    private void readReference(final StateReader reader, final OneToOneAssociation association, final ObjectAdapter object) {
+        ObjectAdapter fieldObject;
+        final String ref = reader.readField(association.getId());
+        if (ref == null || ref.equals("null")) {
+            fieldObject = null;
+        } else {
+            if (ref.equals("")) {
+                throw new NoSqlStoreException("Invalid reference field (an empty string) in data for " + association.getName() + "  in " + object);
+            }
+            final RootOid oid = keyCreator.unmarshal(ref);
+            fieldObject = getAdapter(oid);
+        }
+        try {
+            association.initAssociation(object, fieldObject);
+        } catch (IllegalArgumentException e) {
+            throw new NoSqlStoreException("Failed to process field data for " + association.getName() + "  in " + object + ": " + ref);
+        }
+    }
+
+    private void readCollection(final StateReader reader, final DataEncryption dataEncrypter, final OneToManyAssociation association, final ObjectAdapter parentAdapter) {
+        final ObjectAdapter collectionAdapter = association.get(parentAdapter);
+        
+        final CollectionFacet facet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
+        if (association.getSpecification().isParented()) {
+            // were persisted inline, so read back inline
+            final List<StateReader> readers = reader.readCollection(association.getId());
+            final ObjectAdapter[] elementAdapters = new ObjectAdapter[readers.size()];
+            int i = 0;
+            for (final StateReader elementReader : readers) {
+                
+                final String oidStr = elementReader.readOid();
+                final AggregatedOid aggregatedOid = getOidMarshaller().unmarshal(oidStr, AggregatedOid.class);
+                
+                elementAdapters[i++] = restoreAggregatedObject(elementReader, aggregatedOid, dataEncrypter);
+            }
+            facet.init(collectionAdapter, elementAdapters);
+        } else {
+            // were persisted as references, so read back as references
+            final String referencesList = reader.readField(association.getId());
+            if (referencesList == null || referencesList.length() == 0) {
+                facet.init(collectionAdapter, new ObjectAdapter[0]);
+            } else {
+                final ObjectAdapter[] elements = restoreElements(referencesList);
+                facet.init(collectionAdapter, elements);
+            }
+        }
+    }
+
+    private ObjectAdapter[] restoreElements(final String referencesList) {
+        final String[] references = referencesList.split("\\|");
+        final ObjectAdapter[] elements = new ObjectAdapter[references.length];
+        for (int i = 0; i < references.length; i++) {
+            
+            // no longer used
+            //final ObjectSpecification specification = keyCreator.specificationFromOidStr(references[i]);
+            
+            final RootOid oid = keyCreator.unmarshal(references[i]);
+            elements[i] = getAdapter(oid);
+        }
+        return elements;
+    }
+
+    protected ObjectAdapter getAdapter(final TypedOid oid) {
+        return getAdapterManager().adapterFor(oid);
+    }
+
+    
+    ////////////////////////////////////////////////////////////////////////////
+    // dependencies (from context)
+    ////////////////////////////////////////////////////////////////////////////
+    
+    protected Persistor getPersistenceSession() {
+    	return IsisContext.getPersistenceSession();
+    }
+    
+    protected AdapterManager getAdapterManager() {
+        return getPersistenceSession().getAdapterManager();
+    }
+
+    protected SpecificationLoaderSpi getSpecificationLoader() {
+        return IsisContext.getSpecificationLoader();
+    }
+
+    protected OidMarshaller getOidMarshaller() {
+        return IsisContext.getOidMarshaller();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/WriteObjectCommand.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/WriteObjectCommand.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/WriteObjectCommand.java
new file mode 100644
index 0000000..3e3e41c
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/WriteObjectCommand.java
@@ -0,0 +1,249 @@
+/*
+ *  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.objectstore.nosql;
+
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.lang.ToString;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.AggregatedOid;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+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.object.encodeable.EncodableFacet;
+import org.apache.isis.core.metamodel.spec.DomainModelException;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.nosql.db.StateWriter;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+import org.apache.isis.objectstore.nosql.keys.KeyCreatorDefault;
+import org.apache.isis.objectstore.nosql.versions.VersionCreator;
+
+class WriteObjectCommand implements PersistenceCommand {
+    
+    public enum Mode {
+        UPDATE,
+        NON_UPDATE;
+        
+        public static Mode modeFor(boolean isUpdate) {
+            return isUpdate?UPDATE:NON_UPDATE;
+        }
+
+        public boolean isUpdate() {
+            return this == UPDATE;
+        }
+    }
+    
+    private final KeyCreatorDefault keyCreator = new KeyCreatorDefault();
+    private final ObjectAdapter adapter;
+    private final VersionCreator versionCreator;
+    private final DataEncryption dataEncrypter;
+    private final Mode mode;
+
+    WriteObjectCommand(final Mode mode, final VersionCreator versionCreator, final DataEncryption dataEncrypter, final ObjectAdapter adapter) {
+        this.mode = mode;
+        this.versionCreator = versionCreator;
+        this.dataEncrypter = dataEncrypter;
+        this.adapter = adapter;
+    }
+
+    @Override
+    public void execute(final PersistenceCommandContext context) {
+        final NoSqlCommandContext noSqlCommandContext = (NoSqlCommandContext) context;
+        
+        final ObjectSpecification objectSpec = adapter.getSpecification();
+        //final String specName = objectSpec.getFullIdentifier();
+        final StateWriter writer = noSqlCommandContext.createStateWriter(objectSpec.getSpecId());
+        
+        //final String key = keyCreator.key(adapter.getOid());
+        //writer.writeId(key);
+        final TypedOid typedOid = (TypedOid) adapter.getOid();
+        writer.writeOid(typedOid);
+        
+        writeFields(writer, adapter);
+        final String user = getAuthenticationSession().getUserName();
+
+        final Version currentVersion = adapter.getVersion();
+        
+        final Version newVersion = mode.isUpdate() ? versionCreator.nextVersion(currentVersion, user) : versionCreator.newVersion(user);
+        adapter.setVersion(newVersion);
+        if (newVersion != null) {
+            final String version = currentVersion == null ? null : versionCreator.versionString(currentVersion);
+            writer.writeVersion(version, versionCreator.versionString(newVersion));
+            writer.writeUser(newVersion.getUser());
+            writer.writeTime(versionCreator.timeString(newVersion));
+            writer.writeEncryptionType(dataEncrypter.getType());
+        }
+
+        if (mode.isUpdate()) {
+            noSqlCommandContext.update(writer);
+        } else {
+            noSqlCommandContext.insert(writer);
+        }
+    }
+
+    private void writeFields(final StateWriter writer, final ObjectAdapter adapter) {
+        
+        final List<ObjectAssociation> associations = adapter.getSpecification().getAssociations();
+        
+//        final String specName = adapter.getSpecification().getFullIdentifier();
+//        writer.writeObjectType(specName);
+        
+        writer.writeOid((TypedOid) adapter.getOid());
+        
+        for (final ObjectAssociation association : associations) {
+            if (association.isNotPersisted()) {
+                continue;
+            }
+            final ObjectAdapter fieldAdapter = association.get(adapter);
+            if (association.isOneToManyAssociation()) {
+                final OneToManyAssociation oneToManyAssociation = (OneToManyAssociation) association;
+                final ObjectAdapter collectionAdapter = fieldAdapter; // to explain
+                writeCollection(writer, oneToManyAssociation, collectionAdapter);
+            } else { 
+                final OneToOneAssociation oneToOneAssociation = (OneToOneAssociation) association;
+                final ObjectAdapter propertyAdapter = fieldAdapter; // to explain
+                writeProperty(writer, oneToOneAssociation, propertyAdapter);
+            }
+        }
+    }
+
+    private void writeProperty(final StateWriter writer, final OneToOneAssociation oneToOneAssociation, final ObjectAdapter propertyAdapter) {
+        if (oneToOneAssociation.getSpecification().isValue()) {
+            final ObjectAdapter valueAdapter = propertyAdapter; // to explain
+            writeValueProperty(writer, oneToOneAssociation, valueAdapter);
+        } else { 
+            final ObjectAdapter referencedAdapter = propertyAdapter; // to explain 
+            writeReferenceProperty(writer, oneToOneAssociation, referencedAdapter);
+        }
+    }
+
+    private void writeValueProperty(final StateWriter writer, final OneToOneAssociation otoa, final ObjectAdapter valueAdapter) {
+        String data;
+        if (valueAdapter == null) {
+            data = null;
+        } else {
+            final EncodableFacet encodeableFacet = valueAdapter.getSpecification().getFacet(EncodableFacet.class);
+            data = encodeableFacet.toEncodedString(valueAdapter);
+            data = dataEncrypter.encrypt(data);
+        }
+        writer.writeField(otoa.getId(), data);
+    }
+
+    private void writeReferenceProperty(final StateWriter writer, final OneToOneAssociation otoa, final ObjectAdapter referencedAdapter) {
+        if (otoa.getSpecification().isParented()) {
+            writeReferencedAsAggregated(writer, otoa, referencedAdapter);
+        } else {
+            writeReference(writer, otoa, referencedAdapter);
+        }
+    }
+
+    private void writeReferencedAsAggregated(final StateWriter writer, final OneToOneAssociation otoa, final ObjectAdapter referencedAdapter) {
+        if (referencedAdapter == null) {
+            writer.writeField(otoa.getId(), null);
+            return;
+        } 
+        final Oid referencedOid = referencedAdapter.getOid();
+        if (!(referencedOid instanceof AggregatedOid)) {
+            throw new NoSqlStoreException("Object type is inconsistent with it OID - it should have an AggregatedOid: " + referencedAdapter);
+        } 
+        final AggregatedOid aggregatedOid = (AggregatedOid) referencedOid;
+        
+        final String associationId = otoa.getId();
+        final StateWriter aggregateWriter = writer.addAggregate(associationId);
+        //aggregateWriter.writeId(aggregatedOid.getLocalId());
+        aggregateWriter.writeOid(aggregatedOid);
+        
+        writeFields(aggregateWriter, referencedAdapter);
+    }
+
+    private void writeReference(final StateWriter writer, final ObjectAssociation association, final ObjectAdapter referencedAdapter) {
+        final String key = keyCreator.oidStrFor(referencedAdapter);
+        writer.writeField(association.getId(), key);
+    }
+
+    private void writeCollection(final StateWriter writer, final OneToManyAssociation association, final ObjectAdapter collectionAdapter) {
+        if (association.getSpecification().isParented()) {
+            writeCollectionOfAggregated(writer, association, collectionAdapter);
+        } else {
+            writeCollectionOfReferences(writer, association, collectionAdapter);
+        }
+    }
+
+    private void writeCollectionOfAggregated(final StateWriter writer, final ObjectAssociation association, final ObjectAdapter collectionAdapter) {
+        final List<StateWriter> elementWriters = Lists.newArrayList();
+        final CollectionFacet collectionFacet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
+        for (final ObjectAdapter referencedAdapter : collectionFacet.iterable(collectionAdapter)) {
+            final AggregatedOid elementOid = (AggregatedOid) referencedAdapter.getOid();
+            final StateWriter elementWriter = writer.createElementWriter();
+            
+            //elementWriter.writeId(elementOid.getLocalId());
+            elementWriter.writeOid(elementOid);
+            
+            writeFields(elementWriter, referencedAdapter);
+            elementWriters.add(elementWriter);
+        }
+        writer.writeCollection(association.getId(), elementWriters);
+    }
+
+    private void writeCollectionOfReferences(final StateWriter writer, final ObjectAssociation association, final ObjectAdapter collectionAdapter) {
+        final CollectionFacet collectionFacet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
+        
+        final StringBuilder buf = new StringBuilder();
+        for (final ObjectAdapter elementAdapter : collectionFacet.iterable(collectionAdapter)) {
+            if (elementAdapter.isParented()) {
+                throw new DomainModelException("Can't store an aggregated object within a collection that is not expected aggregates: " + elementAdapter + " (" + collectionAdapter + ")");
+            }
+            buf.append(keyCreator.oidStrFor(elementAdapter)).append("|");
+        }
+        if (buf.length() > 0) {
+            writer.writeField(association.getId(), buf.toString());
+        }
+    }
+
+
+    @Override
+    public ObjectAdapter onAdapter() {
+        return adapter;
+    }
+
+    @Override
+    public String toString() {
+        final ToString toString = new ToString(this);
+        toString.append("spec", adapter.getSpecification().getFullIdentifier());
+        toString.append("oid", adapter.getOid());
+        return toString.toString();
+    }
+    
+    
+    protected AuthenticationSession getAuthenticationSession() {
+        return IsisContext.getAuthenticationSession();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlDataDatabase.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlDataDatabase.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlDataDatabase.java
new file mode 100644
index 0000000..a6e283b
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlDataDatabase.java
@@ -0,0 +1,47 @@
+/*
+ *  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.objectstore.nosql.db;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
+
+public interface NoSqlDataDatabase {
+
+    void open();
+    void close();
+    
+    boolean containsData();
+
+    void addService(ObjectSpecId objectSpecId, String key);
+    String getService(ObjectSpecId objectSpecId);
+
+    boolean hasInstances(ObjectSpecId objectSpecId);
+    StateReader getInstance(String key, ObjectSpecId objectSpecId);
+    Iterator<StateReader> instancesOf(ObjectSpecId objectSpecId);
+    Iterator<StateReader> instancesOf(ObjectSpecId specId, ObjectAdapter pattern);
+
+    long nextSerialNumberBatch(ObjectSpecId objectSpecId, int batchSize);
+
+    void write(List<PersistenceCommand> commands);
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlPersistorMechanismInstaller.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlPersistorMechanismInstaller.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlPersistorMechanismInstaller.java
new file mode 100644
index 0000000..a2b4f95
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlPersistorMechanismInstaller.java
@@ -0,0 +1,113 @@
+/*
+ *  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.objectstore.nosql.db;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import org.apache.isis.core.commons.config.ConfigurationConstants;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.commons.factory.InstanceUtil;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapterFactory;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
+import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
+import org.apache.isis.core.runtime.system.persistence.AdapterManagerSpi;
+import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
+import org.apache.isis.core.runtime.system.persistence.OidGenerator;
+import org.apache.isis.objectstore.nosql.NoSqlIdentifierGenerator;
+import org.apache.isis.objectstore.nosql.NoSqlObjectStore;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+import org.apache.isis.objectstore.nosql.encryption.none.DataEncryptionNone;
+import org.apache.isis.objectstore.nosql.versions.VersionCreator;
+import org.apache.isis.objectstore.nosql.versions.VersionCreatorDefault;
+
+public abstract class NoSqlPersistorMechanismInstaller extends PersistenceMechanismInstallerAbstract {
+
+    private static final Logger LOG = Logger.getLogger(NoSqlPersistorMechanismInstaller.class);
+
+    private static final String NAKEDOBJECTS_ENCRYPTION_CLASSES = ConfigurationConstants.ROOT + "nosql.encryption";
+
+    private NoSqlObjectStore objectStore;
+
+    public NoSqlPersistorMechanismInstaller(final String name) {
+        super(name);
+    }
+
+    @Override
+    protected ObjectStoreSpi createObjectStore(final IsisConfiguration configuration, final ObjectAdapterFactory objectFactory, final AdapterManagerSpi adapterManager) {
+        return getObjectStore(configuration);
+    }
+
+    @Override
+    public IdentifierGenerator createIdentifierGenerator(final IsisConfiguration configuration) {
+        return getObjectStore(configuration).getIdentifierGenerator();
+    }
+
+    private NoSqlObjectStore getObjectStore(final IsisConfiguration configuration) {
+        if (objectStore == null) {
+            //final KeyCreatorDefault keyCreator = createKeyCreator();
+            final VersionCreator versionCreator = createVersionCreator();
+            final NoSqlDataDatabase db = createNoSqlDatabase(configuration);
+            final OidGenerator oidGenerator = new OidGenerator(createIdentifierGenerator(db));
+
+            final Map<String, DataEncryption> availableDataEncryption = new HashMap<String, DataEncryption>();
+            try {
+                final String[] encryptionClasses = getConfiguration().getList(NAKEDOBJECTS_ENCRYPTION_CLASSES);
+                DataEncryption writeWithEncryption = null;
+                boolean encryptionSpecified = false;
+                for (final String fullyQualifiedClass : encryptionClasses) {
+                    LOG.info("  adding encryption " + fullyQualifiedClass);
+                    final DataEncryption encryption = (DataEncryption) InstanceUtil.createInstance(fullyQualifiedClass);
+                    encryption.init(configuration);
+                    availableDataEncryption.put(encryption.getType(), encryption);
+                    if (!encryptionSpecified) {
+                        writeWithEncryption = encryption;
+                    }
+                    encryptionSpecified = true;
+                }
+                if (!encryptionSpecified) {
+                    LOG.warn("No encryption specified");
+                    final DataEncryption encryption = new DataEncryptionNone();
+                    availableDataEncryption.put(encryption.getType(), encryption);
+                    writeWithEncryption = encryption;
+                }
+                objectStore = new NoSqlObjectStore(db, oidGenerator, versionCreator, writeWithEncryption, availableDataEncryption);
+            } catch (final IllegalArgumentException e) {
+                throw new IsisException(e);
+            } catch (final SecurityException e) {
+                throw new IsisException(e);
+            }
+        }
+        return objectStore;
+    }
+
+    protected NoSqlIdentifierGenerator createIdentifierGenerator(final NoSqlDataDatabase database) {
+        return new NoSqlIdentifierGenerator(database);
+    }
+
+    protected abstract NoSqlDataDatabase createNoSqlDatabase(IsisConfiguration configuration);
+
+    private VersionCreator createVersionCreator() {
+        return new VersionCreatorDefault();
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateReader.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateReader.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateReader.java
new file mode 100644
index 0000000..c7a3770
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateReader.java
@@ -0,0 +1,64 @@
+/*
+ *  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.objectstore.nosql.db;
+
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.oid.AggregatedOid;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+
+public interface StateReader {
+
+    /**
+     * Aggregated objects are persisted &quot;under&quot; a key taken from the
+     * association (property or collection).
+     * 
+     * <p>
+     * This is not to be confused with the adapter's {@link AggregatedOid#getLocalId() localId},
+     * which is a locally unique id for the adapter within the aggregate.
+     * 
+     * <p>
+     * The parameter passed here is the {@link OneToOneAssociation#getId() property Id}.
+     * 
+     * @param associationId - under which the aggregate (property/collection) were persisted. 
+     */
+    StateReader readAggregate(String propertyId);
+
+    List<StateReader> readCollection(String collectionId);
+
+    long readLongField(String id);
+
+    String readField(String id);
+
+    String readEncrytionType();
+
+//    String readObjectType();
+//    String readId();
+    
+    String readOid();
+
+    String readVersion();
+
+    String readUser();
+
+    String readTime();
+
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateWriter.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateWriter.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateWriter.java
new file mode 100644
index 0000000..e605a56
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateWriter.java
@@ -0,0 +1,51 @@
+/*
+ *  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.objectstore.nosql.db;
+
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+
+public interface StateWriter {
+
+    StateWriter addAggregate(String id);
+
+//    void writeObjectType(String type);
+//    void writeId(String oid);
+    
+    void writeOid(TypedOid typedOid);
+
+    void writeEncryptionType(String type);
+
+    void writeField(String id, String data);
+
+    void writeField(String id, long l);
+
+    void writeVersion(String currentVersion, String newVersion);
+
+    void writeTime(String time);
+
+    void writeUser(String user);
+
+    void writeCollection(String id, List<StateWriter> elements);
+
+    StateWriter createElementWriter();
+
+}