You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2017/05/19 06:12:19 UTC

svn commit: r1795582 - in /jackrabbit/oak/branches/1.4: ./ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/ oak-core/src/main/java/org/apache/jackrabbit/oak/plug...

Author: reschke
Date: Fri May 19 06:12:19 2017
New Revision: 1795582

URL: http://svn.apache.org/viewvc?rev=1795582&view=rev
Log:
OAK-5741: DocumentStore UpdateOp: support removal of properties (ported to 1.4)

Modified:
    jackrabbit/oak/branches/1.4/   (props changed)
    jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Document.java
    jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateOp.java
    jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateUtils.java
    jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
    jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
    jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java

Propchange: jackrabbit/oak/branches/1.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri May 19 06:12:19 2017
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735081,1735109,1735141,1735267,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738136,1738138,1738207,1738234,1738252,1738775,1738795,1738833,1738950,1738957,1738963,1739712,1739760,1739867,1739894,1739959-1739960,1740114,1740116,1740250,1740333,1740349,1740360,1740625-1740626,1740774,1740837,1740879,1740971,1741016,1741032,1741339,1741343,1742077,1742117,1742125,1742363,1742520,1742888,1742916,1743097,1743172,1743343,1743674,1744265,1744292,1744589,1744670,1744672,1744959,1745038,1745127,1745197,1745336,1745368,1746086,1746117,1746342,1746345,1746408,1746634,1746696,1746981,1747198,1747200,1747341-1747342,1747380,1747387,1747406,1747492,1747512,1747654,1748505,1748553,1748722,1748870,1749275,1749350,1749424,1749443,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287
 ,1750457,1750462,1750465,1750495,1750626,1750809,1750886-1750887,1751396,1751410,1751419,1751445-1751446,1751478,1751748,1751753,1751755,1751871,1752198,1752202,1752259,1752273-1752274,1752283,1752292,1752438,1752447-1752448,1752508,1752596,1752616,1752659,1752672,1753262,1753331-1753332,1753335-1753336,1753355,1753444,1754117,1754239,1755157,1755191,1756520,1756580,1757119,1757166,1758213,1758713,1759433,1759795,1759826,1760326,1760340,1760373,1760387,1760486,1760492,1760494,1760661-1760662,1760677,1760701,1760709,1760946,1761412,1761444,1761571,1761762,1761787,1761866,1761876,1762453,1762612,1762632,1762635,1763347,1763355-1763356,1763378,1763465,1763735,1764678,1764705,1764814,1764898,1765817,1765983,1766071,1766390,1766423,1766496,1766519,1766554,1766644,1767025,1767265,1767502,1767704,1768446,1768637,1769078,1769939-1769940,1770694,1770982,1771022,1771093,1771098,1771739,1771852,1771870,1771902,1772155,1772162,1772228,1772593,1772768,1773190,1774497,1774787,1775474,1775622,1775
 628,1775757,1778112,1778423,1778968,1779137,1779478,1780388,1780424,1780538,1780543,1781068,1781075,1781386,1781846,1781907,1782476,1782966,1783066,1783089,1783104-1783105,1783110,1783619,1783720,1783738,1783773,1783855,1784023,1784130,1784251,1784574,1784689,1785283,1785946,1787074,1787217,1787425,1789056,1792463,1792742,1793088,1793644,1795314,1795330,1795475,1795488,1795491
