You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2012/12/06 12:09:56 UTC
[24/51] [partial] ISIS-188: moving components into correct
directories.
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java
new file mode 100644
index 0000000..fbdc8ce
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java
@@ -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();
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java
new file mode 100644
index 0000000..27cc9c8
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java
@@ -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;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java
new file mode 100644
index 0000000..92ad996
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java
@@ -0,0 +1,281 @@
+/*
+ * 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");
+
+ final File dir = new File("target/test/org.domain.Class2");
+ dir.mkdirs();
+
+ 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.Class2", "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.Class2 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.Class2", "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.Class2 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 2010\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.Class2", "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.Class2 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.Class2", "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.Class2 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.Class2", "2025.data");
+ // file1.getParentFile().mkdirs();
+ final FileWriter fileWriter = new FileWriter(file1);
+ fileWriter.write("type 1025 1\n{data1}");
+ fileWriter.close();
+
+ final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Iorg.domain.Class2\n\n"), out);
+ server.process(connection);
+
+ assertThat(out.toString(), is(equalTo("ok true\n")));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java
new file mode 100644
index 0000000..f448313
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java
@@ -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));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java
new file mode 100644
index 0000000..8f327ff
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.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);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java
new file mode 100644
index 0000000..a5d6146
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java
@@ -0,0 +1,81 @@
+/*
+ * 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.mongo;
+
+import java.util.Set;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.Mongo;
+
+public class DemoMongo {
+
+ // @Test
+ public void installed() throws Exception {
+
+ final Mongo m = new Mongo();
+
+ for (final String s : m.getDatabaseNames()) {
+ System.out.println(s);
+ }
+
+ /*
+ * Mongo m = new Mongo( "localhost" ); Mongo m = new Mongo( "localhost"
+ * , 27017 );
+ */
+ m.dropDatabase("mydb");
+
+ System.out.println("\n...");
+ for (final String s : m.getDatabaseNames()) {
+ System.out.println(s);
+ }
+
+ final DB db = m.getDB("mydb");
+ /*
+ * DBCollection coll = db.getCollection("testCollection1"); coll =
+ * db.getCollection("testCollection2");
+ */
+
+ final DBCollection coll = db.getCollection("testCollection1");
+
+ final BasicDBObject doc = new BasicDBObject();
+
+ doc.put("name", "MongoDB");
+ doc.put("type", "database");
+ doc.put("count", 1);
+
+ final BasicDBObject info = new BasicDBObject();
+
+ info.put("x", 203);
+ info.put("y", 102);
+
+ doc.put("info", info);
+
+ coll.insert(doc);
+
+ final Set<String> colls = db.getCollectionNames();
+
+ for (final String s : colls) {
+ System.out.println(s);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoIntegrationTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoIntegrationTest.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoIntegrationTest.java
new file mode 100644
index 0000000..7c69edc
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoIntegrationTest.java
@@ -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.mongo;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeThat;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.Mongo;
+
+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.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;
+
+public class MongoIntegrationTest {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().with(new MongoPersistorMechanismInstaller()).build();
+
+ private MongoDb db;
+ private DB testDb;
+
+ private ObjectAdapter adapter1;
+
+ private ObjectSpecification specification;
+
+ @Before
+ public void setupMongo() throws Exception {
+
+ try {
+ final Mongo m = new Mongo();
+ m.dropDatabase("testdb");
+ testDb = m.getDB("testdb");
+ } catch (final Exception e) {
+ assumeThat(true, is(false)); // ignore if no MongoDB instance to
+ // connect to
+ return;
+ }
+
+ db = new MongoDb("localhost", 0, "testdb", new KeyCreatorDefault());
+ db.open();
+
+ adapter1 = iswf.adapterFor(iswf.fixtures.smpl1);
+ specification = adapter1.getSpecification();
+ }
+
+ @Test
+ public void newDatabaseContainsNothing() throws Exception {
+ assertFalse(db.containsData());
+ }
+
+ @Test
+ public void serialNumberSaved() throws Exception {
+ assertEquals(1, db.nextSerialNumberBatch(ObjectSpecId.of("oid"), 10));
+ assertEquals(11, db.nextSerialNumberBatch(ObjectSpecId.of("oid"), 10));
+ }
+
+ @Test
+ public void hasInstances() throws Exception {
+ assertFalse(db.hasInstances(specification.getSpecId()));
+ db.close();
+
+ final DBCollection instances = testDb.getCollection(specification.getSpecId().asString());
+ instances.insert(new BasicDBObject().append("test", "test"));
+
+ db.open();
+ assertTrue(db.hasInstances(specification.getSpecId()));
+ assertFalse(db.hasInstances(ObjectSpecId.of("org.xxx.unknown")));
+ }
+
+ @Test
+ public void serviceIds() throws Exception {
+ final ObjectSpecId osi = ObjectSpecId.of("one");
+ db.addService(osi, "123");
+ assertEquals("123", db.getService(osi));
+ }
+
+ @Test
+ public void unknownServiceIds() throws Exception {
+ assertNull(db.getService(ObjectSpecId.of("two")));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderIntegrationTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderIntegrationTest.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderIntegrationTest.java
new file mode 100644
index 0000000..f3fd962
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderIntegrationTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.mongo;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeThat;
+
+import com.mongodb.BasicDBObject;
+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.spec.ObjectSpecId;
+
+public class MongoStateReaderIntegrationTest {
+
+ private static final String OBJECT_TYPE = "org.test.Object";
+
+ private DB testDb;
+ private MongoStateReader reader;
+
+ @Before
+ public void setup() throws Exception {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ final Mongo m = new Mongo();
+ try {
+ m.dropDatabase("mydb");
+ } catch (final Exception e) {
+ assumeThat(true, is(false));// ie ignore test because we've had an
+ // exception
+ return;
+ }
+
+ testDb = m.getDB("mydb");
+
+ final BasicDBObject object = new BasicDBObject();
+// 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(OBJECT_TYPE);
+ instances.insert(object);
+
+ reader = new MongoStateReader(testDb, ObjectSpecId.of(OBJECT_TYPE), "1023");
+ }
+
+ @Test
+ public void readNonexistantFieldAsNull() throws Exception {
+ assumeThat(reader, is(not(nullValue())));
+ assertEquals(null, reader.readField("unknown"));
+ }
+
+ @Test
+ public void readStringField() throws Exception {
+ assertEquals("Fred Smith", reader.readField("name"));
+ }
+
+ @Test
+ public void readStringFieldAsNull() throws Exception {
+ assertEquals(null, reader.readField("null name"));
+ }
+
+ @Test
+ public void readNullFieldAsNull() throws Exception {
+ 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 readOid() throws Exception {
+ assertEquals(OBJECT_TYPE + ":1023", reader.readOid());
+ }
+
+ @Test
+ public void readNumberField() throws Exception {
+ assertEquals(102L, reader.readLongField("number"));
+ }
+
+ @Test
+ public void readNumberFieldAsNull() throws Exception {
+ assertEquals(0L, reader.readLongField("null number"));
+ }
+
+ @Test
+ public void readNonexistingNumberFieldAsZero() throws Exception {
+ assertEquals(0L, reader.readLongField("unknown"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterIntegrationTest.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterIntegrationTest.java
new file mode 100644
index 0000000..3df43a8
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterIntegrationTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.mongo;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeThat;
+
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+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.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+
+public class MongoStateWriterIntegrationTest {
+
+ private static final String SPEC_NAME = "org.test.Object";
+ private DB testDb;
+ private MongoStateWriter writer;
+
+ @Before
+ public void setup() throws Exception {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ try {
+
+ final Mongo m = new Mongo();
+ m.dropDatabase("mydb");
+ testDb = m.getDB("mydb");
+ } catch (final Exception e) {
+ assumeThat(true, is(false)); // ie no exceptions
+ return;
+ }
+
+ writer = new MongoStateWriter(testDb, ObjectSpecId.of(SPEC_NAME));
+ }
+
+ @Test
+ public void flushSavesObject() throws Exception {
+ writer.flush();
+
+ final DBCollection instances = testDb.getCollection(SPEC_NAME);
+ assertEquals(1, instances.getCount());
+ }
+
+ @Test
+ public void objectNotSavedUntilFlush() throws Exception {
+ writer.writeField("number", 1023);
+ writer.writeField("string", "testing");
+
+ final DBCollection instances = testDb.getCollection(SPEC_NAME);
+ assertEquals(0, instances.getCount());
+ }
+
+ @Test
+ public void serialNumberNotStored() throws Exception {
+ //writer.writeId("D01");
+ writer.writeOid(RootOidDefault.deString(SPEC_NAME+":"+"D01", new OidMarshaller()));
+ writer.flush();
+
+ final DBCollection instances = testDb.getCollection(SPEC_NAME);
+ assertEquals(1, instances.getCount());
+ final DBObject object = instances.findOne();
+
+ assertEquals(SPEC_NAME+":"+"D01", object.get("_oid"));
+ assertEquals("D01", object.get("_id"));
+
+ assertEquals(2, object.keySet().size());
+ }
+
+ @Test
+ public void writeFields() throws Exception {
+ //writer.writeObjectType(SPEC_NAME);
+ writer.writeOid(RootOidDefault.deString(SPEC_NAME+":"+"D01", new OidMarshaller()));
+ writer.writeField("number", 1023);
+ writer.writeField("string", "testing");
+ writer.flush();
+
+ final DBCollection instances = testDb.getCollection(SPEC_NAME);
+ assertEquals(1, instances.getCount());
+ final DBObject object = instances.findOne();
+ 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.writeObjectType(SPEC_NAME);
+ writer.writeOid(RootOidDefault.deString(SPEC_NAME + ":" + "3", new OidMarshaller()));
+ writer.flush();
+
+ writer.writeField("number", 1023);
+ writer.writeField("string", "testing");
+ writer.flush();
+
+ final DBCollection instances = testDb.getCollection(SPEC_NAME);
+ assertEquals(1, instances.getCount());
+ final DBObject object = instances.findOne();
+ assertEquals(SPEC_NAME + ":" + "3", object.get("_oid"));
+ assertEquals("1023", object.get("number"));
+ assertEquals("testing", object.get("string"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/ObjectReaderMongoIntegrationTest.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/ObjectReaderMongoIntegrationTest.java b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/ObjectReaderMongoIntegrationTest.java
new file mode 100644
index 0000000..15cfd7a
--- /dev/null
+++ b/framework/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/ObjectReaderMongoIntegrationTest.java
@@ -0,0 +1,290 @@
+/*
+ * 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.mongo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hamcrest.CoreMatchers;
+import org.jmock.Expectations;
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.exceptions.UnexpectedCallException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+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.SpecificationLoaderSpi;
+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.ObjectReader;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateReader;
+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.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManagerSpi;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.tck.dom.refs.ParentEntity;
+import org.apache.isis.tck.dom.refs.ReferencingEntity;
+import org.apache.isis.tck.dom.refs.SimpleEntity;
+
+public class ObjectReaderMongoIntegrationTest {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().with(new MongoPersistorMechanismInstaller()).build();
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
+
+ @Mock
+ private VersionCreator versionCreator;
+
+ @Mock
+ private StateReader reader1;
+ @Mock
+ private StateReader reader2;
+
+ private ObjectReader objectReader;
+
+ private Map<String, DataEncryption> dataEncrypter;
+
+ private OidMarshaller oidMarshaller = new OidMarshaller();
+
+ private final RootOidDefault oid3 = RootOidDefault.deString("SMPL:3", oidMarshaller );
+ private final RootOidDefault oid4 = RootOidDefault.deString("RFCG:4", oidMarshaller);
+ private final RootOidDefault oid5 = RootOidDefault.deString("PRNT:5", oidMarshaller);
+
+
+ @Before
+ public void setup() {
+ objectReader = new ObjectReader();
+
+ dataEncrypter = new HashMap<String, DataEncryption>();
+ final DataEncryption etcEncryption = new DataEncryption() {
+ @Override
+ public String getType() {
+ return "etc1";
+ }
+
+ @Override
+ public void init(final IsisConfiguration configuration) {
+ }
+
+ @Override
+ public String encrypt(final String plainText) {
+ throw new UnexpectedCallException();
+ }
+
+ @Override
+ public String decrypt(final String encryptedText) {
+ return encryptedText.substring(3);
+ }
+ };
+ dataEncrypter.put(etcEncryption.getType(), etcEncryption);
+ }
+
+ @Test
+ public void testReadingValues() throws Exception {
+ setupObject1();
+
+ context.checking(new Expectations() {
+ {
+ one(reader1).readOid();
+ will(returnValue("SMPL:3"));
+
+ one(reader1).readEncrytionType();
+ will(returnValue("etc1"));
+ one(reader1).readVersion();
+ will(returnValue("3"));
+ one(reader1).readUser();
+ will(returnValue("username"));
+ one(reader1).readTime();
+ will(returnValue("1020"));
+ one(versionCreator).version("3", "username", "1020");
+ }
+ });
+
+ final ObjectAdapter readObject = objectReader.load(reader1, versionCreator, dataEncrypter);
+ assertEquals(oid3, readObject.getOid());
+ assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
+
+ final SimpleEntity pojo = (SimpleEntity) readObject.getObject();
+ assertEquals("Fred Smith", pojo.getName());
+ assertEquals(34, pojo.getSize());
+
+ context.assertIsSatisfied();
+ }
+
+ @Test
+ public void testReadingReference() throws Exception {
+ context.checking(new Expectations() {
+ {
+ one(reader2).readOid();
+ will(returnValue("RFCG:4"));
+
+ one(reader2).readEncrytionType();
+ will(returnValue("etc1"));
+ one(reader2).readVersion();
+ will(returnValue("3"));
+ one(reader2).readUser();
+ will(returnValue("username"));
+ one(reader2).readTime();
+ will(returnValue("1020"));
+ one(versionCreator).version("3", "username", "1020");
+
+ one(reader2).readField("reference");
+ will(returnValue("SMPL:3"));
+
+ one(reader2).readCollection("aggregatedEntities");
+ will(returnValue(new ArrayList<StateReader>()));
+
+ one(reader2).readAggregate("aggregatedReference");
+ will(returnValue(null));
+ }
+ });
+
+ final ObjectAdapter readObject = objectReader.load(reader2, versionCreator, dataEncrypter);
+ assertEquals(oid4, readObject.getOid());
+ assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
+
+ final ReferencingEntity pojo = (ReferencingEntity) readObject.getObject();
+ assertEquals(null, pojo.getAggregatedReference());
+ assertThat(pojo.getReference(), CoreMatchers.instanceOf(SimpleEntity.class));
+
+ context.assertIsSatisfied();
+ }
+
+ @Test
+ public void testReadingCollection() throws Exception {
+ //final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExamplePojoWithValues.class);
+ context.checking(new Expectations() {
+ {
+ one(reader2).readOid();
+ will(returnValue("PRNT:5"));
+
+ one(reader2).readEncrytionType();
+ will(returnValue("etc1"));
+ one(reader2).readVersion();
+ will(returnValue("3"));
+ one(reader2).readUser();
+ will(returnValue("username"));
+ one(reader2).readTime();
+ will(returnValue("1020"));
+ one(versionCreator).version("3", "username", "1020");
+
+ one(reader2).readField("name");
+ will(returnValue(null));
+ one(reader2).readField("children");
+ will(returnValue(null));
+ one(reader2).readField("heterogeneousCollection");
+ will(returnValue(null));
+ one(reader2).readField("homogeneousCollection");
+ will(returnValue("SMPL:3|SMPL:4|"));
+ }
+ });
+
+ final ObjectAdapter readObject = objectReader.load(reader2, versionCreator, dataEncrypter);
+ assertEquals(oid5, readObject.getOid());
+ assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
+
+ final ParentEntity pojo = (ParentEntity) readObject.getObject();
+ final List<SimpleEntity> collection2 = pojo.getHomogeneousCollection();
+ assertEquals(2, collection2.size());
+
+ assertThat(collection2.get(0), CoreMatchers.instanceOf(SimpleEntity.class));
+ assertThat(collection2.get(1), CoreMatchers.instanceOf(SimpleEntity.class));
+
+ context.assertIsSatisfied();
+ }
+
+ @Test
+ public void updateObjectsState() throws Exception {
+ setupObject1();
+ context.checking(new Expectations() {
+ {
+
+ one(reader1).readEncrytionType();
+ will(returnValue("etc1"));
+ one(reader1).readVersion();
+ will(returnValue("3"));
+ one(reader1).readUser();
+ will(returnValue("username"));
+ one(reader1).readTime();
+ will(returnValue("1020"));
+ one(versionCreator).version("3", "username", "1020");
+ }
+ });
+
+ final ObjectAdapter readObject = getAdapterManager().adapterFor(RootOidDefault.create(ObjectSpecId.of("SMPL"), ""+4));
+
+ objectReader.update(reader1, versionCreator, dataEncrypter, readObject);
+
+ final SimpleEntity pojo = (SimpleEntity) readObject.getObject();
+ assertEquals("Fred Smith", pojo.getName());
+ assertEquals(34, pojo.getSize());
+
+ context.assertIsSatisfied();
+ }
+
+ private void setupObject1() {
+ context.checking(new Expectations() {
+ {
+ one(reader1).readField("date");
+ will(returnValue("null"));
+
+ one(reader1).readField("name");
+ will(returnValue("ENCFred Smith"));
+
+ one(reader1).readField("size");
+ will(returnValue("ENC34"));
+
+ one(reader1).readField("nullable");
+ will(returnValue("null"));
+ }
+ });
+ }
+
+ protected SpecificationLoaderSpi getSpecificationLoader() {
+ return IsisContext.getSpecificationLoader();
+ }
+
+ protected PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+ protected AdapterManager getAdapterManager() {
+ return getPersistenceSession().getAdapterManager();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/NOTICE
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/NOTICE b/framework/objectstore/sql/NOTICE
new file mode 100644
index 0000000..d391f54
--- /dev/null
+++ b/framework/objectstore/sql/NOTICE
@@ -0,0 +1,7 @@
+Apache Isis
+Copyright 2010-2011 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/pom.xml
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/pom.xml b/framework/objectstore/sql/pom.xml
new file mode 100644
index 0000000..88ff8b9
--- /dev/null
+++ b/framework/objectstore/sql/pom.xml
@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ you under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.isis</groupId>
+ <artifactId>isis</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.isis.runtimes.dflt.objectstores</groupId>
+ <artifactId>sql</artifactId>
+
+ <name>Default Runtime SQL ObjectStore</name>
+
+ <description>
+ Provides JDBC-based persistence.
+ </description>
+
+ <packaging>pom</packaging>
+
+ <properties>
+ <siteBaseDir>../..</siteBaseDir>
+ <relativeUrl>objectstore/sql/</relativeUrl>
+
+ <docbkxGuideTitle>Apache Isis Default Runtime SQL ObjectStore</docbkxGuideTitle>
+ <docbkxGuideSubTitle>Configuration and Deployment Guide</docbkxGuideSubTitle>
+ <docbkxGuideName>isis-sql-objectstore</docbkxGuideName>
+ </properties>
+
+ <!-- used in Site generation for relative references. -->
+ <url>http://incubator.apache.org/isis/${relativeUrl}</url>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.agilejava.docbkx</groupId>
+ <artifactId>docbkx-maven-plugin</artifactId>
+ <inherited>false</inherited>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>${maven-project-info-reports-plugin}</version>
+ <inherited>false</inherited>
+ <reportSets>
+ <reportSet>
+ <inherited>false</inherited>
+ <reports>
+ <report>dependency-management</report>
+ <report>plugins</report>
+ <report>modules</report>
+ <report>summary</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+
+
+ <modules>
+ <module>sql-impl</module>
+ <module>sql-tests-common</module>
+ <module>sql-tests-served</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt</groupId>
+ <artifactId>runtime</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-unittestsupport</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt</groupId>
+ <artifactId>isis-integtestsupport</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </dependency>
+
+ <!-- Required for TestProxy -->
+ <!-- Isis defaults -->
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt.objectstores</groupId>
+ <artifactId>dflt</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt.objectstores</groupId>
+ <artifactId>dflt</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt.bytecode</groupId>
+ <artifactId>dflt</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt.objectstores</groupId>
+ <artifactId>sql-impl</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt.objectstores</groupId>
+ <artifactId>sql-tests-common</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt.objectstores</groupId>
+ <artifactId>sql-tests-common</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt.objectstores</groupId>
+ <artifactId>sql-tests-served</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.tck</groupId>
+ <artifactId>tck-dom</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </dependency>
+
+
+
+ <!-- Test environment -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/sql-impl/NOTICE
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/sql-impl/NOTICE b/framework/objectstore/sql/sql-impl/NOTICE
new file mode 100644
index 0000000..d391f54
--- /dev/null
+++ b/framework/objectstore/sql/sql-impl/NOTICE
@@ -0,0 +1,7 @@
+Apache Isis
+Copyright 2010-2011 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/sql-impl/pom.xml
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/sql-impl/pom.xml b/framework/objectstore/sql/sql-impl/pom.xml
new file mode 100644
index 0000000..1269e13
--- /dev/null
+++ b/framework/objectstore/sql/sql-impl/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ you under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.isis.runtimes.dflt.objectstores</groupId>
+ <artifactId>sql</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>sql-impl</artifactId>
+ <name>Default Runtime SQL ObjectStore Implementation</name>
+ <description>SQL Objectstire Implementation. Uses jdbc for maximum compatibility.</description>
+
+ <properties>
+ <siteBaseDir>../../../../..</siteBaseDir>
+ <relativeUrl>runtimes/dflt/objectstores/sql/sql-impl/</relativeUrl>
+ </properties>
+
+ <!-- used in Site generation for relative references. -->
+ <url>http://incubator.apache.org/isis/${relativeUrl}</url>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>${maven-project-info-reports-plugin}</version>
+ <inherited>false</inherited>
+ <configuration>
+ <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <inherited>false</inherited>
+ <reports>
+ <report>dependencies</report>
+ <report>dependency-convergence</report>
+ <report>plugins</report>
+ <report>summary</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.isis.runtimes.dflt</groupId>
+ <artifactId>runtime</artifactId>
+ </dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/sql-impl/sqlos-testing.properties
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/sql-impl/sqlos-testing.properties b/framework/objectstore/sql/sql-impl/sqlos-testing.properties
new file mode 100644
index 0000000..29d5a76
--- /dev/null
+++ b/framework/objectstore/sql/sql-impl/sqlos-testing.properties
@@ -0,0 +1,59 @@
+# 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.
+# run with SQL object store
+#isis.object-store=org.apache.isis.persistor.sql.SqlObjectStore
+#isis.persistor.sql.connection=org.apache.isis.persistor.sql.SimpleConnection
+#isis.persistor.sql.database=jdbc:hsqldb:tmp/hsql-db
+#isis.persistor.sql.database=jdbc:hsqldb:hsql://localhost
+#isis.persistor.sql.driver=org.hsqldb.jdbcDriver
+#isis.persistor.sql.user=sa
+#isis.persistor.sql.password=
+
+
+#isis.oidgenerator=org.apache.isis.persistor.sql.SqlOidGenerator
+
+#isis.object-store=org.apache.isis.persistor.sql.SqlObjectStore
+isis.persistor.sql.connector=org.apache.isis.persistor.sql.jdbc.JdbcConnectorFactory
+isis.persistor.sql.automapper=org.apache.isis.persistor.sql.auto.AutoMapperFactory
+
+isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver
+isis.persistor.sql.jdbc.connection=jdbc:hsqldb:tmp/hsql-db
+isis.persistor.sql.jdbc.user=sa
+isis.persistor.sql.jdbc.password=
+
+
+## log4j
+# apache's log4j is used to provide system logging.
+##
+log4j.rootCategory=OFF, Console
+
+# The console appender
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.target=System.out
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+log4j.appender.Console.layout.ConversionPattern=%-5r [%-20c{1}] %-5p %m -- %l%n
+
+
+log4j.rootCategory=DEBUG, File
+# The file appender
+log4j.appender.File=org.apache.log4j.RollingFileAppender
+log4j.appender.File.file=isis.log
+log4j.appender.File.append=false
+#log4j.appender.File.maxFileSize=500KB
+#log4j.appender.File.maxBackupIndex=1
+log4j.appender.File.layout=org.apache.log4j.PatternLayout
+log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractDatabaseConnector.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractDatabaseConnector.java b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractDatabaseConnector.java
new file mode 100644
index 0000000..a83c2d5
--- /dev/null
+++ b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractDatabaseConnector.java
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+public abstract class AbstractDatabaseConnector implements DatabaseConnector {
+ private boolean isUsed;
+
+ @Override
+ public final void setUsed(final boolean isUsed) {
+ this.isUsed = isUsed;
+ }
+
+ @Override
+ public final boolean isUsed() {
+ return isUsed;
+ }
+
+ private DatabaseConnectorPool pool;
+
+ @Override
+ public final void setConnectionPool(final DatabaseConnectorPool pool) {
+ this.pool = pool;
+ }
+
+ @Override
+ public final DatabaseConnectorPool getConnectionPool() {
+ return pool;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractFieldMappingFactory.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractFieldMappingFactory.java b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractFieldMappingFactory.java
new file mode 100644
index 0000000..0d7658a
--- /dev/null
+++ b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractFieldMappingFactory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMappingFactory;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+
+public abstract class AbstractFieldMappingFactory implements FieldMappingFactory {
+
+ protected String getTypeOverride(final ObjectSpecification object, final ObjectAssociation field, final String type) {
+ // isis.persistor.sql.automapper.default
+ final IsisConfiguration configParameters = IsisContext.getConfiguration();
+ final String find = object.getShortIdentifier() + "." + field.getId();
+ final String property = SqlObjectStore.BASE_NAME + ".automapper.type." + find;
+ final String dataType = configParameters.getString(property, type);
+ return dataType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractMapper.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractMapper.java b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractMapper.java
new file mode 100644
index 0000000..2bca30a
--- /dev/null
+++ b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/AbstractMapper.java
@@ -0,0 +1,53 @@
+/*
+ * 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 java.util.Date;
+
+import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+
+
+public abstract class AbstractMapper {
+
+ public abstract void createTables(final DatabaseConnector connector);
+
+ protected boolean needsTables(final DatabaseConnector connector) {
+ return false;
+ }
+
+ public void startup(final DatabaseConnector connector) {
+ if (needsTables(connector)) {
+ createTables(connector);
+ }
+ }
+
+ public final void shutdown() {
+ }
+
+ protected String asSqlName(final String name) {
+ return Sql.sqlName(name);
+ }
+
+ protected Version createVersion(final long versionSequence) {
+ return SerialNumberVersion.create(versionSequence, "", new Date());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/CollectionMapper.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/CollectionMapper.java b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/CollectionMapper.java
new file mode 100644
index 0000000..d4c4766
--- /dev/null
+++ b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/CollectionMapper.java
@@ -0,0 +1,36 @@
+/*
+ * 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.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+
+public interface CollectionMapper {
+
+ public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent);
+
+ public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent);
+
+ void createTables(DatabaseConnector connection);
+
+ boolean needsTables(DatabaseConnector connection);
+
+ public void debugData(DebugBuilder debug);
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/DatabaseConnector.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/DatabaseConnector.java b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/DatabaseConnector.java
new file mode 100644
index 0000000..e65e604
--- /dev/null
+++ b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/DatabaseConnector.java
@@ -0,0 +1,79 @@
+/*
+ * 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.isis.core.commons.debug.DebugBuilder;
+
+public interface DatabaseConnector {
+ /*
+ * @deprecated Results callStoredProcedure(String name, Parameter[]
+ * parameters);
+ */
+ void close();
+
+ int count(String sql);
+
+ void delete(String sql);
+
+ // MultipleResults executeStoredProcedure(String name, Parameter[]
+ // parameters);
+
+ boolean hasTable(String tableName);
+
+ boolean hasColumn(String tableName, String columnName);
+
+ void insert(String sql);
+
+ void insert(String sql, Object oid);
+
+ Results select(String sql);
+
+ /**
+ * Updates the database using the specified sql statement, and returns the
+ * number of rows affected.
+ */
+ int update(String sql);
+
+ void setUsed(boolean isUsed);
+
+ boolean isUsed();
+
+ void commit();
+
+ void rollback();
+
+ void setConnectionPool(DatabaseConnectorPool pool);
+
+ DatabaseConnectorPool getConnectionPool();
+
+ void begin();
+
+ void debug(DebugBuilder debug);
+
+ SqlMetaData getMetaData();
+
+ // Full PreparedStatement support
+ public String addToQueryValues(int i);
+
+ public String addToQueryValues(String s);
+
+ public String addToQueryValues(Object object);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/cd9f2e4a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/DatabaseConnectorFactory.java
----------------------------------------------------------------------
diff --git a/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/DatabaseConnectorFactory.java b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/DatabaseConnectorFactory.java
new file mode 100644
index 0000000..568fb87
--- /dev/null
+++ b/framework/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/DatabaseConnectorFactory.java
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+public interface DatabaseConnectorFactory {
+ DatabaseConnector createConnector();
+}