incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmatth...@apache.org
Subject svn commit: r1240809 - in /incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src: main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/ test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/
Date Sun, 05 Feb 2012 20:51:32 GMT
Author: rmatthews
Date: Sun Feb  5 20:51:31 2012
New Revision: 1240809

URL: http://svn.apache.org/viewvc?rev=1240809&view=rev
Log:
Isis-176 - Got the basics working so object are persisted to MongoDB

Added:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoClientCommandContext.java
  (with props)
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/PropertyNames.java
  (with props)
Modified:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoDb.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoDbTest.java

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoClientCommandContext.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoClientCommandContext.java?rev=1240809&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoClientCommandContext.java
(added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoClientCommandContext.java
Sun Feb  5 20:51:31 2012
@@ -0,0 +1,62 @@
+/*
+ *  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.mongo;
+
+import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlCommandContext;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.StateWriter;
+
+import com.mongodb.DB;
+
+
+public class MongoClientCommandContext implements NoSqlCommandContext {
+
+    private final DB db;
+
+    public MongoClientCommandContext(DB db) {
+        this.db = db;
+    }
+
+    @Override
+    public void start() {}
+
+    @Override
+    public void end() {}
+
+    @Override
+    public StateWriter createStateWriter(String specName) {
+        return new MongoStateWriter(db, specName);
+    }
+
+    @Override
+    public void delete(String specificationName, String key, String version) {
+        // TODO
+    }
+
+    @Override
+    public void insert(StateWriter writer) {
+        ((MongoStateWriter) writer).flush();
+    }
+
+    @Override
+    public void update(StateWriter writer) {
+        ((MongoStateWriter) writer).flush();
+    }
+
+}

Propchange: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoClientCommandContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoDb.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoDb.java?rev=1240809&r1=1240808&r2=1240809&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoDb.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoDb.java
Sun Feb  5 20:51:31 2012
@@ -23,6 +23,15 @@ import java.net.UnknownHostException;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.isis.runtimes.dflt.objectstores.nosql.KeyCreator;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlCommandContext;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlDataDatabase;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlStoreException;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.StateReader;
+import org.apache.isis.runtimes.dflt.objectstores.nosql.StateWriter;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.log4j.Logger;
+
 import com.mongodb.BasicDBObject;
 import com.mongodb.DB;
 import com.mongodb.DBCollection;
@@ -32,17 +41,6 @@ import com.mongodb.Mongo;
 import com.mongodb.MongoException;
 import com.mongodb.ObjectId;
 
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.KeyCreator;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlCommandContext;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlDataDatabase;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlStoreException;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.StateReader;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.StateWriter;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
-
 public class MongoDb implements NoSqlDataDatabase {
     private static final Logger LOG = Logger.getLogger(MongoDb.class);
 
@@ -93,10 +91,12 @@ public class MongoDb implements NoSqlDat
 
     @Override
     public long nextSerialNumberBatch(final String name, final int batchSize) {
-        throw new NotYetImplementedException();
+        long next = readSerialNumber();
+        writeSerialNumber(next + batchSize);
+        return next + 1;
     }
 
-    public void writeSerialNumber(final long serialNumber) {
+    private void writeSerialNumber(final long serialNumber) {
         final DBCollection system = db.getCollection("serialnumbers");
         DBObject object = system.findOne();
         if (object == null) {
@@ -107,7 +107,7 @@ public class MongoDb implements NoSqlDat
         LOG.info("serial number written: " + serialNumber);
     }
 
-    public long readSerialNumber() {
+    private long readSerialNumber() {
         final DBCollection system = db.getCollection("serialnumbers");
         final DBObject data = system.findOne();
         if (data == null) {
@@ -168,6 +168,10 @@ public class MongoDb implements NoSqlDat
 
     @Override
     public void write(final List<PersistenceCommand> commands) {
+        final NoSqlCommandContext context = new MongoClientCommandContext(db);
+        for (final PersistenceCommand command : commands) {
+            command.execute(context);
+        }
     }
 
     @Override

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java?rev=1240809&r1=1240808&r2=1240809&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java
Sun Feb  5 20:51:31 2012
@@ -31,8 +31,8 @@ import org.apache.isis.core.commons.exce
 import org.apache.isis.runtimes.dflt.objectstores.nosql.StateReader;
 import org.apache.isis.runtimes.dflt.runtime.persistence.ObjectNotFoundException;
 
-public class MongoStateReader implements StateReader {
-    private static final Logger LOG = Logger.getLogger(MongoStateReader.class);
+public class MongoStateReader implements StateReader, PropertyNames {
+     private static final Logger LOG = Logger.getLogger(MongoStateReader.class);
     private final DBObject instance;
 
     public MongoStateReader(final DB db, final String specName, final String key) {
@@ -71,32 +71,32 @@ public class MongoStateReader implements
 
     @Override
     public String readEncrytionType() {
-        return (String) instance.get("_encrypt");
+        return (String) instance.get(ENCRYPT);
     }
 
     @Override
     public String readObjectType() {
-        return (String) instance.get("_type");
+        return (String) instance.get(TYPE);
     }
 
     @Override
     public String readId() {
-        return readField("_id");
+        return readField(ID);
     }
 
     @Override
     public String readVersion() {
-        return null;
+        return readField(VERSION);
     }
 
     @Override
     public String readUser() {
-        return null;
+        return readField(USER);
     }
 
     @Override
     public String readTime() {
-        return null;
+        return readField(TIME);
     }
 
     @Override

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java?rev=1240809&r1=1240808&r2=1240809&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java
Sun Feb  5 20:51:31 2012
@@ -30,7 +30,7 @@ import org.apache.log4j.Logger;
 import org.apache.isis.core.commons.exceptions.UnexpectedCallException;
 import org.apache.isis.runtimes.dflt.objectstores.nosql.StateWriter;
 
-public class MongoStateWriter implements StateWriter {
+public class MongoStateWriter implements StateWriter, PropertyNames {
     private static final Logger LOG = Logger.getLogger(MongoStateWriter.class);
     private final BasicDBObject dbObject;
     private final DBCollection instances;
@@ -47,12 +47,12 @@ public class MongoStateWriter implements
 
     @Override
     public void writeId(final String oid) {
-        writeField("_id", oid);
+        writeField(ID, oid);
     }
 
     @Override
     public void writeType(final String type) {
-        writeField("_type", type);
+        writeField(TYPE, type);
     }
 
     @Override
@@ -67,18 +67,22 @@ public class MongoStateWriter implements
 
     @Override
     public void writeEncryptionType(final String type) {
+        writeField(ENCRYPT, type);
     }
 
     @Override
     public void writeVersion(final String currentVersion, final String newVersion) {
+         writeField(VERSION, newVersion);
     }
 
     @Override
     public void writeTime(final String time) {
+        writeField(TIME, time);
     }
 
     @Override
     public void writeUser(final String user) {
+        writeField(USER, user);
     }
 
     @Override

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/PropertyNames.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/PropertyNames.java?rev=1240809&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/PropertyNames.java
(added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/PropertyNames.java
Sun Feb  5 20:51:31 2012
@@ -0,0 +1,31 @@
+/*
+ *  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.mongo;
+
+interface PropertyNames {
+    static final String ENCRYPT = "_encrypt";
+    static final String TYPE = "_type";
+    static final String ID = "_id";
+    static final String VERSION = "_version";
+    static final String TIME = "_time";
+    static final String USER = "_user";
+
+}
+

Propchange: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/PropertyNames.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 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/mongo/MongoDbTest.java?rev=1240809&r1=1240808&r2=1240809&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/mongo/MongoDbTest.java
Sun Feb  5 20:51:31 2012
@@ -84,9 +84,8 @@ public class MongoDbTest {
 
     @Test
     public void serialNumberSaved() throws Exception {
-        assertEquals(0, db.readSerialNumber());
-        db.writeSerialNumber(1023);
-        assertEquals(1023, db.readSerialNumber());
+        assertEquals(1, db.nextSerialNumberBatch("oid", 10));
+        assertEquals(11, db.nextSerialNumberBatch("oid", 10));
     }
 
     @Test



Mime
View raw message