+/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735081,1735109,1735141,1735267,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738136,1738138,1738207,1738234,1738252,1738775,1738795,1738833,1738950,1738957,1738963,1739712,1739760,1739867,1739894,1739959-1739960,1740114,1740116,1740250,1740333,1740349,1740360,1740625-1740626,1740774,1740837,1740879,1740971,1741016,1741032,1741339,1741343,1742077,1742117,1742125,1742363,1742520,1742888,1742916,1743097,1743172,1743343,1743674,1744265,1744292,1744589,1744670,1744672,1744959,1745038,1745127,1745197,1745336,1745368,1746086,1746117,1746342,1746345,1746408,1746634,1746696,1746981,1747198,1747200,1747341-1747342,1747380,1747387,1747406,1747492,1747512,1747654,1748505,1748553,1748722,1748870,1749275,1749350,1749424,1749443,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287
 ,1750457,1750462,1750465,1750495,1750626,1750809,1750886-1750887,1751396,1751410,1751419,1751445-1751446,1751478,1751748,1751753,1751755,1751871,1752198,1752202,1752259,1752273-1752274,1752283,1752292,1752438,1752447-1752448,1752508,1752596,1752616,1752659,1752672,1753262,1753331-1753332,1753335-1753336,1753355,1753444,1754117,1754239,1755157,1755191,1756520,1756580,1757119,1757166,1758213,1758713,1759433,1759795,1759826,1760326,1760340,1760373,1760387,1760486,1760492,1760494,1760661-1760662,1760677,1760701,1760709,1760946,1761412,1761444,1761571,1761762,1761787,1761866,1761876,1762453,1762612,1762632,1762635,1763347,1763355-1763356,1763378,1763465,1763735,1764678,1764705,1764814,1764898,1765817,1765983,1766071,1766390,1766423,1766496,1766519,1766554,1766644,1767025,1767265,1767502,1767704,1768446,1768637,1769078,1769939-1769940,1770694,1770982,1771022,1771093,1771098,1771739,1771852,1771870,1771902,1772155,1772162,1772228,1772593,1772768,1773190,1774497,1774787,1775474,1775622,1775
 628,1775757,1778112,1778423,1778968,1779137,1779478,1780388,1780424,1780538,1780543,1781068,1781075,1781386,1781846,1781907,1782476,1782966,1783066,1783089,1783104-1783105,1783110,1783619,1783720,1783738,1783773,1783855,1784023,1784034,1784130,1784251,1784574,1784689,1785283,1785946,1787074,1787217,1787425,1789056,1792463,1792742,1793088,1793644,1795314,1795330,1795475,1795488,1795491
 /jackrabbit/trunk:1345480

Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Document.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Document.java?rev=1795582&r1=1795581&r2=1795582&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Document.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Document.java Fri May 19 06:12:19 2017
@@ -111,6 +111,17 @@ public class Document implements CacheVa
     }
 
     /**
+     * Removes the given <code>key</code>.
+     *
+     * @param key the key.
+     * @return the previous value or <code>null</code> if there was none.
+     */
+    @CheckForNull
+    public Object remove(String key) {
+        return data.remove(key);
+    }
+
+    /**
      * @return a Set view of the keys contained in this document.
      */
     public Set<String> keySet() {

Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateOp.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateOp.java?rev=1795582&r1=1795581&r2=1795582&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateOp.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateOp.java Fri May 19 06:12:19 2017
@@ -160,6 +160,19 @@ public final class UpdateOp {
     }
 
     /**
+     * Remove a property.
+     *
+     * @param property the property name
+     */
+    public void remove(@Nonnull String property) {
+        if (Document.ID.equals(property)) {
+            throw new IllegalArgumentException(Document.ID + " must not be removed");
+        }
+        Operation op = new Operation(Operation.Type.REMOVE, null);
+        changes.put(new Key(property, null), op);
+    }
+
+    /**
      * Remove a map entry.
      * The property is a map of revisions / values.
      *
@@ -396,8 +409,13 @@ public final class UpdateOp {
              * Remove the sub-key / value pair.
              * The value in the stored node is a map.
              */
-            REMOVE_MAP_ENTRY
+            REMOVE_MAP_ENTRY,
 
+            /**
+             * Remove the value.
+             * The sub-key is not used.
+             */
+            REMOVE
          }
 
 
