incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1338472 [3/8] - in /incubator/isis/trunk/framework/runtimes/dflt: objectstores/dflt/src/main/java/org/apache/isis/runtimes/dflt/objectstores/dflt/ objectstores/dflt/src/main/java/org/apache/isis/runtimes/dflt/objectstores/dflt/internal/ ob...
Date Mon, 14 May 2012 22:45:03 GMT
Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlIdentifierGeneratorTest.java (from r1331799, incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlOidGeneratorTest.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlIdentifierGeneratorTest.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlIdentifierGeneratorTest.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlOidGeneratorTest.java&r1=1331799&r2=1338472&rev=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlOidGeneratorTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlIdentifierGeneratorTest.java Mon May 14 22:44:57 2012
@@ -20,8 +20,6 @@
 package org.apache.isis.runtimes.dflt.objectstores.nosql;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
 
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
@@ -31,17 +29,21 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
 import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+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.testsupport.jmock.JUnitRuleMockery2;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.db.NoSqlDataDatabase;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.IdentifierGenerator;
 
-public class NoSqlOidGeneratorTest {
+public class NoSqlIdentifierGeneratorTest {
+
+    public static class ExamplePojo {
+    }
 
-    public static class ExamplePojo {}
-    
     @Rule
     public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
 
@@ -51,102 +53,92 @@ public class NoSqlOidGeneratorTest {
     private SpecificationLoader mockSpecificationLoader;
     @Mock
     private ObjectSpecification mockSpecification;
-    
-    private RootOidDefault oid;
-    private NoSqlOidGenerator oidGenerator;
 
+    private final ObjectSpecId sequenceNumbersSpecId = ObjectSpecId.of("_id");
+    private IdentifierGenerator identifierGenerator;
 
-    
     @Before
     public void setup() {
         Logger.getRootLogger().setLevel(Level.OFF);
 
-        context.checking(new Expectations() {{
-           allowing(mockSpecificationLoader).loadSpecification(with(ExamplePojo.class));
-           will(returnValue(mockSpecification));
-
-           allowing(mockSpecification).getCorrespondingClass();
-           will(returnValue(ExamplePojo.class));
-        }});
-        
-        oidGenerator = new NoSqlOidGenerator(db, -999, 4) {
-            @Override
-            protected SpecificationLoader getSpecificationLoader() {
-                return mockSpecificationLoader;
+        context.checking(new Expectations() {
+            {
+                allowing(mockSpecificationLoader).loadSpecification(with(ExamplePojo.class));
+                will(returnValue(mockSpecification));
+
+                allowing(mockSpecification).getCorrespondingClass();
+                will(returnValue(ExamplePojo.class));
+
+                allowing(mockSpecification).getCorrespondingClass();
+                will(returnValue(sequenceNumbersSpecId));
             }
-        };
-        oid = (RootOidDefault) oidGenerator.createTransientOid(new ExamplePojo());
-    }
+        });
 
-    @Test
-    public void transientOid() throws Exception {
-        
-        // TODO: REVIEW: how did this ever call db.nextSerialNumberBatch?
-        
-        assertEquals(-999, oid.getIdentifier());
-        assertTrue(oid.isTransient());
-        oid = (RootOidDefault) oidGenerator.createTransientOid(new ExamplePojo());
-        assertEquals(-998, oid.getIdentifier());
+        identifierGenerator = new NoSqlIdentifierGenerator(db, -999, 4);
     }
 
     @Test
-    public void batchCreated() throws Exception {
-          context.checking(new Expectations() {
-              {
-                  one(db).nextSerialNumberBatch("_id", 4);
-                  will(returnValue(1L));
-              }
-          });
-
-        oidGenerator.asPersistent(oid);
-        assertFalse(oid.isTransient());
-        assertEquals(1, oid.getIdentifier());
-        context.assertIsSatisfied();
+    public void transientIdentifier() throws Exception {
+        String identifier = identifierGenerator.createTransientIdentifierFor(sequenceNumbersSpecId, new ExamplePojo());
+        assertEquals("-999", identifier);
+        
+        identifier = identifierGenerator.createTransientIdentifierFor(sequenceNumbersSpecId, new ExamplePojo());
+        assertEquals("-998", identifier);
     }
 
     @Test
-    public void batchReused() throws Exception {
+    public void batchCreatedAndReused() throws Exception {
         context.checking(new Expectations() {
             {
-                one(db).nextSerialNumberBatch("_id", 4);
+                one(db).nextSerialNumberBatch(sequenceNumbersSpecId, 4);
                 will(returnValue(1L));
             }
         });
 
-        oidGenerator.asPersistent(oid);
-        oid = (RootOidDefault) oidGenerator.createTransientOid(new ExamplePojo());
-        oidGenerator.asPersistent(oid);
-        assertFalse(oid.isTransient());
-        assertEquals(2, oid.getIdentifier());
-        context.assertIsSatisfied();
+        RootOid transientRootOid = RootOidDefault.createTransient(sequenceNumbersSpecId, "-998");
+        String identifier = identifierGenerator.createPersistentIdentifierFor(sequenceNumbersSpecId, new ExamplePojo(), transientRootOid);
+        assertEquals("1", identifier);
+
+        transientRootOid = RootOidDefault.createTransient(sequenceNumbersSpecId, "-997");
+        identifier = identifierGenerator.createPersistentIdentifierFor(sequenceNumbersSpecId, new ExamplePojo(), transientRootOid);
+        assertEquals("2", identifier);
     }
 
     @Test
-    public void secondbatchCreated() throws Exception {
+    public void secondBatchCreated() throws Exception {
         context.checking(new Expectations() {
             {
-                one(db).nextSerialNumberBatch("_id", 4);
+                one(db).nextSerialNumberBatch(sequenceNumbersSpecId, 4);
                 will(returnValue(1L));
             }
         });
 
-        oidGenerator.asPersistent(oid);
-        oidGenerator.asPersistent(oid = (RootOidDefault) oidGenerator.createTransientOid(new ExamplePojo()));
-        oidGenerator.asPersistent(oid = (RootOidDefault) oidGenerator.createTransientOid(new ExamplePojo()));
-        assertEquals(3, oid.getIdentifier());
-        oidGenerator.asPersistent(oid = (RootOidDefault) oidGenerator.createTransientOid(new ExamplePojo()));
-        assertEquals(4, oid.getIdentifier());
+        RootOid transientRootOid = RootOidDefault.createTransient(sequenceNumbersSpecId, "-998");
+        String identifier = identifierGenerator.createPersistentIdentifierFor(sequenceNumbersSpecId, new ExamplePojo(), transientRootOid);
+        assertEquals("1", identifier);
+
+        transientRootOid = RootOidDefault.createTransient(sequenceNumbersSpecId, "-997");
+        identifier = identifierGenerator.createPersistentIdentifierFor(sequenceNumbersSpecId, new ExamplePojo(), transientRootOid);
+        assertEquals("2", identifier);
+
+        transientRootOid = RootOidDefault.createTransient(sequenceNumbersSpecId, "-996");
+        identifier = identifierGenerator.createPersistentIdentifierFor(sequenceNumbersSpecId, new ExamplePojo(), transientRootOid);
+        assertEquals("3", identifier);
+
+        transientRootOid = RootOidDefault.createTransient(sequenceNumbersSpecId, "-995");
+        identifier = identifierGenerator.createPersistentIdentifierFor(sequenceNumbersSpecId, new ExamplePojo(), transientRootOid);
+        assertEquals("4", identifier);
 
         context.checking(new Expectations() {
             {
-                one(db).nextSerialNumberBatch("_id", 4);
+                one(db).nextSerialNumberBatch(sequenceNumbersSpecId, 4);
                 will(returnValue(5L));
             }
         });
-        oidGenerator.asPersistent(oid = (RootOidDefault) oidGenerator.createTransientOid(new ExamplePojo()));
-        assertFalse(oid.isTransient());
-        assertEquals(5, oid.getIdentifier());
-        context.assertIsSatisfied();
+
+        transientRootOid = RootOidDefault.createTransient(sequenceNumbersSpecId, "-994");
+        identifier = identifierGenerator.createPersistentIdentifierFor(sequenceNumbersSpecId, new ExamplePojo(), transientRootOid);
+        assertEquals("5", identifier);
     }
 
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest.java Mon May 14 22:44:57 2012
@@ -21,58 +21,78 @@ package org.apache.isis.runtimes.dflt.ob
 
 import static org.junit.Assert.assertEquals;
 
+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.metamodel.adapter.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
 import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
-import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
+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.progmodel.app.IsisMetaModel;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
-import org.apache.isis.progmodels.dflt.ProgrammingModelFacetsJava5;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreatorDefault;
-import org.apache.isis.tck.dom.eg.ExamplePojoRepository;
-import org.apache.isis.tck.dom.eg.ExamplePojoWithReferences;
 
 public class NoSqlKeyCreatorTest {
 
     @Rule
     public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
 
-    private final String id = "3";
-    private final String reference = ExamplePojoWithReferences.class.getName() + "@" + id;
-    private final RootOidDefault oid3 = RootOidDefault.create("ERP", id);
-    
-    private ObjectSpecification specification;
-    
-    private KeyCreatorDefault keyCreatorDefault;
+    @Mock
+    private OidMarshaller mockOidMarshaller;
+    @Mock
+    private SpecificationLoader mockSpecificationLoader;
+    @Mock
+    private ObjectSpecification mockSpecification;
 
-    private IsisMetaModel isisMetaModel;
+    private final RootOidDefault oid = RootOidDefault.create(ObjectSpecId.of("ERP"), "3");
+    private final String oidStr = oid.enString();
 
-    @Mock
-    private RuntimeContext mockRuntimeContext;
+    private KeyCreatorDefault keyCreatorDefault;
 
+    
     @Before
-    public void setup() {
-        isisMetaModel = new IsisMetaModel(mockRuntimeContext, new ProgrammingModelFacetsJava5(), new ExamplePojoRepository());
-        specification = isisMetaModel.getSpecificationLoader().loadSpecification(ExamplePojoWithReferences.class);
-
-        keyCreatorDefault = new KeyCreatorDefault();
+    public void setUp() throws Exception {
+        keyCreatorDefault = new KeyCreatorDefault() {
+            @Override
+            protected OidMarshaller getOidMarshaller() {
+                return mockOidMarshaller;
+            }
+            @Override
+            protected SpecificationLoader getSpecificationLoader() {
+                return mockSpecificationLoader;
+            }
+        };
     }
 
     @Test
-    public void oid() throws Exception {
-        final RootOidDefault oid = (RootOidDefault) keyCreatorDefault.oidFromReference(reference);
-        assertEquals(oid3.getIdentifier(), oid.getIdentifier());
-        assertEquals(oid3.getObjectType(), oid.getObjectType());
+    public void unmarshal() throws Exception {
+        context.checking(new Expectations() {
+
+            {
+                one(mockOidMarshaller).unmarshal(oidStr, RootOid.class);
+                will(returnValue(oid));
+            }
+        });
+        assertEquals(oid, keyCreatorDefault.unmarshal(oidStr));
     }
 
     @Test
     public void specification() throws Exception {
-        final ObjectSpecification spec = keyCreatorDefault.specificationFromReference(reference);
-        assertEquals(specification, spec);
+        context.checking(new Expectations() {
+            {
+                one(mockOidMarshaller).unmarshal(oidStr, TypedOid.class);
+                will(returnValue(oid));
+                one(mockSpecificationLoader).lookupBySpecId(oid.getObjectSpecId());
+                will(returnValue(mockSpecification));
+            }
+        });
+        final ObjectSpecification spec = keyCreatorDefault.specificationFromOidStr(oidStr);
+        assertEquals(mockSpecification, spec);
     }
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java Mon May 14 22:44:57 2012
@@ -29,6 +29,7 @@ import org.junit.Test;
 
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
@@ -47,7 +48,7 @@ public class NoSqlKeyCreatorTest_referen
     private final String className = "com.foo.bar.SomeClass";
     private final String objectType = "SCL";
     
-    private final RootOidDefault rootOidDefault = RootOidDefault.create(objectType, ""+123);
+    private final RootOidDefault rootOidDefault = RootOidDefault.create(ObjectSpecId.of(objectType), ""+123);
     
     private KeyCreatorDefault keyCreatorDefault;
 
@@ -71,7 +72,7 @@ public class NoSqlKeyCreatorTest_referen
 
     @Test
     public void reference() throws Exception {
-        final String expectedReference = objectType + "@" + rootOidDefault.getIdentifier();
-        assertEquals(expectedReference, keyCreatorDefault.reference(adapter));
+        final String expectedReference = objectType + ":" + rootOidDefault.getIdentifier();
+        assertEquals(expectedReference, keyCreatorDefault.oidStrFor(adapter));
     }
 }

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_constructor.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_constructor.java?rev=1338472&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_constructor.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_constructor.java Mon May 14 22:44:57 2012
@@ -0,0 +1,105 @@
+/*
+ *  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.nosql;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jmock.Expectations;
+import org.jmock.Sequence;
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.NoSqlDataDatabase;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
+
+public class NoSqlObjectStoreTest_constructor {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+    
+    @Mock
+    private NoSqlDataDatabase db;
+    
+    @Mock
+    private VersionCreator versionCreator;
+
+    private Map<String, DataEncryption> dataEncrypter = Maps.newHashMap();
+
+    private NoSqlObjectStore store;
+
+    @Before
+    public void setup() {
+        Logger.getRootLogger().setLevel(Level.OFF);
+    }
+
+    @Test
+    public void withFixturesNotInstalled() throws Exception {
+        final Sequence constructor = context.sequence("<init>");
+        context.checking(new Expectations() {
+            {
+                one(db).open();
+                inSequence(constructor);
+                
+                one(db).containsData();
+                will(returnValue(false));
+                inSequence(constructor);
+                
+                one(db).close();
+                inSequence(constructor);
+            }
+        });
+        store = new NoSqlObjectStore(db, new OidGenerator(new NoSqlIdentifierGenerator(db)), versionCreator, null, dataEncrypter);
+        assertFalse(store.isFixturesInstalled());
+    }
+
+    @Test
+    public void withFixturesInstalled() throws Exception {
+        final Sequence constructor = context.sequence("<init>");
+        context.checking(new Expectations() {
+            {
+                one(db).open();
+                inSequence(constructor);
+                
+                one(db).containsData();
+                will(returnValue(true));
+                inSequence(constructor);
+                
+                one(db).close();
+                inSequence(constructor);
+            }
+        });
+        store = new NoSqlObjectStore(db, new OidGenerator(new NoSqlIdentifierGenerator(db)), versionCreator, null, dataEncrypter);
+        assertTrue(store.isFixturesInstalled());
+    }
+
+}

Propchange: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_constructor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_interactWith_db.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_interactWith_db.java?rev=1338472&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_interactWith_db.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_interactWith_db.java Mon May 14 22:44:57 2012
@@ -0,0 +1,226 @@
+/*
+ *  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.nosql;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jmock.Expectations;
+import org.jmock.Sequence;
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.NoSqlDataDatabase;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceQuery;
+
+public class NoSqlObjectStoreTest_interactWith_db {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+    
+    @Mock
+    private NoSqlDataDatabase db;
+    
+    @Mock
+    private VersionCreator versionCreator;
+
+    @Mock
+    private PersistenceCommand command;
+
+    @Mock
+    private ObjectSpecification cusSpecification;
+
+    @Mock
+    private ObjectSpecification serviceSpecification;
+
+    @Mock
+    private ObjectAdapter cusAdapter;
+
+    private final ObjectSpecId cusSpecId = ObjectSpecId.of("CUS");
+    private RootOid cusRootOid = RootOidDefault.create(cusSpecId, "3");
+
+    final ObjectSpecId serviceSpecId = ObjectSpecId.of("service");
+
+    private Map<String, DataEncryption> dataEncrypter = Maps.newHashMap();
+
+    private NoSqlObjectStore store;
+
+
+
+
+
+    @Before
+    public void setup() {
+        Logger.getRootLogger().setLevel(Level.OFF);
+
+        context.checking(new Expectations() {
+            {
+                // in the constructor of the object store
+                one(db).open();
+                one(db).containsData();
+                will(returnValue(false));
+                one(db).close();
+
+                allowing(cusAdapter).getOid();
+                will(returnValue(cusRootOid));
+
+                allowing(cusAdapter).getSpecification();
+                will(returnValue(cusSpecification));
+
+                allowing(cusSpecification).getSpecId();
+                will(returnValue(cusSpecId));
+
+                allowing(serviceSpecification).getSpecId();
+                will(returnValue(serviceSpecId));
+            }
+        });
+
+        store = new NoSqlObjectStore(db, new OidGenerator(new NoSqlIdentifierGenerator(db)), versionCreator, null, dataEncrypter);
+    }
+
+    @Test
+    public void open() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).open();
+            }
+        });
+        store.open();
+    }
+
+    @Test
+    public void close() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).close();
+            }
+        });
+        store.close();
+    }
+
+    @Test
+    public void registerService() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).addService(serviceSpecId, "4");
+            }
+        });
+        store.registerService(RootOidDefault.create(serviceSpecId, "4"));
+    }
+
+    @Test
+    public void oidForService() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).getService(serviceSpecId);
+                will(returnValue("4"));
+            }
+        });
+        store.getOidForService(serviceSpecification);
+    }
+
+    @Test
+    public void hasInstances() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).hasInstances(cusSpecification.getSpecId());
+                will(returnValue(true));
+            }
+        });
+        store.hasInstances(cusSpecification);
+    }
+
+    @Test
+    public void execute() throws Exception {
+        final List<PersistenceCommand> commands = new ArrayList<PersistenceCommand>();
+        commands.add(command);
+
+        context.checking(new Expectations() {
+            {
+                // Hone(command).execute(null); // REVIEW: DKH ... how was this expectation ever met?
+                one(db).write(commands);
+            }
+        });
+
+        store.execute(commands);
+    }
+
+    @Test
+    public void instances() throws Exception {
+        final PersistenceQuery persistenceQuery = context.mock(PersistenceQuery.class);
+        context.checking(new Expectations() {
+            {
+                one(persistenceQuery).getSpecification();
+                will(returnValue(cusSpecification));
+
+                one(db).instancesOf(cusSpecification.getSpecId());
+                will(returnIterator());
+                
+                allowing(cusSpecification).subclasses();
+            }
+        });
+
+        store.getInstances(persistenceQuery);
+    }
+
+    @Test
+    public void resolve() throws Exception {
+        final Sequence changingState = context.sequence("changingState");
+        context.checking(new Expectations() {
+            {
+                one(db).getInstance("3", cusSpecId);
+
+                allowing(cusAdapter).getResolveState();
+                inSequence(changingState);
+                will(returnValue(ResolveState.GHOST));
+
+                ignoring(cusSpecification);
+                
+                one(cusAdapter).changeState(ResolveState.RESOLVING);
+                inSequence(changingState);
+                one(cusAdapter).changeState(ResolveState.RESOLVED);
+                inSequence(changingState);
+                
+                one(cusAdapter).setVersion(null);
+            }
+        });
+        store.resolveImmediately(cusAdapter);
+    }
+    
+}

Propchange: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest_interactWith_db.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReaderTest.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReaderTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReaderTest.java Mon May 14 22:44:57 2012
@@ -38,13 +38,13 @@ import org.apache.isis.core.commons.exce
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.ResolveState;
 import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateReader;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo.MongoPersistorMechanismInstaller;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreator;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
@@ -61,36 +61,41 @@ public class ObjectReaderTest {
     public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
 
     @Mock
-    private KeyCreator keyCreator;
-    @Mock
     private VersionCreator versionCreator;
-    
-    private ObjectSpecification exampleValuePojoSpec;
-    private ObjectSpecification exampleReferencePojoSpec;
-    private ObjectSpecification exampleCollectionPojoSpec;
+
+    @Mock
+    private StateReader reader1;
+    @Mock
+    private StateReader reader2;
+
+    //private KeyCreatorDefault keyCreator;
+
+    //private ObjectSpecification exampleValuePojoSpec;
+    //private ObjectSpecification exampleReferencePojoSpec;
+    //private ObjectSpecification exampleCollectionPojoSpec;
     
     private ObjectReader objectReader;
     
-    private StateReader reader1;
-    private StateReader reader2;
     
     private Map<String, DataEncryption> dataEncrypter;
 
-    private final RootOidDefault oid3 = RootOidDefault.create("EPV|3"); // ExampleValuePojo
-    private final RootOidDefault oid4 = RootOidDefault.create("EPR|4"); // ExampleReferencePojo
-    private final RootOidDefault oid5 = RootOidDefault.create("EPC|5"); // ExampleCollectionPojo
+    private final RootOidDefault oid3 = RootOidDefault.deString("EPV:3"); // ExampleValuePojo
+    private final RootOidDefault oid4 = RootOidDefault.deString("EPR:4"); // ExampleReferencePojo
+    private final RootOidDefault oid5 = RootOidDefault.deString("EPC:5"); // ExampleCollectionPojo
 
 
     @Before
     public void setup() {
-        exampleValuePojoSpec = iswf.loadSpecification(ExamplePojoWithValues.class);
-        exampleReferencePojoSpec = iswf.loadSpecification(ExamplePojoWithReferences.class);
-        exampleCollectionPojoSpec = iswf.loadSpecification(ExamplePojoWithCollections.class);
+        //keyCreator = new KeyCreatorDefault();
+        
+        //exampleValuePojoSpec = iswf.loadSpecification(ExamplePojoWithValues.class);
+        //exampleReferencePojoSpec = iswf.loadSpecification(ExamplePojoWithReferences.class);
+        //exampleCollectionPojoSpec = iswf.loadSpecification(ExamplePojoWithCollections.class);
                 
         objectReader = new ObjectReader();
 
         dataEncrypter = new HashMap<String, DataEncryption>();
-        final DataEncryption dataEncrypter1 = new DataEncryption() {
+        final DataEncryption etcEncryption = new DataEncryption() {
             @Override
             public String getType() {
                 return "etc1";
@@ -110,8 +115,7 @@ public class ObjectReaderTest {
                 return encryptedText.substring(3);
             }
         };
-        dataEncrypter.put(dataEncrypter1.getType(), dataEncrypter1);
-
+        dataEncrypter.put(etcEncryption.getType(), etcEncryption);
     }
 
     @Test
@@ -120,11 +124,14 @@ public class ObjectReaderTest {
 
         context.checking(new Expectations() {
             {
-                one(reader1).readObjectType();
-                will(returnValue(ExamplePojoWithValues.class.getName()));
+//                one(reader1).readObjectType();
+//                will(returnValue(ExamplePojoWithValues.class.getName()));
+//
+//                one(reader1).readId();
+//                will(returnValue("3"));
 
-                one(reader1).readId();
-                will(returnValue("3"));
+                one(reader1).readOid();
+                will(returnValue("EPV:3"));
 
                 one(reader1).readEncrytionType();
                 will(returnValue("etc1"));
@@ -136,13 +143,13 @@ public class ObjectReaderTest {
                 will(returnValue("1020"));
                 one(versionCreator).version("3", "username", "1020");
                 
-                one(keyCreator).oid(exampleValuePojoSpec, "3");
-                will(returnValue(oid3));
+//                one(keyCreator).createRootOid(exampleValuePojoSpec, "3");
+//                will(returnValue(oid3));
                 ;
             }
         });
 
-        final ObjectAdapter readObject = objectReader.load(reader1, keyCreator, versionCreator, dataEncrypter);
+        final ObjectAdapter readObject = objectReader.load(reader1, versionCreator, dataEncrypter);
         assertEquals(oid3, readObject.getOid());
         assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
 
@@ -155,14 +162,16 @@ public class ObjectReaderTest {
 
     @Test
     public void testReadingReference() throws Exception {
-        reader2 = context.mock(StateReader.class, "reader 2");
         context.checking(new Expectations() {
             {
-                one(reader2).readObjectType();
-                will(returnValue(ExamplePojoWithReferences.class.getName()));
+//                one(reader2).readObjectType();
+//                will(returnValue(ExamplePojoWithReferences.class.getName()));
+//
+//                one(reader2).readId();
+//                will(returnValue("4"));
 
-                one(reader2).readId();
-                will(returnValue("4"));
+                one(reader2).readOid();
+                will(returnValue("EPR:4"));
 
                 one(reader2).readEncrytionType();
                 will(returnValue("etc1"));
@@ -174,25 +183,23 @@ public class ObjectReaderTest {
                 will(returnValue("1020"));
                 one(versionCreator).version("3", "username", "1020");
 
-                one(keyCreator).oid(exampleReferencePojoSpec, "4");
-                will(returnValue(oid4));
-                ;
+//                one(keyCreator).createRootOid(exampleReferencePojoSpec, "4");
+//                will(returnValue(oid4));
 
-                one(reader2).readField("reference1");
-                will(returnValue("ref@3"));
+                one(reader2).readField("reference");
+                will(returnValue("EPV:3"));
 
-                one(reader2).readField("reference2");
-                will(returnValue("null"));
+                one(reader2).readAggregate("aggregatedReference");
+                will(returnValue(null));
 
-                one(keyCreator).oidFromReference("ref@3");
-                will(returnValue(oid3));
-                ;
-                one(keyCreator).specificationFromReference("ref@3");
-                will(returnValue(exampleValuePojoSpec));
+//                one(keyCreator).unmarshal("ref@3");
+//                will(returnValue(oid3));
+//                one(keyCreator).specificationFromOidStr("ref@3");
+//                will(returnValue(exampleValuePojoSpec));
             }
         });
 
-        final ObjectAdapter readObject = objectReader.load(reader2, keyCreator, versionCreator, dataEncrypter);
+        final ObjectAdapter readObject = objectReader.load(reader2, versionCreator, dataEncrypter);
         assertEquals(oid4, readObject.getOid());
         assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
 
@@ -205,15 +212,17 @@ public class ObjectReaderTest {
 
     @Test
     public void testReadingCollection() throws Exception {
-        final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExamplePojoWithValues.class);
-        reader2 = context.mock(StateReader.class, "reader 2");
+        //final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExamplePojoWithValues.class);
         context.checking(new Expectations() {
             {
-                one(reader2).readObjectType();
-                will(returnValue(ExamplePojoWithCollections.class.getName()));
+//                one(reader2).readObjectType();
+//                will(returnValue(ExamplePojoWithCollections.class.getName()));
+//
+//                one(reader2).readId();
+//                will(returnValue("5"));
 
-                one(reader2).readId();
-                will(returnValue("5"));
+                one(reader2).readOid();
+                will(returnValue("EPC:5"));
 
                 one(reader2).readEncrytionType();
                 will(returnValue("etc1"));
@@ -225,27 +234,26 @@ public class ObjectReaderTest {
                 will(returnValue("1020"));
                 one(versionCreator).version("3", "username", "1020");
 
-                one(keyCreator).oid(exampleCollectionPojoSpec, "5");
-                will(returnValue(oid5));
-                ;
+//                one(keyCreator).createRootOid(exampleCollectionPojoSpec, "5");
+//                will(returnValue(oid5));
 
-                one(reader2).readField("hetrogenousCollection");
+                one(reader2).readField("heterogeneousCollection");
                 will(returnValue(null));
-                one(reader2).readField("homogenousCollection");
-                will(returnValue("ref@3|ref@4|"));
+                one(reader2).readField("homogeneousCollection");
+                will(returnValue("EPV:3|EPV:4|"));
 
-                one(keyCreator).specificationFromReference("ref@3");
-                will(returnValue(specification));
-                one(keyCreator).oidFromReference("ref@3");
-                will(returnValue(oid3));
-                one(keyCreator).specificationFromReference("ref@4");
-                will(returnValue(specification));
-                one(keyCreator).oidFromReference("ref@4");
-                will(returnValue(oid4));
+//                one(keyCreator).specificationFromOidStr("ref@3");
+//                will(returnValue(specification));
+//                one(keyCreator).unmarshal("ref@3");
+//                will(returnValue(oid3));
+//                one(keyCreator).specificationFromOidStr("ref@4");
+//                will(returnValue(specification));
+//                one(keyCreator).unmarshal("ref@4");
+//                will(returnValue(oid4));
             }
         });
 
-        final ObjectAdapter readObject = objectReader.load(reader2, keyCreator, versionCreator, dataEncrypter);
+        final ObjectAdapter readObject = objectReader.load(reader2, versionCreator, dataEncrypter);
         assertEquals(oid5, readObject.getOid());
         assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
 
@@ -278,9 +286,9 @@ public class ObjectReaderTest {
         });
 
         final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExamplePojoWithValues.class);
-        final ObjectAdapter readObject = IsisContext.getPersistenceSession().recreateAdapter(RootOidDefault.create("EVP", ""+4), specification);
+        final ObjectAdapter readObject = IsisContext.getPersistenceSession().recreateAdapter(specification, RootOidDefault.create(ObjectSpecId.of("EVP"), ""+4));
 
-        objectReader.update(reader1, keyCreator, versionCreator, dataEncrypter, readObject);
+        objectReader.update(reader1, versionCreator, dataEncrypter, readObject);
 
         final ExamplePojoWithValues pojo = (ExamplePojoWithValues) readObject.getObject();
         assertEquals("Fred Smith", pojo.getName());
@@ -290,9 +298,11 @@ public class ObjectReaderTest {
     }
 
     private void setupObject1() {
-        reader1 = context.mock(StateReader.class, "reader 1");
         context.checking(new Expectations() {
             {
+                one(reader1).readField("date");
+                will(returnValue("null"));
+
                 one(reader1).readField("name");
                 will(returnValue("ENCFred Smith"));
 

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java Mon May 14 22:44:57 2012
@@ -31,12 +31,10 @@ import org.apache.isis.core.metamodel.ad
 import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
 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.ObjectSpecification;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateWriter;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreator;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
 import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
 import org.apache.isis.tck.dom.eg.ExamplePojoWithCollections;
@@ -55,16 +53,14 @@ public class WriteObjectCommandTest {
     private StateWriter writer;
     @Mock
     private VersionCreator versionCreator;
-    @Mock
-    private KeyCreator keyCreator;
+    
     @Mock
     private NoSqlCommandContext commandContext;
 
     private DataEncryption dataEncrypter;
+    //private KeyCreatorDefault keyCreator;
 
     private ObjectAdapter epv1Adapter;
-    private ObjectSpecification specification;
-    private ObjectAdapter epv2Adapter;
     private ObjectAdapter epr1Adapter;
     private ObjectAdapter epc1Adapter;
 
@@ -78,26 +74,26 @@ public class WriteObjectCommandTest {
     @Before
     public void setup() {
 
+        //keyCreator = new KeyCreatorDefault();
+        
         epv1 = iswf.fixtures.epv1;
         epv1.setName("Fred Smith");
         epv1.setSize(108);
-        epv1Adapter = iswf.remapAsPersistent(RootOidDefault.create("EPV|1"), epv1);
+        epv1Adapter = iswf.remapAsPersistent(epv1, RootOidDefault.deString("EPV:1"));
 
         epv2 = iswf.fixtures.epv2;
         epv2.setName("John Brown");
-        epv2Adapter = iswf.remapAsPersistent(RootOidDefault.create("EPV|2"), epv2);
+        iswf.remapAsPersistent(epv2, RootOidDefault.deString("EPV:2"));
 
         epr1 = iswf.fixtures.epr1;
         epr1.setReference(epv1);
-        epr1Adapter = iswf.remapAsPersistent(RootOidDefault.create("EPR|1"), epr1);
+        epr1Adapter = iswf.remapAsPersistent(epr1, RootOidDefault.deString("EPR:1"));
 
         epc1 = iswf.fixtures.epc1;
         epc1.getHomogeneousCollection().add(epv1);
         epc1.getHomogeneousCollection().add(epv2);
         
-        epc1Adapter = iswf.remapAsPersistent(RootOidDefault.create("EPC|1"), epc1Adapter);
-
-        specification = epv1Adapter.getSpecification();
+        epc1Adapter = iswf.remapAsPersistent(epc1, RootOidDefault.deString("EPC:1"));
 
         final Version version = new SerialNumberVersion(2, "username", null);
 
@@ -141,16 +137,18 @@ public class WriteObjectCommandTest {
         context.checking(new Expectations() {
 
             {
-                one(commandContext).createStateWriter(specification.getFullIdentifier());
+                one(commandContext).createStateWriter(epv1Adapter.getSpecification().getSpecId());
                 will(returnValue(writer));
 
-                one(keyCreator).key(RootOidDefault.create("EPV|1"));
-                will(returnValue("1"));
+//                one(writer).writeId("1");
+//                one(writer).writeObjectType(specification.getFullIdentifier());
+
+                final RootOidDefault oid = RootOidDefault.create(epv1Adapter.getSpecification().getSpecId(), "1");
+                exactly(2).of(writer).writeOid(oid); // once for the id, once for the type
 
-                one(writer).writeId("3");
-                one(writer).writeType(specification.getFullIdentifier());
                 one(writer).writeField("name", "ENCFred Smith");
                 one(writer).writeField("size", "ENC108");
+                one(writer).writeField("date", null);
                 one(writer).writeField("nullable", null);
                 one(writer).writeVersion(null, "2");
                 one(writer).writeUser("username");
@@ -162,9 +160,8 @@ public class WriteObjectCommandTest {
             }
         });
 
-        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, epv1Adapter).execute(commandContext);
-
-        context.assertIsSatisfied();
+        final WriteObjectCommand command = new WriteObjectCommand(WriteObjectCommand.Mode.NON_UPDATE, versionCreator, dataEncrypter, epv1Adapter);
+        command.execute(commandContext);
     }
 
     @Test
@@ -172,18 +169,18 @@ public class WriteObjectCommandTest {
 
         context.checking(new Expectations() {
             {
-                one(commandContext).createStateWriter(epr1Adapter.getSpecification().getFullIdentifier());
+                one(commandContext).createStateWriter(epr1Adapter.getSpecification().getSpecId());
                 will(returnValue(writer));
 
-                one(keyCreator).key(RootOidDefault.create("EPR|1"));
-                will(returnValue("5"));
-                one(keyCreator).reference(epv1Adapter);
-                will(returnValue("ref@3"));
-
-                one(writer).writeId("5");
-                one(writer).writeType(epr1Adapter.getSpecification().getFullIdentifier());
-                one(writer).writeField("reference1", "ref@3");
-                one(writer).writeField("reference2", null);
+//                one(writer).writeId("1");
+//                one(writer).writeObjectType(epr1Adapter.getSpecification().getFullIdentifier());
+                
+                final RootOidDefault oid = RootOidDefault.create(epr1Adapter.getSpecification().getSpecId(), "1");
+                exactly(2).of(writer).writeOid(oid); // once for the id, once for the type
+                
+                one(writer).writeField("reference", "EPV:1");
+                one(writer).writeField("aggregatedReference", null);
+                
                 one(writer).writeVersion(null, "2");
                 one(writer).writeUser("username");
                 one(writer).writeTime("1057");
@@ -193,9 +190,8 @@ public class WriteObjectCommandTest {
             }
         });
 
-        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, epr1Adapter).execute(commandContext);
-
-        context.assertIsSatisfied();
+        final WriteObjectCommand command = new WriteObjectCommand(WriteObjectCommand.Mode.NON_UPDATE, versionCreator, dataEncrypter, epr1Adapter);
+        command.execute(commandContext);
     }
 
     @Test
@@ -203,20 +199,16 @@ public class WriteObjectCommandTest {
 
         context.checking(new Expectations() {
             {
-                one(commandContext).createStateWriter(epc1Adapter.getSpecification().getFullIdentifier());
+                one(commandContext).createStateWriter(epc1Adapter.getSpecification().getSpecId());
                 will(returnValue(writer));
 
-                one(keyCreator).key(RootOidDefault.create("EPC|1"));
-                will(returnValue("6"));
-                one(writer).writeId("6");
-                one(writer).writeType(epc1Adapter.getSpecification().getFullIdentifier());
-
-                one(keyCreator).reference(epv1Adapter);
-                will(returnValue("ref@3"));
-                one(keyCreator).reference(epv2Adapter);
-                will(returnValue("ref@4"));
+//                one(writer).writeId("1");
+//                one(writer).writeObjectType(epc1Adapter.getSpecification().getFullIdentifier());
+
+                final RootOidDefault oid = RootOidDefault.create(epc1Adapter.getSpecification().getSpecId(), "1");
+                exactly(2).of(writer).writeOid(oid); // once for the id, once for the type
 
-                one(writer).writeField("homogenousCollection", "ref@3|ref@4|");
+                one(writer).writeField("homogeneousCollection", "EPV:1|EPV:2|");
 
                 one(writer).writeVersion(null, "2");
                 one(writer).writeUser("username");
@@ -227,9 +219,7 @@ public class WriteObjectCommandTest {
             }
         });
 
-        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, epc1Adapter).execute(commandContext);
-
-        context.assertIsSatisfied();
+        final WriteObjectCommand command = new WriteObjectCommand(WriteObjectCommand.Mode.NON_UPDATE, versionCreator, dataEncrypter, epc1Adapter);
+        command.execute(commandContext);
     }
-
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java Mon May 14 22:44:57 2012
@@ -30,9 +30,9 @@ public class ChecksummingPerfomance {
 
     public static void main(final String[] args) throws Exception {
 
-        final CRC32 inputChecksum = new CRC32();
-        final CheckedInputStream in = new CheckedInputStream(new FileInputStream("test.data"), inputChecksum);
-        final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Util.ENCODING));
+        //final CRC32 inputChecksum = new CRC32();
+        //final CheckedInputStream in = new CheckedInputStream(new FileInputStream("test.data"), inputChecksum);
+        //final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Util.ENCODING));
 
         for (int i = 0; i < 30; i++) {
             long time = System.currentTimeMillis();

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java Mon May 14 22:44:57 2012
@@ -29,12 +29,9 @@ import java.io.InputStream;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import org.apache.isis.core.commons.lang.IoUtils;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.ClientConnection;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.RemotingException;
 import org.apache.isis.runtimes.dflt.runtime.persistence.ConcurrencyException;
 import org.apache.isis.runtimes.dflt.runtime.persistence.ObjectNotFoundException;
 
@@ -53,7 +50,6 @@ public class ClientConnectionTest {
         connection = new ClientConnection(input, output);
     }
 
-    @Ignore
     @Test
     public void testRequest() throws Exception {
         connection.request('D', "xxx yyy");

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java Mon May 14 22:44:57 2012
@@ -35,8 +35,21 @@ public class JsonStateReaderTest {
 
     @Before
     public void setup() {
-        reader = new JsonStateReader("{" + "\"_encrypt\": \"etc1\"," + "\"_id\": \"#2\"," + "\"_type\": \"com.package.ClassName\"," + "\"_time\": \"ddmmyy\"," + "\"_user\": \"fred\"," + "\"_version\": \"2\"," + "\"field-1\": \"1234\"," + "\"field-2\": \"data\"," + "\"field-3\": null,"
-                + "\"list\": [{}, {}]," + "\"aggregate\": {\"_id\": \"#3\"}," + "}");
+        reader = new JsonStateReader(
+                "{" + 
+                    "\"_encrypt\": \"etc1\"," + 
+                    "\"_oid\": \"com.package.ClassName:#2\"," + 
+                    "\"_time\": \"ddmmyy\"," + 
+                    "\"_user\": \"fred\"," + 
+                    "\"_version\": \"2\"," + 
+                    "\"field-1\": \"1234\"," + 
+                    "\"field-2\": \"data\"," + 
+                    "\"field-3\": null,"
+                    + "\"list\": [{}, {}]," + 
+                    "\"aggregate\": {" +
+                        "\"_oid\": \"com.package.ClassName:#2~com.package.AggregatedClassName:#3\""  +
+                        "}," + 
+                    "}");
     }
 
     @Test
@@ -44,14 +57,19 @@ public class JsonStateReaderTest {
         assertEquals("etc1", reader.readEncrytionType());
     }
 
-    @Test
-    public void readId() throws Exception {
-        assertEquals("#2", reader.readId());
-    }
+//    @Test
+//    public void readId() throws Exception {
+//        assertEquals("#2", reader.readId());
+//    }
+//
+//    @Test
+//    public void readObjectType() throws Exception {
+//        assertEquals("com.package.ClassName", reader.readObjectType());
+//    }
 
     @Test
-    public void readObjectType() throws Exception {
-        assertEquals("com.package.ClassName", reader.readObjectType());
+    public void readOid() throws Exception {
+        assertEquals("com.package.ClassName:#2", reader.readOid());
     }
 
     @Test
@@ -104,6 +122,6 @@ public class JsonStateReaderTest {
     @Test
     public void readAggregate() throws Exception {
         final StateReader aggregate = reader.readAggregate("aggregate");
-        assertEquals("#3", aggregate.readId());
+        assertEquals("com.package.ClassName:#2~com.package.AggregatedClassName:#3", aggregate.readOid());
     }
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java Mon May 14 22:44:57 2012
@@ -26,6 +26,7 @@ import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateWriter;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.JsonStateWriter;
 
@@ -45,12 +46,19 @@ public class JsonStateWriterTest {
 
     @Test
     public void basicData() throws Exception {
-        writer.writeId("#1");
+//        writer.writeObjectType("com.planchase.ClassName");
+//        writer.writeId("#1");
+        writer.writeOid(RootOidDefault.deString("com.planchase.ClassName:1"));
         writer.writeTime("ddmmyy");
-        writer.writeType("com.planchase.ClassName");
         writer.writeVersion("1", "2");
         writer.writeUser("fred");
-        assertEquals("{\n    \"_id\": \"#1\",\n    \"_time\": \"ddmmyy\",\n    \"_type\": \"com.planchase.ClassName\",\n    \"_user\": \"fred\",\n    \"_version\": \"2\"\n}", writer.getData());
+        assertEquals("{\n" +
+        		"    \"_oid\": \"com.planchase.ClassName:1\",\n" +
+        		"    \"_time\": \"ddmmyy\",\n" +
+        		"    \"_user\": \"fred\",\n" +
+        		"    \"_version\": \"2\"\n" +
+        		"}", 
+        		writer.getData());
     }
 
     @Test
@@ -101,10 +109,11 @@ public class JsonStateWriterTest {
 
     @Test
     public void requestData() throws Exception {
-        writer.writeType("com.planchase.ClassName");
-        writer.writeId("#8");
+//        writer.writeObjectType("com.planchase.ClassName");
+//        writer.writeId("#8");
+        writer.writeOid(RootOidDefault.deString("com.planchase.ClassName:8"));
         writer.writeVersion("1", "2");
-        assertEquals("com.planchase.ClassName #8 1 2", writer.getRequest());
+        assertEquals("com.planchase.ClassName:8 1 2", writer.getRequest());
     }
 
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoDbTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoDbTest.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoDbTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoDbTest.java Mon May 14 22:44:57 2012
@@ -36,8 +36,7 @@ import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreatorDefault;
 import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
@@ -70,7 +69,6 @@ public class MongoDbTest {
         db = new MongoDb("localhost", 0, "testdb", new KeyCreatorDefault());
         db.open();
 
-        RootOid oid = RootOidDefault.createTransient("EPV|3");
         adapter1 = iswf.adapterFor(iswf.fixtures.epv1);
         specification = adapter1.getSpecification();
     }
@@ -82,47 +80,46 @@ public class MongoDbTest {
 
     @Test
     public void serialNumberSaved() throws Exception {
-        assertEquals(1, db.nextSerialNumberBatch("oid", 10));
-        assertEquals(11, db.nextSerialNumberBatch("oid", 10));
+        assertEquals(1, db.nextSerialNumberBatch(ObjectSpecId.of("oid"), 10));
+        assertEquals(11, db.nextSerialNumberBatch(ObjectSpecId.of("oid"), 10));
     }
 
     @Test
     public void hasInstances() throws Exception {
-        final String specificationName = specification.getFullIdentifier();
-        assertFalse(db.hasInstances(specificationName));
+        assertFalse(db.hasInstances(specification.getSpecId()));
         db.close();
 
-        final DBCollection instances = testDb.getCollection(specificationName);
+        final DBCollection instances = testDb.getCollection(specification.getSpecId().asString());
         instances.insert(new BasicDBObject().append("test", "test"));
 
         db.open();
-        assertTrue(db.hasInstances(specificationName));
-        assertFalse(db.hasInstances("org.xxx.unknown"));
+        assertTrue(db.hasInstances(specification.getSpecId()));
+        assertFalse(db.hasInstances(ObjectSpecId.of("org.xxx.unknown")));
     }
 
     @Test
     public void destroyInstance() throws Exception {
         db.close();
 
-        final String specificationName = specification.getFullIdentifier();
-        final DBCollection instances = testDb.getCollection(specificationName);
+        final DBCollection instances = testDb.getCollection(specification.getSpecId().asString());
         final BasicDBObject dbObject = new BasicDBObject().append("test", "test");
         instances.insert(dbObject);
 
         db.open();
-        db.delete(specificationName, dbObject.getString("_id"));
-        assertFalse(db.hasInstances(specificationName));
+        db.delete(specification.getSpecId(), dbObject.getString("_id"));
+        assertFalse(db.hasInstances(specification.getSpecId()));
     }
 
     @Test
     public void serviceIds() throws Exception {
-        db.addService("one", "123");
-        assertEquals("123", db.getService("one"));
+        final ObjectSpecId osi = ObjectSpecId.of("one");
+        db.addService(osi, "123");
+        assertEquals("123", db.getService(osi));
     }
 
     @Test
     public void unknownServiceIds() throws Exception {
-        assertNull(db.getService("two"));
+        assertNull(db.getService(ObjectSpecId.of("two")));
     }
 
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderTest.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderTest.java Mon May 14 22:44:57 2012
@@ -35,11 +35,13 @@ import org.apache.log4j.Logger;
 import org.junit.Before;
 import org.junit.Test;
 
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo.MongoStateReader;
 
 public class MongoStateReaderTest {
 
-    private static final String SPEC_NAME = "org.test.Object";
+    private static final String OBJECT_TYPE = "org.test.Object";
+    
     private DB testDb;
     private MongoStateReader reader;
 
@@ -59,17 +61,20 @@ public class MongoStateReaderTest {
         testDb = m.getDB("mydb");
 
         final BasicDBObject object = new BasicDBObject();
-        object.put("_id", "1023");
-        object.put("_type", "org.xxx.Class");
+//        object.put("_id", "1023");
+//        object.put("_type", "org.xxx.Class");
+        object.put("_oid", OBJECT_TYPE + ":1023");
+        object.put("_id", "1023"); // the MongoDB internal identifier
+
         object.put("name", "Fred Smith");
         object.put("null name", "null");
         object.put("null name 2", null);
         object.put("number", "102");
         object.put("null number", "null");
-        final DBCollection instances = testDb.getCollection(SPEC_NAME);
+        final DBCollection instances = testDb.getCollection(OBJECT_TYPE);
         instances.insert(object);
 
-        reader = new MongoStateReader(testDb, SPEC_NAME, "1023");
+        reader = new MongoStateReader(testDb, ObjectSpecId.of(OBJECT_TYPE), "1023");
     }
 
     @Test
@@ -93,9 +98,19 @@ public class MongoStateReaderTest {
         assertEquals(null, reader.readField("null name 2"));
     }
 
+//    @Test
+//    public void readType() throws Exception {
+//        assertEquals("org.xxx.Class", reader.readObjectType());
+//    }
+//
+//    @Test
+//    public void readId() throws Exception {
+//        assertEquals("1023", reader.readId());
+//    }
+
     @Test
-    public void readType() throws Exception {
-        assertEquals("org.xxx.Class", reader.readObjectType());
+    public void readOid() throws Exception {
+        assertEquals(OBJECT_TYPE + ":1023", reader.readOid());
     }
 
     @Test
@@ -113,8 +128,4 @@ public class MongoStateReaderTest {
         assertEquals(0L, reader.readLongField("unknown"));
     }
 
-    @Test
-    public void readId() throws Exception {
-        assertEquals("1023", reader.readId());
-    }
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterTest.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterTest.java Mon May 14 22:44:57 2012
@@ -21,7 +21,6 @@ package org.apache.isis.runtimes.dflt.ob
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assume.assumeThat;
 
 import com.mongodb.DB;
@@ -34,7 +33,8 @@ import org.apache.log4j.Logger;
 import org.junit.Before;
 import org.junit.Test;
 
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo.MongoStateWriter;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 
 public class MongoStateWriterTest {
 
@@ -56,7 +56,7 @@ public class MongoStateWriterTest {
             return;
         }
 
-        writer = new MongoStateWriter(testDb, SPEC_NAME);
+        writer = new MongoStateWriter(testDb, ObjectSpecId.of(SPEC_NAME));
     }
 
     @Test
@@ -78,20 +78,24 @@ public class MongoStateWriterTest {
 
     @Test
     public void serialNumberNotStored() throws Exception {
-        writer.writeId("D01");
+        //writer.writeId("D01");
+        writer.writeOid(RootOidDefault.deString(SPEC_NAME+":"+"D01"));
         writer.flush();
 
         final DBCollection instances = testDb.getCollection(SPEC_NAME);
         assertEquals(1, instances.getCount());
         final DBObject object = instances.findOne();
-        assertNotNull(object.get("_id"));
+        
+        assertEquals(SPEC_NAME+":"+"D01", object.get("_oid"));
         assertEquals("D01", object.get("_id"));
-        assertEquals(1, object.keySet().size());
+        
+        assertEquals(2, object.keySet().size());
     }
 
     @Test
     public void writeFields() throws Exception {
-        writer.writeType(SPEC_NAME);
+        //writer.writeObjectType(SPEC_NAME);
+        writer.writeOid(RootOidDefault.deString(SPEC_NAME+":"+"D01"));
         writer.writeField("number", 1023);
         writer.writeField("string", "testing");
         writer.flush();
@@ -99,15 +103,16 @@ public class MongoStateWriterTest {
         final DBCollection instances = testDb.getCollection(SPEC_NAME);
         assertEquals(1, instances.getCount());
         final DBObject object = instances.findOne();
-        assertEquals(SPEC_NAME, object.get("_type"));
+        assertEquals(SPEC_NAME+":"+"D01", object.get("_oid"));
         assertEquals("1023", object.get("number"));
         assertEquals("testing", object.get("string"));
     }
 
     @Test
     public void writeFields2() throws Exception {
-        writer.writeId("3");
-        writer.writeType(SPEC_NAME);
+//        writer.writeId("3");
+//        writer.writeObjectType(SPEC_NAME);
+        writer.writeOid(RootOidDefault.deString(SPEC_NAME + ":" + "3"));
         writer.flush();
 
         writer.writeField("number", 1023);
@@ -117,7 +122,7 @@ public class MongoStateWriterTest {
         final DBCollection instances = testDb.getCollection(SPEC_NAME);
         assertEquals(1, instances.getCount());
         final DBObject object = instances.findOne();
-        assertEquals(SPEC_NAME, object.get("_type"));
+        assertEquals(SPEC_NAME + ":" + "3", object.get("_oid"));
         assertEquals("1023", object.get("number"));
         assertEquals("testing", object.get("string"));
     }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/IdMappingAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/IdMappingAbstract.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/IdMappingAbstract.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/IdMappingAbstract.java Mon May 14 22:44:57 2012
@@ -23,6 +23,7 @@ import org.apache.isis.core.metamodel.ad
 import org.apache.isis.core.metamodel.adapter.oid.Oid;
 import org.apache.isis.core.metamodel.adapter.oid.RootOid;
 import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
@@ -78,13 +79,13 @@ public class IdMappingAbstract {
         return oid.getIdentifier();
     }
 
-    public Oid recreateOid(final Results rs, final ObjectSpecification specification) {
+    public TypedOid recreateOid(final Results rs, final ObjectSpecification specification) {
         final Object object = rs.getObject(column);
         if (object == null) {
             return null;
         } 
         final int id = ((Integer) object).intValue();
-        return new RootOidDefault(specification.getObjectType(), ""+id, Oid.State.PERSISTENT);
+        return new RootOidDefault(specification.getSpecId(), ""+id, Oid.State.PERSISTENT);
     }
 
     protected ObjectAdapter getAdapter(final ObjectSpecification specification, final Oid oid) {
@@ -93,7 +94,7 @@ public class IdMappingAbstract {
         if (adapter != null) {
             return adapter;
         } else {
-            return IsisContext.getPersistenceSession().recreateAdapter(oid, specification);
+            return IsisContext.getPersistenceSession().recreateAdapter(specification, oid);
         }
     }
 

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/ObjectMapping.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/ObjectMapping.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/ObjectMapping.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/ObjectMapping.java Mon May 14 22:44:57 2012
@@ -22,7 +22,7 @@ package org.apache.isis.runtimes.dflt.ob
 import java.util.Vector;
 
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByPattern;
@@ -38,7 +38,7 @@ public interface ObjectMapping {
 
     Vector<ObjectAdapter> getInstances(DatabaseConnector connector, ObjectSpecification spec, PersistenceQueryFindByPattern query);
 
-    ObjectAdapter getObject(DatabaseConnector connector, Oid oid, ObjectSpecification hint);
+    ObjectAdapter getObject(DatabaseConnector connector, TypedOid typedOid);
 
     boolean hasInstances(DatabaseConnector connector, ObjectSpecification cls);
 

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlIdentifierGenerator.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlIdentifierGenerator.java?rev=1338472&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlIdentifierGenerator.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlIdentifierGenerator.java Mon May 14 22:44:57 2012
@@ -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.runtimes.dflt.objectstores.sql;
+
+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.runtimes.dflt.runtime.system.persistence.IdentifierGenerator;
+import org.apache.isis.runtimes.dflt.runtime.transaction.ObjectPersistenceException;
+
+public class SqlIdentifierGenerator implements IdentifierGenerator {
+    
+    private final DatabaseConnectorPool connectionPool;
+    private final IdNumbers ids = new IdNumbers();
+
+    //////////////////////////////////////////////////////////////////
+    // constructor
+    //////////////////////////////////////////////////////////////////
+
+    public SqlIdentifierGenerator(final DatabaseConnectorPool connectionPool) {
+        this.connectionPool = connectionPool;
+    }
+
+    ///////////////////////////////////////////////////////
+    // API
+    ///////////////////////////////////////////////////////
+    
+    @Override
+    public String createAggregateLocalId(ObjectSpecId objectSpecId, final Object pojo, final ObjectAdapter parentAdapter) {
+        throw new SqlObjectStoreException("Aggregated objects are not supported in this store");
+    }
+
+    @Override
+    public String createTransientIdentifierFor(ObjectSpecId objectSpecId, final Object pojo) {
+        return ""+ids.nextTransientId();
+    }
+
+    @Override
+    public String createPersistentIdentifierFor(ObjectSpecId objectSpecId, Object pojo, RootOid transientRootOid) {
+        Assert.assertNotNull("No connection set up", connectionPool);
+        return "" + (int) ids.nextPersistentId(connectionPool);
+    }
+
+    
+    ///////////////////////////////////////////////////////
+    // Debug
+    ///////////////////////////////////////////////////////
+
+    @Override
+    public void debugData(final DebugBuilder debug) {
+        debug.appendln(this.toString());
+        debug.indent();
+        ids.debugData(debug);
+        debug.unindent();
+    }
+
+    @Override
+    public String debugTitle() {
+        return "Sql Identifier Generator";
+    }
+}
+
+
+
+class IdNumbers {
+
+    private static final Logger LOG = Logger.getLogger(IdNumbers.class);
+
+    private static final String NUMBER_COLUMN = "number";
+    private static final String TABLE_NAME = "isis_admin_serial_id";
+    private static int BATCH_SIZE = 50;
+    private long transientNumber = -9999999;
+    private long lastId = 0;
+    private long newBatchAt = 0;
+
+    public synchronized long nextTransientId() {
+        return transientNumber++;
+    }
+
+    public synchronized long nextPersistentId(final DatabaseConnectorPool connectionPool) {
+        if (lastId > newBatchAt) {
+            throw new SqlObjectStoreException("ID exception, last id (" + lastId + ") past new batch boundary (" + newBatchAt + ")");
+        }
+        if (lastId == newBatchAt) {
+            prepareNewBatch(connectionPool);
+        }
+        lastId++;
+        return lastId;
+    }
+
+    private void prepareNewBatch(final DatabaseConnectorPool connectionPool) {
+        final DatabaseConnector db = connectionPool.acquire();
+        try {
+            final String tableName = Sql.tableIdentifier(TABLE_NAME);
+            final String numberColumn = Sql.identifier(NUMBER_COLUMN);
+            if (!db.hasTable(tableName)) {
+                lastId = 1;
+                newBatchAt = BATCH_SIZE;
+                db.update("create table " + tableName + " (" + numberColumn + " INTEGER)");
+                db.update("insert into " + tableName + " values (" + newBatchAt + ")");
+                LOG.debug("Initial ID batch created, from " + lastId + " to " + newBatchAt);
+            } else {
+                if (db.update("update " + tableName + " set " + numberColumn + " = " + numberColumn + " + " + BATCH_SIZE) != 1) {
+                    throw new SqlObjectStoreException("failed to update serial id table; no rows updated");
+                }
+                final Results rs = db.select("select " + numberColumn + " from " + tableName);
+                rs.next();
+                newBatchAt = rs.getLong(NUMBER_COLUMN); // TODO here
+                lastId = newBatchAt - BATCH_SIZE;
+                LOG.debug("New ID batch created, from " + lastId + " to " + newBatchAt);
+                rs.close();
+            }
+        } catch (final ObjectPersistenceException e) {
+            throw e;
+        } finally {
+            connectionPool.release(db);
+        }
+    }
+
+    public void debugData(final DebugBuilder debug) {
+        debug.appendln("id", lastId);
+        debug.appendln("transient id", transientNumber);
+    }
+
+}
+

Propchange: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlIdentifierGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java?rev=1338472&r1=1338471&r2=1338472&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java Mon May 14 22:44:57 2012
@@ -35,7 +35,9 @@ import org.apache.isis.core.metamodel.ad
 import org.apache.isis.core.metamodel.adapter.oid.Oid;
 import org.apache.isis.core.metamodel.adapter.oid.RootOid;
 import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLookup;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.ObjectStore;
 import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.CreateObjectCommand;
@@ -127,7 +129,7 @@ public final class SqlObjectStore implem
 
         final RootOidDefault sqlOid = (RootOidDefault) rootOid;
         connector.addToQueryValues(sqlOid.getIdentifier());
-        connector.addToQueryValues(rootOid.getObjectType());
+        connector.addToQueryValues(rootOid.getObjectSpecId());
 
         connector.insert(sql.toString());
         connectionPool.release(connector);
@@ -411,11 +413,13 @@ public final class SqlObjectStore implem
         return (ObjectAdapter[]) instances.toArray();
     }
 
+
     @Override
-    public ObjectAdapter getObject(final Oid oid, final ObjectSpecification hint) {
+    public ObjectAdapter getObject(final TypedOid oid) {
         final DatabaseConnector connection = connectionPool.acquire();
-        final ObjectMapping mapper = objectMappingLookup.getMapping(hint, connection);
-        final ObjectAdapter object = mapper.getObject(connection, oid, hint);
+        final ObjectSpecification objectSpec = getSpecificationLookup().lookupBySpecId(oid.getObjectSpecId());
+        final ObjectMapping mapper = objectMappingLookup.getMapping(objectSpec, connection);
+        final ObjectAdapter object = mapper.getObject(connection, oid);
         connectionPool.release(connection);
         return object;
     }
@@ -433,14 +437,14 @@ public final class SqlObjectStore implem
             sql.append(" where ");
             sql.append(Defaults.getIdColumn());
             sql.append(" = ?");
-            connector.addToQueryValues(serviceSpec.getObjectType());
+            connector.addToQueryValues(serviceSpec.getSpecId());
 
             final Results results = connector.select(sql.toString());
             if (!results.next()) {
                 return null;
             } 
             final int id = results.getInt(Defaults.getPkIdLabel());
-            return RootOidDefault.create(serviceSpec.getObjectType(), ""+id);
+            return RootOidDefault.create(serviceSpec.getSpecId(), ""+id);
             
         } finally {
             connectionPool.release(connector);
@@ -477,6 +481,10 @@ public final class SqlObjectStore implem
         connectionPool.release(connector);
     }
 
+    ///////////////////////////////////////////////////////////
+    // Dependencies (injected)
+    ///////////////////////////////////////////////////////////
+
     public void setConnectionPool(final DatabaseConnectorPool connectionPool) {
         this.connectionPool = connectionPool;
     }
@@ -485,9 +493,17 @@ public final class SqlObjectStore implem
         this.objectMappingLookup = mapperLookup;
     }
 
+
+    ///////////////////////////////////////////////////////////
+    // Dependencies (from context)
+    ///////////////////////////////////////////////////////////
     
     protected ObjectAdapterLookup getAdapterManager() {
         return IsisContext.getPersistenceSession().getAdapterManager();
     }
 
+    protected SpecificationLookup getSpecificationLookup() {
+        return IsisContext.getSpecificationLoader();
+    }
+
 }



Mime
View raw message