jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1585497 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
Date Mon, 07 Apr 2014 14:51:07 GMT
Author: reschke
Date: Mon Apr  7 14:51:07 2014
New Revision: 1585497

URL: http://svn.apache.org/r1585497
Log:
OAK-1266 - simplify implementation of update(), add test case

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1585497&r1=1585496&r2=1585497&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
Mon Apr  7 14:51:07 2014
@@ -400,30 +400,11 @@ public class RDBDocumentStore implements
 
     @CheckForNull
     private <T extends Document> void internalUpdate(Collection<T> collection,
List<String> ids, UpdateOp update) {
-        Connection connection = null;
-        String tableName = getTable(collection);
-        try {
-            connection = getConnection();
-            for (String id : ids) {
-                String in = dbRead(connection, tableName, id);
-                if (in == null) {
-                    throw new MicroKernelException(tableName + " " + id + " not found");
-                }
-                T doc = fromString(collection, in);
-                Long oldmodcount = (Long) doc.get(MODCOUNT);
-                update.increment(MODCOUNT, 1);
-                UpdateUtils.applyChanges(doc, update, comparator);
-                String data = asString(doc);
-                Long modified = (Long) doc.get(MODIFIED);
-                Long modcount = (Long) doc.get(MODCOUNT);
-                dbUpdate(connection, tableName, id, modified, modcount, oldmodcount, data);
-                invalidateCache(collection, id); // TODO
-            }
-            connection.commit();
-        } catch (Exception ex) {
-            throw new MicroKernelException(ex);
-        } finally {
-            closeConnection(connection);
+
+        for (String id : ids) {
+            UpdateOp up = update.copy();
+            up = up.shallowCopy(id);
+            internalCreateOrUpdate(collection, up, false, true);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java?rev=1585497&r1=1585496&r2=1585497&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
Mon Apr  7 14:51:07 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.document;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -136,6 +137,32 @@ public class BasicDocumentStoreTest exte
     }
 
     @Test
+    public void testUpdateMultiple() {
+        String id = this.getClass().getName() + ".testUpdateMultiple";
+        // create a test node
+        UpdateOp up = new UpdateOp(id, true);
+        up.set("_id", id);
+        boolean success = super.ds.create(Collection.NODES, Collections.singletonList(up));
+        assertTrue(success);
+        removeMe.add(id);
+
+        // update a non-existing one and this one
+        List<String> toupdate = new ArrayList<String>();
+        toupdate.add(id + "-" + UUID.randomUUID());
+        toupdate.add(id);
+
+        UpdateOp up2 = new UpdateOp(id, false);
+        up2.set("foo", "bar");
+        ds.update(Collection.NODES, toupdate, up2);
+
+        // id should be updated
+        ds.invalidateCache();
+        Document d = ds.find(Collection.NODES, id);
+        assertNotNull(d);
+        assertEquals(d.get("foo").toString(), "bar");
+    }
+
+    @Test
     public void testCreatePerfSmall() {
         createPerf(16);
     }



Mime
View raw message