incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1304796 [6/16] - in /incubator/isis/trunk/framework: applib/src/main/java/org/apache/isis/applib/ applib/src/test/java/org/apache/isis/applib/ core/commons/src/main/java/org/apache/isis/core/commons/config/ core/commons/src/main/java/org/a...
Date Sat, 24 Mar 2012 14:01:52 GMT
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=1304796&r1=1304795&r2=1304796&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 Sat Mar 24 14:01:35 2012
@@ -26,8 +26,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
 import org.hamcrest.CoreMatchers;
 import org.jmock.Expectations;
 import org.jmock.auto.Mock;
@@ -42,11 +40,26 @@ import org.apache.isis.core.metamodel.ad
 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.dflt.testsystem.TestProxySystemII;
-import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.simple.SerialOid;
+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.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.serial.RootOidDefault;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.runtimes.dflt.testsupport.TestSystemWithObjectStoreTestAbstract;
+import org.apache.isis.runtimes.dflt.testsupport.domain.ExamplePojoWithCollections;
+import org.apache.isis.runtimes.dflt.testsupport.domain.ExamplePojoWithReferences;
+import org.apache.isis.runtimes.dflt.testsupport.domain.ExamplePojoWithValues;
 
-public class ObjectReaderTest {
+public class ObjectReaderTest extends TestSystemWithObjectStoreTestAbstract {
+    
+    @Override
+    protected PersistenceMechanismInstaller createPersistenceMechanismInstaller() {
+        return new MongoPersistorMechanismInstaller();
+    }
 
     @Rule
     public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
@@ -67,20 +80,16 @@ public class ObjectReaderTest {
     
     private Map<String, DataEncryption> dataEncrypter;
 
-    private final NoSqlOid oid3 = new NoSqlOid(ExampleValuePojo.class.getName(), SerialOid.createPersistent(3));
-    private final NoSqlOid oid4 = new NoSqlOid(ExampleReferencePojo.class.getName(), SerialOid.createPersistent(4));
-    private final NoSqlOid oid5 = new NoSqlOid(ExampleCollectionPojo.class.getName(), SerialOid.createPersistent(5));
+    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
 
 
     @Before
     public void setup() {
-        Logger.getRootLogger().setLevel(Level.OFF);
-        final TestProxySystemII system = new TestProxySystemII();
-        system.init();
-
-        exampleValuePojoSpec = IsisContext.getSpecificationLoader().loadSpecification(ExampleValuePojo.class);
-        exampleReferencePojoSpec = IsisContext.getSpecificationLoader().loadSpecification(ExampleReferencePojo.class);
-        exampleCollectionPojoSpec = IsisContext.getSpecificationLoader().loadSpecification(ExampleCollectionPojo.class);
+        exampleValuePojoSpec = system.loadSpecification(ExamplePojoWithValues.class);
+        exampleReferencePojoSpec = system.loadSpecification(ExamplePojoWithReferences.class);
+        exampleCollectionPojoSpec = system.loadSpecification(ExamplePojoWithCollections.class);
                 
         objectReader = new ObjectReader();
 
@@ -116,7 +125,7 @@ public class ObjectReaderTest {
         context.checking(new Expectations() {
             {
                 one(reader1).readObjectType();
-                will(returnValue(ExampleValuePojo.class.getName()));
+                will(returnValue(ExamplePojoWithValues.class.getName()));
 
                 one(reader1).readId();
                 will(returnValue("3"));
@@ -141,7 +150,7 @@ public class ObjectReaderTest {
         assertEquals(oid3, readObject.getOid());
         assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
 
-        final ExampleValuePojo pojo = (ExampleValuePojo) readObject.getObject();
+        final ExamplePojoWithValues pojo = (ExamplePojoWithValues) readObject.getObject();
         assertEquals("Fred Smith", pojo.getName());
         assertEquals(34, pojo.getSize());
 
@@ -154,7 +163,7 @@ public class ObjectReaderTest {
         context.checking(new Expectations() {
             {
                 one(reader2).readObjectType();
-                will(returnValue(ExampleReferencePojo.class.getName()));
+                will(returnValue(ExamplePojoWithReferences.class.getName()));
 
                 one(reader2).readId();
                 will(returnValue("4"));
@@ -191,21 +200,21 @@ public class ObjectReaderTest {
         assertEquals(oid4, readObject.getOid());
         assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
 
-        final ExampleReferencePojo pojo = (ExampleReferencePojo) readObject.getObject();
+        final ExamplePojoWithReferences pojo = (ExamplePojoWithReferences) readObject.getObject();
         assertEquals(null, pojo.getReference2());
-        assertThat(pojo.getReference1(), CoreMatchers.instanceOf(ExampleValuePojo.class));
+        assertThat(pojo.getReference1(), CoreMatchers.instanceOf(ExamplePojoWithValues.class));
 
         context.assertIsSatisfied();
     }
 
     @Test
     public void testReadingCollection() throws Exception {
-        final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExampleValuePojo.class);
+        final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExamplePojoWithValues.class);
         reader2 = context.mock(StateReader.class, "reader 2");
         context.checking(new Expectations() {
             {
                 one(reader2).readObjectType();
-                will(returnValue(ExampleCollectionPojo.class.getName()));
+                will(returnValue(ExamplePojoWithCollections.class.getName()));
 
                 one(reader2).readId();
                 will(returnValue("5"));
@@ -244,12 +253,12 @@ public class ObjectReaderTest {
         assertEquals(oid5, readObject.getOid());
         assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
 
-        final ExampleCollectionPojo pojo = (ExampleCollectionPojo) readObject.getObject();
-        final List<ExampleValuePojo> collection2 = pojo.getHomogenousCollection();
+        final ExamplePojoWithCollections pojo = (ExamplePojoWithCollections) readObject.getObject();
+        final List<ExamplePojoWithValues> collection2 = pojo.getHomogenousCollection();
         assertEquals(2, collection2.size());
 
-        assertThat(collection2.get(0), CoreMatchers.instanceOf(ExampleValuePojo.class));
-        assertThat(collection2.get(1), CoreMatchers.instanceOf(ExampleValuePojo.class));
+        assertThat(collection2.get(0), CoreMatchers.instanceOf(ExamplePojoWithValues.class));
+        assertThat(collection2.get(1), CoreMatchers.instanceOf(ExamplePojoWithValues.class));
 
         context.assertIsSatisfied();
     }
@@ -272,12 +281,12 @@ public class ObjectReaderTest {
             }
         });
 
-        final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExampleValuePojo.class);
-        final ObjectAdapter readObject = IsisContext.getPersistenceSession().recreateAdapter(SerialOid.createPersistent(4), specification);
+        final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExamplePojoWithValues.class);
+        final ObjectAdapter readObject = IsisContext.getPersistenceSession().recreateAdapter(RootOidDefault.create("EVP", ""+4), specification);
 
         objectReader.update(reader1, keyCreator, versionCreator, dataEncrypter, readObject);
 
-        final ExampleValuePojo pojo = (ExampleValuePojo) readObject.getObject();
+        final ExamplePojoWithValues pojo = (ExamplePojoWithValues) readObject.getObject();
         assertEquals("Fred Smith", pojo.getName());
         assertEquals(34, pojo.getSize());
 

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/SystemTest.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/SystemTest.java?rev=1304796&r1=1304795&r2=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/SystemTest.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/SystemTest.java Sat Mar 24 14:01:35 2012
@@ -19,31 +19,32 @@
 
 package org.apache.isis.runtimes.dflt.objectstores.nosql;
 
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Before;
 import org.junit.Test;
 
 import org.apache.isis.core.commons.debug.DebugBuilder;
 import org.apache.isis.core.commons.debug.DebugString;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.objectstores.dflt.testsystem.TestProxySystemII;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo.MongoPersistorMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-
-public class SystemTest {
-
-    @Before
-    public void setup() {
-        Logger.getRootLogger().setLevel(Level.OFF);
-        final TestProxySystemII system = new TestProxySystemII();
-        system.init();
-
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.runtimes.dflt.testsupport.TestSystemWithObjectStoreTestAbstract;
+import org.apache.isis.runtimes.dflt.testsupport.domain.ExamplePojoWithReferences;
+
+public class SystemTest extends TestSystemWithObjectStoreTestAbstract {
+
+    @Override
+    protected PersistenceMechanismInstaller createPersistenceMechanismInstaller() {
+        return new MongoPersistorMechanismInstaller();
     }
 
+    /**
+     * What's being tested here???
+     */
     @Test
     public void test() {
-        final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExampleReferencePojo.class);
+        final ObjectSpecification specification = system.loadSpecification(ExamplePojoWithReferences.class);
         final ObjectAdapter object = IsisContext.getPersistenceSession().createInstance(specification);
 
         final DebugBuilder debug = new DebugString();

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=1304796&r1=1304795&r2=1304796&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 Sat Mar 24 14:01:35 2012
@@ -22,8 +22,10 @@ package org.apache.isis.runtimes.dflt.ob
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.jmock.Expectations;
-import org.jmock.Mockery;
+import org.jmock.auto.Mock;
+import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.isis.core.commons.config.IsisConfiguration;
@@ -32,59 +34,81 @@ import org.apache.isis.core.metamodel.ad
 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.runtimes.dflt.objectstores.dflt.testsystem.TestProxySystemII;
-import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.simple.SerialOid;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.objectstores.dflt.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateWriter;
+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.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.serial.RootOidDefault;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.testsupport.TestSystem;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.runtimes.dflt.testsupport.TestSystemWithObjectStoreTestAbstract;
+import org.apache.isis.runtimes.dflt.testsupport.domain.ExamplePojoWithCollections;
+import org.apache.isis.runtimes.dflt.testsupport.domain.ExamplePojoWithReferences;
+import org.apache.isis.runtimes.dflt.testsupport.domain.ExamplePojoWithValues;
+
+public class WriteObjectCommandTest extends TestSystemWithObjectStoreTestAbstract {
+    
+    @Override
+    protected PersistenceMechanismInstaller createPersistenceMechanismInstaller() {
+        return new MongoPersistorMechanismInstaller();
+    }
 
-public class WriteObjectCommandTest {
-    private TrialObjects testObjects;
-    private ObjectAdapter object1;
-    private ObjectSpecification specification;
-    private ObjectAdapter object2;
-    private ObjectAdapter object3;
-    private ObjectAdapter object4;
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+    @Mock
     private StateWriter writer;
+    @Mock
     private VersionCreator versionCreator;
+    @Mock
     private KeyCreator keyCreator;
+    @Mock
     private NoSqlCommandContext commandContext;
-    private Mockery context;
+
     private DataEncryption dataEncrypter;
 
+    private ObjectAdapter adapter1;
+    private ObjectSpecification specification;
+    private ObjectAdapter adapter2;
+    private ObjectAdapter adapter3;
+    private ObjectAdapter object4;
+    
+
+    private final String objectType = "FOO";
+
+    private TestSystem system;
+
     @Before
     public void setup() {
-        Logger.getRootLogger().setLevel(Level.OFF);
-        final TestProxySystemII system = new TestProxySystemII();
-        system.init();
 
-        testObjects = new TrialObjects();
-
-        final ExampleValuePojo pojo1 = new ExampleValuePojo();
+        final ExamplePojoWithValues pojo1 = new ExamplePojoWithValues();
+        final String objectType = "EVP";
+        
         pojo1.setName("Fred Smith");
         pojo1.setSize(108);
-        SerialOid oid = SerialOid.createPersistent(3);
-        object1 = testObjects.createAdapter(pojo1, oid);
-        specification = object1.getSpecification();
+        adapter1 = system.recreateAdapter(pojo1, RootOidDefault.create(objectType, "3"));
 
-        final ExampleValuePojo pojo2 = new ExampleValuePojo();
+        final ExamplePojoWithValues pojo2 = new ExamplePojoWithValues();
         pojo2.setName("John Brown");
-        oid = SerialOid.createPersistent(4);
-        object2 = testObjects.createAdapter(pojo2, oid);
+        adapter2 = system.recreateAdapter(pojo2, RootOidDefault.create(objectType, "4"));
 
-        final ExampleReferencePojo pojo3 = new ExampleReferencePojo();
+        final ExamplePojoWithReferences pojo3 = new ExamplePojoWithReferences();
         pojo3.setReference1(pojo1);
-        oid = SerialOid.createPersistent(5);
-        object3 = testObjects.createAdapter(pojo3, oid);
+        adapter3 = system.recreateAdapter(pojo3, RootOidDefault.create(objectType, "5"));
+
+        final ExamplePojoWithCollections adapter4 = new ExamplePojoWithCollections();
+        adapter4.getHomogenousCollection().add(pojo1);
+        adapter4.getHomogenousCollection().add(pojo2);
+        
+        object4 = system.recreateAdapter(adapter4, RootOidDefault.create(objectType, "6"));
 
-        final ExampleCollectionPojo pojo4 = new ExampleCollectionPojo();
-        pojo4.getHomogenousCollection().add(pojo1);
-        pojo4.getHomogenousCollection().add(pojo2);
-        oid = SerialOid.createPersistent(6);
-        object4 = testObjects.createAdapter(pojo4, oid);
-
-        context = new Mockery();
-        writer = context.mock(StateWriter.class);
-        commandContext = context.mock(NoSqlCommandContext.class);
-        keyCreator = context.mock(KeyCreator.class);
-        versionCreator = context.mock(VersionCreator.class);
+        specification = adapter1.getSpecification();
 
         final Version version = new SerialNumberVersion(2, "username", null);
 
@@ -119,18 +143,19 @@ public class WriteObjectCommandTest {
                 throw new UnexpectedCallException();
             }
         };
-
     }
 
+
     @Test
     public void objectWithValues() throws Exception {
 
         context.checking(new Expectations() {
+
             {
                 one(commandContext).createStateWriter(specification.getFullIdentifier());
                 will(returnValue(writer));
 
-                one(keyCreator).key(SerialOid.createPersistent(3));
+                one(keyCreator).key(RootOidDefault.create(objectType, ""+3));
                 will(returnValue("3"));
 
                 one(writer).writeId("3");
@@ -148,7 +173,7 @@ public class WriteObjectCommandTest {
             }
         });
 
-        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, object1).execute(commandContext);
+        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, adapter1).execute(commandContext);
 
         context.assertIsSatisfied();
     }
@@ -158,16 +183,16 @@ public class WriteObjectCommandTest {
 
         context.checking(new Expectations() {
             {
-                one(commandContext).createStateWriter(object3.getSpecification().getFullIdentifier());
+                one(commandContext).createStateWriter(adapter3.getSpecification().getFullIdentifier());
                 will(returnValue(writer));
 
-                one(keyCreator).key(SerialOid.createPersistent(5));
+                one(keyCreator).key(RootOidDefault.create(objectType, ""+5));
                 will(returnValue("5"));
-                one(keyCreator).reference(object1);
+                one(keyCreator).reference(adapter1);
                 will(returnValue("ref@3"));
 
                 one(writer).writeId("5");
-                one(writer).writeType(object3.getSpecification().getFullIdentifier());
+                one(writer).writeType(adapter3.getSpecification().getFullIdentifier());
                 one(writer).writeField("reference1", "ref@3");
                 one(writer).writeField("reference2", null);
                 one(writer).writeVersion(null, "2");
@@ -179,7 +204,7 @@ public class WriteObjectCommandTest {
             }
         });
 
-        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, object3).execute(commandContext);
+        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, adapter3).execute(commandContext);
 
         context.assertIsSatisfied();
     }
@@ -192,14 +217,14 @@ public class WriteObjectCommandTest {
                 one(commandContext).createStateWriter(object4.getSpecification().getFullIdentifier());
                 will(returnValue(writer));
 
-                one(keyCreator).key(SerialOid.createPersistent(6));
+                one(keyCreator).key(RootOidDefault.create(objectType, ""+6));
                 will(returnValue("6"));
                 one(writer).writeId("6");
                 one(writer).writeType(object4.getSpecification().getFullIdentifier());
 
-                one(keyCreator).reference(object1);
+                one(keyCreator).reference(adapter1);
                 will(returnValue("ref@3"));
-                one(keyCreator).reference(object2);
+                one(keyCreator).reference(adapter2);
                 will(returnValue("ref@4"));
 
                 one(writer).writeField("homogenousCollection", "ref@3|ref@4|");

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java (from r1301918, incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/ChecksummingPerfomance.java&r1=1301918&r2=1304796&rev=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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 Sat Mar 24 14:01:35 2012
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.runtimes.dflt.objectstores.nosql.file;
+package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file;
 
 import java.io.BufferedReader;
 import java.io.FileInputStream;
@@ -24,7 +24,7 @@ import java.io.InputStreamReader;
 import java.util.zip.CRC32;
 import java.util.zip.CheckedInputStream;
 
-import org.apache.isis.runtimes.dflt.objectstores.nosql.file.server.Util;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
 
 public class ChecksummingPerfomance {
 

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java (from r1301918, incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/ClientConnectionTest.java&r1=1301918&r2=1304796&rev=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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 Sat Mar 24 14:01:35 2012
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.runtimes.dflt.objectstores.nosql.file;
+package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file;
 
 import static org.hamcrest.Matchers.containsString;
 import static org.junit.Assert.assertEquals;
@@ -33,6 +33,8 @@ 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;
 

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java (from r1301918, incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReaderTest.java&r1=1301918&r2=1304796&rev=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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 Sat Mar 24 14:01:35 2012
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.runtimes.dflt.objectstores.nosql.file;
+package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file;
 
 import static org.junit.Assert.assertEquals;
 
@@ -26,7 +26,8 @@ import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 
-import org.apache.isis.runtimes.dflt.objectstores.nosql.StateReader;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateReader;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.JsonStateReader;
 
 public class JsonStateReaderTest {
 

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java (from r1301918, incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriterTest.java&r1=1301918&r2=1304796&rev=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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 Sat Mar 24 14:01:35 2012
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.isis.runtimes.dflt.objectstores.nosql.file;
+package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file;
 
 import static org.junit.Assert.assertEquals;
 
@@ -26,7 +26,8 @@ import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 
-import org.apache.isis.runtimes.dflt.objectstores.nosql.StateWriter;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateWriter;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.JsonStateWriter;
 
 public class JsonStateWriterTest {
 
@@ -34,7 +35,7 @@ public class JsonStateWriterTest {
 
     @Before
     public void setup() {
-        writer = new JsonStateWriter(null, "spec-name");
+        writer = new JsonStateWriter();
     }
 
     @Test

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.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/server/DataReaderTest.java?rev=1304796&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java Sat Mar 24 14:01:35 2012
@@ -0,0 +1,88 @@
+/*
+ *  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.db.file.server;
+
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.DataFileReader;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.FileServerException;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
+
+public class DataReaderTest {
+
+    private DataFileReader reader;
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        Util.setDirectory("target/test", "services", "logs", "archive");
+        Util.ensureDirectoryExists();
+        new File("target/test/type").mkdir();
+    }
+
+    @Test
+    public void noFileCausesException() throws Exception {
+        try {
+            new DataFileReader("type", "nonexistant");
+            fail();
+        } catch (final FileNotFoundException expected) {
+        }
+    }
+
+    @Test
+    public void noDataRead() throws Exception {
+        final FileWriter writer = new FileWriter("target/test/type/0013.data");
+        writer.write("");
+        writer.close();
+
+        try {
+            reader = new DataFileReader("type", "0013");
+            fail();
+        } catch (final FileServerException expected) {
+            assertThat(expected.getMessage(), startsWith("No data in file:"));
+        }
+
+    }
+
+    @Test
+    public void readIdAndVersion() throws Exception {
+        final FileWriter writer = new FileWriter("target/test/type/0012.data");
+        writer.write("class.type 0012 17\n{data}");
+        writer.close();
+
+        reader = new DataFileReader("type", "0012");
+
+        assertEquals("0012", reader.getId());
+        assertEquals("17", reader.getVersion());
+
+        final String data = reader.getData();
+        assertEquals("{data}\n", data);
+        reader.close();
+    }
+}

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

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.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/server/DataWriterTest.java?rev=1304796&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java Sat Mar 24 14:01:35 2012
@@ -0,0 +1,112 @@
+/*
+ *  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.db.file.server;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.DataFileWriter;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.FileContent;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
+
+public class DataWriterTest {
+
+    private static final String TARGET_DIRECTORY = "target/test/";
+    private static final String FULLY_QUALIFIED_CLASSNAME = "org.domain.Class";
+    private static final String FULLY_QUALIFIED_CLASSNAME_2 = "org.domain.Class2";
+    private DataFileWriter writer;
+
+    @Before
+    public void setUp() throws Exception {
+        Logger.getRootLogger().setLevel(Level.OFF);
+        Util.setDirectory(TARGET_DIRECTORY, "services", "logs", "archive");
+        Util.ensureDirectoryExists();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (writer != null) {
+            writer.close();
+        }
+    }
+
+    @Test
+    public void testWriteData() throws Exception {
+        final File file = new File(TARGET_DIRECTORY + FULLY_QUALIFIED_CLASSNAME + "/1030.data");
+        file.mkdirs();
+        file.createNewFile();
+        Assert.assertTrue(file.exists());
+
+        final List<FileContent> files = new ArrayList<FileContent>();
+        files.add(new FileContent('I', "1023", "1", "2", FULLY_QUALIFIED_CLASSNAME, "{data1}"));
+        files.add(new FileContent('U', "1024", "21", "22", FULLY_QUALIFIED_CLASSNAME, "{data2}"));
+        files.add(new FileContent('D', "1030", "66", "", FULLY_QUALIFIED_CLASSNAME, ""));
+        final DataFileWriter writer = new DataFileWriter(files);
+        writer.writeData();
+
+        BufferedReader reader = new BufferedReader(new FileReader(TARGET_DIRECTORY + FULLY_QUALIFIED_CLASSNAME + "/1023.data"));
+        Assert.assertEquals("org.domain.Class 1023 2", reader.readLine());
+        Assert.assertEquals("{data1}", reader.readLine());
+
+        reader = new BufferedReader(new FileReader(TARGET_DIRECTORY + FULLY_QUALIFIED_CLASSNAME + "/1024.data"));
+        Assert.assertEquals(FULLY_QUALIFIED_CLASSNAME + " 1024 22", reader.readLine());
+        Assert.assertEquals("{data2}", reader.readLine());
+
+        Assert.assertFalse("file still exists", file.exists());
+    }
+
+    @Test
+    public void createsTypeDirectory() throws Exception {
+        final String dir = TARGET_DIRECTORY + FULLY_QUALIFIED_CLASSNAME_2;
+        final File file = deleteDirectory(dir);
+        Assert.assertFalse(file.exists());
+
+        final List<FileContent> files = new ArrayList<FileContent>();
+        files.add(new FileContent('I', "1023", "1", "2", FULLY_QUALIFIED_CLASSNAME_2, "{data1}"));
+        writer = new DataFileWriter(files);
+        writer.writeData();
+
+        Assert.assertTrue(file.exists());
+    }
+
+    protected File deleteDirectory(final String dir) {
+        final File file = new File(dir);
+        if (file.exists()) {
+            for (final File f : file.listFiles()) {
+                f.delete();
+            }
+            file.delete();
+
+        }
+        return file;
+    }
+
+}

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

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.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/server/FileServerTest.java?rev=1304796&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java Sat Mar 24 14:01:35 2012
@@ -0,0 +1,277 @@
+/*
+ *  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.db.file.server;
+
+import static org.apache.isis.core.commons.matchers.IsisMatchers.existsAndNotEmpty;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.lang.IoUtils;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.FileServerProcessor;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.ServerConnection;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
+
+public class FileServerTest {
+    private FileServerProcessor server;
+    private File logFile1;
+    private File logFile2;
+    private ByteArrayOutputStream out;
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        Util.setDirectory("target/test", "services", "logs", "archive");
+        Util.ensureDirectoryExists();
+        new File("target/test/type").mkdir();
+    }
+
+    @Before
+    public void startup() {
+        logFile1 = recreateFile("target/test/logs", "recovery0.log");
+        logFile2 = recreateFile("target/test/logs", "recovery1.log");
+
+        server = new FileServerProcessor();
+        server.startup();
+
+        out = new ByteArrayOutputStream();
+    }
+
+    private static File recreateFile(final String parent, final String child) {
+        final File file = new File(parent, child);
+        file.delete();
+        assertFalse(file.exists());
+        return file;
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (server != null) {
+            server.shutdown();
+        }
+    }
+
+    @Test
+    public void cantReadOrWriteAfterShutdown() throws Exception {
+        final InputStream in = IoUtils.asUtf8ByteStream("R[org.domain.Class 1025]\n");
+        final ByteArrayOutputStream out = new ByteArrayOutputStream();
+        final ServerConnection connection = new ServerConnection(in, out);
+
+        server.shutdown();
+        server.process(connection);
+        assertThat(new String(out.toByteArray(), "utf-8"), is(equalTo("abort\n")));
+    }
+
+    @Test
+    public void writeAbortedAsDataNotComplete() throws Exception {
+        final InputStream in = IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025 null 1  \n{da");
+        final ServerConnection connection = new ServerConnection(in, out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(containsString("stream ended prematurely while reading data, aborting request")));
+    }
+
+    @Test
+    public void writeAbortsIfMissingNextDataBlock() throws Exception {
+        final InputStream in = IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025 null 1  \n{data1}\n\n");
+        final ServerConnection connection = new ServerConnection(in, out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(containsString("stream ended prematurely while reading header, aborting request")));
+    }
+
+    @Test
+    public void writeAbortedAsHeaderNotComplete() throws Exception {
+        final InputStream in = IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025");
+        final ServerConnection connection = new ServerConnection(in, out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(containsString("invalid header string, aborting request")));
+    }
+
+    @Test
+    public void writeCreatesFilesUsingDataWriter() throws Exception {
+        final File file1 = new File("target/test/org.domain.Class", "1025.data");
+        final File file2 = new File("target/test/org.domain.Class", "1026.data");
+        file1.delete();
+        file2.delete();
+        assertFalse(file1.exists());
+        assertFalse(file2.exists());
+
+        final InputStream in = IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025 null 1  \n{data1}\n\nIorg.domain.Class 1026 null 1\n{data2}\n\n\n");
+        final ServerConnection connection = new ServerConnection(in, out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(equalTo("ok\n")));
+        assertThat(file1, existsAndNotEmpty());
+        assertThat(file2, existsAndNotEmpty());
+    }
+
+    @Test
+    public void writeUpdatesFilesUsingDataWriter() throws Exception {
+        final File file2 = new File("target/test/org.domain.Class", "1026.data");
+        final FileWriter fileWriter = new FileWriter(file2);
+        final String originalData = "org.domain.Class 1026 21 {}";
+        fileWriter.write(originalData);
+        fileWriter.close();
+
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("W\nUorg.domain.Class 1026 21 22 \n{data2}\n\n\n"), out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(equalTo("ok\n")));
+        assertThat(file2.length(), is(greaterThan((long) originalData.length())));
+    }
+
+    @Test
+    public void writeUpdateFailsWhenVersionsDontMatch() throws Exception {
+        final File file2 = new File("target/test/org.domain.Class", "1026.data");
+        final FileWriter fileWriter = new FileWriter(file2);
+        final String originalData = "org.domain.Class 1026 21\n{datax}\n\n\n***";
+        fileWriter.write(originalData);
+        fileWriter.close();
+
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("W\nUorg.domain.Class 1026 19 21 \n{data2}\n\n\n"), out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(equalTo("error\nmismatch between FileContent version (19) and DataReader version (21)\n")));
+    }
+
+    @Test
+    public void writeCreatesLogFile() throws Exception {
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025 6 7\n{data1}\n\n\n"), out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(equalTo("ok\n")));
+
+        assertThat(logFile1, existsAndNotEmpty());
+        assertThat(logFile2, not(existsAndNotEmpty()));
+    }
+
+    @Test
+    public void readNonExistingFileThrowsException() throws Exception {
+        final File file1 = new File("target/test/org.domain.Class", "2020.data");
+        file1.delete();
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class 2020\n\n"), out);
+        server.process(connection);
+
+        final String string = out.toString();
+        assertThat(string, startsWith("not-found"));
+        assertThat(string, containsString("File not found for org.domain.Class/2020"));
+    }
+
+    @Test
+    public void aTestTheTests() throws Exception {
+        final File dir = new File("target/test/org.domain.Class");
+        assertTrue(dir.exists());
+
+        final File file1 = new File("target/test/org.domain.Class", "2025.data");
+        assertTrue(file1.getParentFile().exists());
+
+        final FileWriter fileWriter = new FileWriter(file1);
+        assertNotNull(fileWriter);
+        fileWriter.write("data");
+        fileWriter.close();
+    }
+
+    @Test
+    public void copyOfReadTest() throws Exception {
+        final File file1 = new File("target/test/org.domain.Class", "2025.data");
+        final FileWriter fileWriter = new FileWriter(file1);
+        fileWriter.write("type 1025 1\n{data1}");
+        fileWriter.close();
+
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class 2025\n\n"), out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(equalTo("ok\n{data1}\n\n")));
+    }
+
+    @Test
+    public void ReadFailIfEndsEarly() throws Exception {
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class 2025\n"), out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(containsString("stream ended prematurely while reading end of command, aborting request")));
+    }
+
+    @Test
+    public void lookReadRenamed() throws Exception {
+        final File file1 = new File("target/test/org.domain.Class", "2025.data");
+        final FileWriter fileWriter = new FileWriter(file1);
+        fileWriter.write("type 1025 1\n{data1}");
+        fileWriter.close();
+
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class 2025\n\n"), out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(equalTo("ok\n{data1}\n\n")));
+    }
+
+    @Test
+    public void read2() throws Exception {
+        final File file1 = new File("target/test/org.domain.Class", "2025.data");
+        final FileWriter fileWriter = new FileWriter(file1);
+        fileWriter.write("type 1025 1\n{data1}");
+        fileWriter.close();
+
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class 2025\n\n"), out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(equalTo("ok\n{data1}\n\n")));
+    }
+
+    @Test
+    public void hasNoInstances() throws Exception {
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Iorg.domain.None\n\n"), out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(equalTo("ok false\n")));
+    }
+
+    @Test
+    public void hasInstances() throws Exception {
+        final File file1 = new File("target/test/org.domain.Class", "2025.data");
+        final FileWriter fileWriter = new FileWriter(file1);
+        fileWriter.write("type 1025 1\n{data1}");
+        fileWriter.close();
+
+        final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Iorg.domain.Class\n\n"), out);
+        server.process(connection);
+
+        assertThat(out.toString(), is(equalTo("ok true\n")));
+    }
+
+}

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

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.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/server/LockManagerTest.java?rev=1304796&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java Sat Mar 24 14:01:35 2012
@@ -0,0 +1,57 @@
+/*
+ *  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.db.file.server;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.LockManager;
+
+public class LockManagerTest {
+
+    private LockManager manager;
+
+    @Before
+    public void setUp() throws Exception {
+        manager = new LockManager();
+    }
+
+    @Test
+    public void readDoesNotBlockReads() throws Exception {
+        final Thread tx1 = new Thread();
+        final Thread tx2 = new Thread();
+        manager.acquireRead("2", tx1);
+        manager.acquireRead("2", tx2);
+        manager.release("2", tx1);
+        manager.release("2", tx2);
+    }
+
+    @Test
+    public void writeAbortsSecondWrite() throws Exception {
+        final Thread tx1 = new Thread();
+        final Thread tx2 = new Thread();
+        assertTrue(manager.acquireWrite("2", tx1));
+        assertFalse(manager.acquireWrite("2", tx2));
+    }
+
+}

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

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.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/server/LogWriterTest.java?rev=1304796&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java Sat Mar 24 14:01:35 2012
@@ -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.runtimes.dflt.objectstores.nosql.db.file.server;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.DataFileWriter;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.FileContent;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.LogWriter;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
+
+public class LogWriterTest {
+
+    private LogWriter logger;
+    private File logFile1;
+    private File logFile2;
+    private List<FileContent> items;
+
+    @BeforeClass
+    public static void directory() {
+        Util.setDirectory("target/test", "services", "logs", "archive");
+        Util.ensureDirectoryExists();
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        logFile1 = new File("target/test/logs", "recovery0.log");
+        logFile1.delete();
+        assertFalse(logFile1.exists());
+        logFile2 = new File("target/test/logs", "recovery1.log");
+        logFile2.delete();
+        assertFalse(logFile2.exists());
+
+        logger = new LogWriter();
+        logger.startup();
+
+        items = new ArrayList<FileContent>();
+        items.add(new FileContent('U', "20", "6", "7", "type", "{data}"));
+        new DataFileWriter(items);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (logger != null) {
+            logger.shutdown();
+        }
+    }
+
+    @Test
+    public void newLogFileCreatedOnStartup() throws Exception {
+        assertTrue(logFile1.exists() && logFile1.length() == 0);
+        assertFalse(logFile2.exists());
+    }
+
+    @Test
+    public void logsData() throws Exception {
+        logger.logWrites(items);
+
+        final BufferedReader reader = new BufferedReader(new FileReader(logFile1));
+        String line = reader.readLine();
+        line = reader.readLine();
+        Assert.assertEquals("Utype 20 7", line);
+        line = reader.readLine();
+        Assert.assertEquals("{data}", line);
+        reader.close();
+
+    }
+
+    @Test
+    public void logAddedToExistingFile() throws Exception {
+        logger.logWrites(items);
+        assertTrue(logFile1.exists() && logFile1.length() > 0);
+        assertFalse(logFile2.exists());
+    }
+
+    @Test
+    public void logAddedToNewFileWhenRotated() throws Exception {
+        logger.logWrites(items);
+        logger.startNewFile();
+        logger.logWrites(items);
+        assertTrue(logFile2.exists() && logFile1.length() > 0);
+    }
+}

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

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java (from r1301918, incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/DemoMongo.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/DemoMongo.java?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/DemoMongo.java&r1=1301918&r2=1304796&rev=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/DemoMongo.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java Sat Mar 24 14:01:35 2012
@@ -17,7 +17,7 @@
  *  under the License.
  */
 
-package org.apache.isis.runtimes.dflt.objectstores.nosql.mongo;
+package org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo;
 
 import java.util.Set;
 

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoDbTest.java (from r1301918, incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoDbTest.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoDbTest.java&r1=1301918&r2=1304796&rev=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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 Sat Mar 24 14:01:35 2012
@@ -17,7 +17,7 @@
  *  under the License.
  */
 
-package org.apache.isis.runtimes.dflt.objectstores.nosql.mongo;
+package org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertEquals;
@@ -31,30 +31,29 @@ import com.mongodb.DB;
 import com.mongodb.DBCollection;
 import com.mongodb.Mongo;
 
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
 import org.junit.Before;
 import org.junit.Test;
 
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.ExampleValuePojo;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlKeyCreator;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.TrialObjects;
-import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.simple.SerialOid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreatorDefault;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.serial.RootOidDefault;
+import org.apache.isis.runtimes.dflt.testsupport.TestSystemWithObjectStoreTestAbstract;
+import org.apache.isis.runtimes.dflt.testsupport.domain.ExamplePojoWithValues;
 
-public class MongoDbTest {
+public class MongoDbTest extends TestSystemWithObjectStoreTestAbstract {
+    
     private MongoDb db;
-    private TrialObjects testObjects;
-    private ObjectSpecification specification;
-    private ObjectAdapter object;
-    private SerialOid oid;
+    
     private DB testDb;
 
+    @Override
+    protected PersistenceMechanismInstaller createPersistenceMechanismInstaller() {
+        return new MongoPersistorMechanismInstaller();
+    }
+
     @Before
-    public void setup() throws Exception {
-        Logger.getRootLogger().setLevel(Level.OFF);
-        testObjects = new TrialObjects();
+    public void setupMongo() throws Exception {
 
         try {
             final Mongo m = new Mongo();
@@ -66,15 +65,14 @@ public class MongoDbTest {
             return;
         }
 
-        db = new MongoDb("localhost", 0, "testdb", new NoSqlKeyCreator());
+        db = new MongoDb("localhost", 0, "testdb", new KeyCreatorDefault());
         db.open();
 
-        final ExampleValuePojo pojo = new ExampleValuePojo();
+        final ExamplePojoWithValues pojo = new ExamplePojoWithValues();
         pojo.setName("Fred Smith");
-        oid = SerialOid.createTransient(3);
-        object = testObjects.createAdapter(pojo, oid);
-        specification = object.getSpecification();
-
+        RootOid oid = RootOidDefault.createTransient("EPV|3");
+        adapter1 = system.createTransient(pojo, oid);
+        specification = adapter1.getSpecification();
     }
 
     @Test
@@ -126,4 +124,5 @@ public class MongoDbTest {
     public void unknownServiceIds() throws Exception {
         assertNull(db.getService("two"));
     }
+
 }

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderTest.java (from r1301918, incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderTest.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReaderTest.java&r1=1301918&r2=1304796&rev=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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 Sat Mar 24 14:01:35 2012
@@ -17,7 +17,7 @@
  *  under the License.
  */
 
-package org.apache.isis.runtimes.dflt.objectstores.nosql.mongo;
+package org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo;
 
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.not;
@@ -35,6 +35,8 @@ import org.apache.log4j.Logger;
 import org.junit.Before;
 import org.junit.Test;
 
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo.MongoStateReader;
+
 public class MongoStateReaderTest {
 
     private static final String SPEC_NAME = "org.test.Object";

Copied: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterTest.java (from r1301918, incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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?p2=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterTest.java&p1=incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriterTest.java&r1=1301918&r2=1304796&rev=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/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 Sat Mar 24 14:01:35 2012
@@ -17,7 +17,7 @@
  *  under the License.
  */
 
-package org.apache.isis.runtimes.dflt.objectstores.nosql.mongo;
+package org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertEquals;
@@ -34,6 +34,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;
+
 public class MongoStateWriterTest {
 
     private static final String SPEC_NAME = "org.test.Object";

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractMapper.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/AbstractMapper.java?rev=1304796&r1=1304795&r2=1304796&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractMapper.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractMapper.java Sat Mar 24 14:01:35 2012
@@ -20,66 +20,33 @@
 package org.apache.isis.runtimes.dflt.objectstores.sql;
 
 import java.util.Date;
-import java.util.Hashtable;
 
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
 import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.objectstores.sql.SqlOid.State;
 
-public abstract class AbstractMapper {
-    private FieldMappingLookup fieldMappingLookup;
-    private final Hashtable<String, PrimaryKeyMapper> keyMapping = new Hashtable<String, PrimaryKeyMapper>();
 
+public abstract class AbstractMapper {
+    
     public abstract void createTables(final DatabaseConnector connector);
 
     protected boolean needsTables(final DatabaseConnector connector) {
         return false;
     }
 
-    public final void shutdown() {
-    }
-
-    public void startup(final DatabaseConnector connector, final FieldMappingLookup fieldMappingLookup) {
-        this.fieldMappingLookup = fieldMappingLookup;
+    public void startup(final DatabaseConnector connector) {
         if (needsTables(connector)) {
             createTables(connector);
         }
     }
 
-    protected FieldMappingLookup getFieldMappingLookup() {
-        return fieldMappingLookup;
-    }
-
-    // TODO remove
-    protected Oid recreateOid(final Results rs, final ObjectSpecification cls, final String column) {
-        PrimaryKey key;
-        if (keyMapping.containsKey(column)) {
-            key = keyMapping.get(column).generateKey(rs, column);
-        } else {
-            final Object object = rs.getObject(column);
-            if (object == null) {
-                return null;
-            } else {
-                final int id = ((Integer) object).intValue();
-                key = new IntegerPrimaryKey(id);
-            }
-        }
-        final Oid oid = new SqlOid(cls.getFullIdentifier(), key, State.PERSISTENT);
-        return oid;
-    }
-
-    // TODO remove
-    protected void addPrimaryKeyMapper(final String columnName, final PrimaryKeyMapper mapper) {
-        keyMapping.put(columnName, mapper);
+    public final void shutdown() {
     }
 
     protected String asSqlName(final String name) {
         return Sql.sqlName(name);
     }
-
-    // TODO remove
+    
     protected SerialNumberVersion createVersion(final long versionSequence) {
         return new SerialNumberVersion(versionSequence, "", new Date());
     }
+
 }

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=1304796&r1=1304795&r2=1304796&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 Sat Mar 24 14:01:35 2012
@@ -21,9 +21,9 @@ package org.apache.isis.runtimes.dflt.ob
 
 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.RootOid;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.objectstores.sql.SqlOid.State;
-import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.simple.SerialOid;
+import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.serial.RootOidDefault;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
 
@@ -38,15 +38,15 @@ public class IdMappingAbstract {
         return column;
     }
 
-    public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final Oid oid) {
+    public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final RootOid oid) {
         sql.append(column);
         sql.append(" = ");
         appendObjectId(connector, sql, oid);
     }
 
-    public void appendObjectId(final DatabaseConnector connector, final StringBuffer sql, final Oid oid) {
+    public void appendObjectId(final DatabaseConnector connector, final StringBuffer sql, final RootOid oid) {
         sql.append("?");
-        connector.addToQueryValues(primaryKeyAsObject(oid));
+        connector.addToQueryValues(primaryKey(oid));
     }
 
     public void appendCreateColumnDefinitions(final StringBuffer sql) {
@@ -69,42 +69,22 @@ public class IdMappingAbstract {
         if (object == null) {
             sql.append("NULL");
         } else {
-            appendObjectId(connector, sql, object.getOid());
+            appendObjectId(connector, sql, (RootOid)object.getOid());
             // sql.append(connector.addToQueryValues(primaryKeyAsObject(object.getOid())));
         }
     }
 
-    /*
-     * This doesn't have to be an Int, it should be any object.
-     */
-    public Object primaryKeyAsObject(final Oid oid) {
-        if (oid instanceof SqlOid) {
-            final PrimaryKey pk = ((SqlOid) oid).getPrimaryKey();
-            return pk.naturalValue();
-        } else {
-            return ((SerialOid) oid).getSerialNo();
-        }
-    }
-
-    public String primaryKey(final Oid oid) {
-        if (oid instanceof SqlOid) {
-            return "" + ((SqlOid) oid).getPrimaryKey().stringValue() + "";
-        } else {
-            return "" + ((SerialOid) oid).getSerialNo();
-        }
+    public String primaryKey(final RootOid oid) {
+        return oid.getIdentifier();
     }
 
     public Oid recreateOid(final Results rs, final ObjectSpecification specification) {
-        PrimaryKey key;
         final Object object = rs.getObject(column);
         if (object == null) {
             return null;
-        } else {
-            final int id = ((Integer) object).intValue();
-            key = new IntegerPrimaryKey(id);
-        }
-        final Oid oid = new SqlOid(specification.getFullIdentifier(), key, State.PERSISTENT);
-        return oid;
+        } 
+        final int id = ((Integer) object).intValue();
+        return new RootOidDefault(specification.getObjectType(), ""+id, Oid.State.PERSISTENT);
     }
 
     protected ObjectAdapter getAdapter(final ObjectSpecification specification, final Oid oid) {

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=1304796&r1=1304795&r2=1304796&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 Sat Mar 24 14:01:35 2012
@@ -29,8 +29,10 @@ import org.apache.isis.core.commons.debu
 import org.apache.isis.core.commons.exceptions.IsisException;
 import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapterLookup;
 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.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.ObjectStore;
@@ -39,6 +41,7 @@ import org.apache.isis.runtimes.dflt.run
 import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
 import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
 import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.SaveObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.serial.RootOidDefault;
 import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindAllInstances;
 import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByPattern;
 import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByTitle;
@@ -109,7 +112,7 @@ public final class SqlObjectStore implem
     }
 
     @Override
-    public void registerService(final String name, final Oid oid) {
+    public void registerService(final RootOid rootOid) {
         final DatabaseConnector connector = connectionPool.acquire();
 
         final StringBuffer sql = new StringBuffer();
@@ -121,8 +124,9 @@ public final class SqlObjectStore implem
         sql.append(Defaults.getIdColumn());
         sql.append(") values (?,?)");
 
-        connector.addToQueryValues(((SqlOid) oid).getPrimaryKey().naturalValue());
-        connector.addToQueryValues(name);
+        final RootOidDefault sqlOid = (RootOidDefault) rootOid;
+        connector.addToQueryValues(sqlOid.getIdentifier());
+        connector.addToQueryValues(rootOid.getObjectType());
 
         connector.insert(sql.toString());
         connectionPool.release(connector);
@@ -220,7 +224,7 @@ public final class SqlObjectStore implem
                 LOG.debug("  save object " + object);
                 if (object.getSpecification().isCollectionOrIsAggregated()) {
 
-                    final ObjectAdapter parent = object.getAggregateRoot();
+                    final ObjectAdapter parent = object.getAggregateRoot(getAdapterManager());
                     LOG.debug("change to internal collection being persisted through parent");
 
                     final Oid oid = object.getOid();
@@ -228,7 +232,7 @@ public final class SqlObjectStore implem
                         final AggregatedOid aoid = (AggregatedOid) oid;
                         final ObjectMapping mapping2 = objectMappingLookup.getMapping(parent, connection);
 
-                        if (mapping2.saveCollection(connection, parent, aoid.getId()) == false) {
+                        if (mapping2.saveCollection(connection, parent, aoid.getLocalId()) == false) {
                             final ObjectMapping mapping = objectMappingLookup.getMapping(parent, connection);
                             mapping.save(connection, object);
                         }
@@ -277,6 +281,7 @@ public final class SqlObjectStore implem
         };
     }
 
+
     @Override
     public void debugData(final DebugBuilder debug) {
         debug.appendln("initialised", isInitialized);
@@ -366,7 +371,6 @@ public final class SqlObjectStore implem
                 addSpecQueryInstances(subclassSpec, connector, query, matchingInstances);
             }
         }
-
     }
 
     private ObjectAdapter[] getAllInstances(final PersistenceQueryFindAllInstances criteria) {
@@ -425,27 +429,29 @@ public final class SqlObjectStore implem
     }
 
     @Override
-    public Oid getOidForService(ObjectSpecification serviceSpecification, final String name) {
-        final DatabaseConnector connector = connectionPool.acquire();
+    public RootOid getOidForService(ObjectSpecification serviceSpec) {
 
-        final StringBuffer sql = new StringBuffer();
-        sql.append("select ");
-        sql.append(Defaults.getPkIdLabel());
-        sql.append(" from ");
-        sql.append(Sql.tableIdentifier(TABLE_NAME));
-        sql.append(" where ");
-        sql.append(Defaults.getIdColumn());
-        sql.append(" = ?");
-        connector.addToQueryValues(name);
+        final DatabaseConnector connector = connectionPool.acquire();
+        try {
+            final StringBuffer sql = new StringBuffer();
+            sql.append("select ");
+            sql.append(Defaults.getPkIdLabel());
+            sql.append(" from ");
+            sql.append(Sql.tableIdentifier(TABLE_NAME));
+            sql.append(" where ");
+            sql.append(Defaults.getIdColumn());
+            sql.append(" = ?");
+            connector.addToQueryValues(serviceSpec.getObjectType());
 
-        final Results results = connector.select(sql.toString());
-        if (results.next()) {
-            final int key = results.getInt(Defaults.getPkIdLabel());
-            connectionPool.release(connector);
-            return SqlOid.createPersistent(name, new IntegerPrimaryKey(key));
-        } else {
+            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);
+            
+        } finally {
             connectionPool.release(connector);
-            return null;
         }
     }
 
@@ -487,8 +493,9 @@ public final class SqlObjectStore implem
         this.objectMappingLookup = mapperLookup;
     }
 
-    public static String getTableName() {
-        return TABLE_NAME;
+    
+    protected ObjectAdapterLookup getAdapterManager() {
+        return IsisContext.getPersistenceSession().getAdapterManager();
     }
 
 }



Mime
View raw message