@@ -424,17 +442,18 @@ public final class UpdateOp {
         public Operation getReverse() {
             Operation reverse = null;
             switch (type) {
-            case INCREMENT:
-                reverse = new Operation(Type.INCREMENT, -(Long) value);
-                break;
-            case SET:
-            case MAX:
-            case REMOVE_MAP_ENTRY:
-                // nothing to do
-                break;
-            case SET_MAP_ENTRY:
-                reverse = new Operation(Type.REMOVE_MAP_ENTRY, null);
-                break;
+                case INCREMENT:
+                    reverse = new Operation(Type.INCREMENT, -(Long) value);
+                    break;
+                case SET:
+                case MAX:
+                case REMOVE_MAP_ENTRY:
+                case REMOVE:
+                    // nothing to do
+                    break;
+                case SET_MAP_ENTRY:
+                    reverse = new Operation(Type.REMOVE_MAP_ENTRY, null);
+                    break;
             }
             return reverse;
         }

Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateUtils.java?rev=1795582&r1=1795581&r2=1795582&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateUtils.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateUtils.java Fri May 19 06:12:19 2017
@@ -55,6 +55,10 @@ public class UpdateUtils {
                     doc.put(k.toString(), op.value);
                     break;
                 }
+                case REMOVE: {
+                    doc.remove(k.toString());
+                    break;
+                }
                 case MAX: {
                     Comparable newValue = (Comparable) op.value;
                     Object old = doc.get(k.toString());

Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1795582&r1=1795581&r2=1795582&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java Fri May 19 06:12:19 2017
@@ -1096,6 +1096,7 @@ public class MongoDocumentStore implemen
                         }
                         break;
                     }
+                    case REMOVE:
                     case REMOVE_MAP_ENTRY:
                         // nothing to do for new entries
                         break;
@@ -1457,6 +1458,7 @@ public class MongoDocumentStore implemen
                     incUpdates.append(k.toString(), op.value);
                     break;
                 }
+                case REMOVE:
                 case REMOVE_MAP_ENTRY: {
                     unsetUpdates.append(k.toString(), "1");
                     break;

Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java?rev=1795582&r1=1795581&r2=1795582&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java Fri May 19 06:12:19 2017
@@ -121,7 +121,7 @@ public class RDBDocumentSerializer {
                 sb.append("\"=\",");
             } else if (op.type == UpdateOp.Operation.Type.MAX) {
                 sb.append("\"M\",");
-            } else if (op.type == UpdateOp.Operation.Type.REMOVE_MAP_ENTRY) {
+            } else if (op.type == UpdateOp.Operation.Type.REMOVE || op.type == UpdateOp.Operation.Type.REMOVE_MAP_ENTRY) {
                 sb.append("\"*\",");
             } else {
                 throw new DocumentStoreException("Can't serialize " + update.toString() + " for JSON append");
@@ -266,7 +266,7 @@ public class RDBDocumentSerializer {
             }
         } else if ("*".equals(opcode)) {
             if (rev == null) {
-                throw new DocumentStoreException("unexpected operation " + op + " in: " + updateString);
+                doc.remove(key);
             } else {
                 @SuppressWarnings("unchecked")
                 Map<Revision, Object> m = (Map<Revision, Object>) old;

Modified: jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java?rev=1795582&r1=1795581&r2=1795582&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java Fri May 19 06:12:19 2017
@@ -133,6 +133,17 @@ public class BasicDocumentStoreTest exte
         assertEquals(NodeDocument.HAS_BINARY_VAL, nd.get(NodeDocument.HAS_BINARY_FLAG));
         assertFalse(nd.wasDeletedOnce());
         assertTrue(nd.hasBinary());
+        
+        // remove
+        up = new UpdateOp(id, false);
+        up.remove(NodeDocument.DELETED_ONCE);
+        up.remove(NodeDocument.HAS_BINARY_FLAG);
+        super.ds.findAndUpdate(Collection.NODES, up);
+        
+        super.ds.invalidateCache();
+        nd = super.ds.find(Collection.NODES, id, 0);
+        assertNull(nd.get(NodeDocument.DELETED_ONCE));
+        assertNull(nd.get(NodeDocument.HAS_BINARY_FLAG));
     }
 
     @Test