ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject [3/4] incubator-ignite git commit: #ignite-964: add CACHE_REPLACE_VALUE for nodejs cache.
Date Wed, 01 Jul 2015 14:08:51 GMT
#ignite-964: add CACHE_REPLACE_VALUE for nodejs cache.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/13e78dac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/13e78dac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/13e78dac

Branch: refs/heads/ignite-964
Commit: 13e78dacab1eb3eb9e4c49d0d51c6142c2f7834a
Parents: cb366d4
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Wed Jul 1 16:56:13 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Wed Jul 1 16:56:13 2015 +0300

----------------------------------------------------------------------
 .../processors/rest/GridRestCommand.java        |  3 ++
 .../processors/rest/GridRestProcessor.java      |  1 +
 .../handlers/cache/GridCacheCommandHandler.java | 33 ++++++++++++++++++++
 modules/nodejs/src/main/js/cache.js             | 18 +++++++++--
 .../ignite/internal/NodeJsCacheApiSelfTest.java |  7 +++++
 modules/nodejs/src/test/js/test-cache-api.js    | 18 +++++++++++
 .../http/jetty/GridJettyRestHandler.java        |  4 ++-
 7 files changed, 81 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/13e78dac/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
index 3887b4e..90d7dc2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
@@ -76,6 +76,9 @@ public enum GridRestCommand {
     CACHE_REPLACE("rep"),
 
     /** Replace cache value only if there is currently a mapping for it. */
+    CACHE_REPLACE_VALUE("repval"),
+
+    /** Replace cache value only if there is currently a mapping for it. */
     CACHE_GET_AND_REPLACE("getandreplace"),
 
     /** Compare and set. */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/13e78dac/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
index 3eca643..c3c9871 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
@@ -552,6 +552,7 @@ public class GridRestProcessor extends GridProcessorAdapter {
             case CACHE_GET_AND_REPLACE:
             case CACHE_GET_AND_PUT_IF_ABSENT:
             case CACHE_PUT_IF_ABSENT:
+            case CACHE_REPLACE_VALUE:
                 perm = SecurityPermission.CACHE_PUT;
                 name = ((GridRestCacheRequest)req).cacheName();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/13e78dac/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
index 5631d87..87a87e3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
@@ -66,6 +66,7 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
         CACHE_PUT_ALL,
         CACHE_REMOVE,
         CACHE_REMOVE_VALUE,
+        CACHE_REPLACE_VALUE,
         CACHE_GET_AND_REMOVE,
         CACHE_REMOVE_ALL,
         CACHE_REPLACE,
@@ -87,6 +88,7 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
         CACHE_ADD,
         CACHE_REMOVE,
         CACHE_REMOVE_VALUE,
+        CACHE_REPLACE_VALUE,
         CACHE_GET_AND_REMOVE,
         CACHE_REPLACE,
         ATOMIC_INCREMENT,
@@ -259,6 +261,13 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
                     break;
                 }
 
+                case CACHE_REPLACE_VALUE: {
+                    fut = executeCommand(req.destinationId(), req.clientId(), cacheName,
skipStore, key,
+                        new ReplaceValueCommand(key, getValue(req0), req0.value2()));
+
+                    break;
+                }
+
                 case CACHE_GET_AND_REMOVE: {
                     fut = executeCommand(req.destinationId(), req.clientId(), cacheName,
skipStore, key,
                         new GetAndRemoveCommand(key));
@@ -894,6 +903,30 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
     }
 
     /** */
+    private static class ReplaceValueCommand extends GetAndReplaceCommand {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** */
+        private final Object oldVal;
+
+        /**
+         * @param key Key.
+         * @param val Value.
+         * @param oldVal Old value.
+         */
+        ReplaceValueCommand(Object key, Object val, Object oldVal) {
+            super(key, val);
+            this.oldVal = oldVal;
+        }
+
+        /** {@inheritDoc} */
+        @Override public IgniteInternalFuture<?> applyx(IgniteInternalCache<Object,
Object> c, GridKernalContext ctx) {
+            return c.replaceAsync(key, oldVal, val);
+        }
+    }
+
+    /** */
     private static class GetAndPutIfAbsentCommand extends GetAndPutCommand {
         /** */
         private static final long serialVersionUID = 0L;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/13e78dac/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index bb48dfd..97175fd 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -220,8 +220,8 @@ Cache.prototype.getAndPut = function(key, val, callback) {
  * replace cache value
  *
  * @this {Cache}
- * @param {string} key Key
- * @param {string} value Value
+ * @param key Key
+ * @param value Value
  * @param {onGet} callback Called on finish
  */
 Cache.prototype.replace = function(key, val, callback) {
@@ -230,6 +230,20 @@ Cache.prototype.replace = function(key, val, callback) {
 }
 
 /**
+ * replace cache value
+ *
+ * @this {Cache}
+ * @param key Key
+ * @param value Value
+ * @param oldVal Old value
+ * @param {onGet} callback Called on finish
+ */
+Cache.prototype.replaceValue = function(key, val, oldVal, callback) {
+    this._server.runCommand(this._createCommand("repVal").
+        setPostData(JSON.stringify({"key" : key, "val" : val, "oldVal" : oldVal})), callback);
+}
+
+/**
  * Get and put cache value
  *
  * @this {Cache}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/13e78dac/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
index 3d42d94..a79ab6f 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
@@ -203,4 +203,11 @@ public class NodeJsCacheApiSelfTest extends NodeJsAbstractTest {
     public void testGetAndReplaceObject() throws Exception {
         runJsScript("testGetAndReplaceObject");
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplaceValueObject() throws Exception {
+        runJsScript("testReplaceValueObject");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/13e78dac/modules/nodejs/src/test/js/test-cache-api.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-cache-api.js b/modules/nodejs/src/test/js/test-cache-api.js
index 864b4c1..99c97c9 100644
--- a/modules/nodejs/src/test/js/test-cache-api.js
+++ b/modules/nodejs/src/test/js/test-cache-api.js
@@ -220,6 +220,24 @@ testGetAndReplaceObject = function() {
     startTest("mycache", {trace: [put, getAndReplace], entry: [key, val]});
 }
 
+testReplaceValueObject = function() {
+    function replaceValue(cache, entry, next) {
+        var newKey = {"key" :"7"};
+        cache.replaceValue(entry[0], newKey, entry[1], onReplaceValue.bind(null, cache));
+
+        function onReplaceValue(cache, err, res) {
+            assert(err === null, "Get error on get and put [err=" + err + "]");
+            assert(res === true, "Incorrect result for replace [expected=true, val" + res
+ "]");
+            TestUtils.testDone();
+        }
+    }
+
+    var key = {"name" : "Paul"};
+    var val = {"age" : 12, "books" : ["1", "Book"]};
+
+    startTest("mycache", {trace: [put, replaceValue], entry: [key, val]});
+}
+
 testIncorrectReplaceObject = function() {
     function replace(cache, entry, next) {
         cache.replace(entry[0], "7", onReplace.bind(null, cache));

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/13e78dac/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index e1a56da..8b60fcf 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -381,6 +381,7 @@ public class GridJettyRestHandler extends AbstractHandler {
             case CACHE_PUT_ALL:
             case CACHE_REMOVE:
             case CACHE_REMOVE_VALUE:
+            case CACHE_REPLACE_VALUE:
             case CACHE_GET_AND_REMOVE:
             case CACHE_REMOVE_ALL:
             case CACHE_ADD:
@@ -430,13 +431,14 @@ public class GridJettyRestHandler extends AbstractHandler {
                         cmd == CACHE_CONTAINS_KEY || cmd == CACHE_GET_AND_PUT ||
                         cmd == CACHE_GET_AND_PUT_IF_ABSENT || cmd == CACHE_GET_AND_REMOVE
||
                         cmd == CACHE_PUT_IF_ABSENT || cmd == CACHE_REMOVE_VALUE || cmd ==
CACHE_REPLACE ||
-                        cmd == CACHE_GET_AND_REPLACE) {
+                        cmd == CACHE_GET_AND_REPLACE || cmd == CACHE_REPLACE_VALUE) {
                         JSONCacheObject cacheObj = new JSONCacheObject(o);
 
                         restReq0.cacheName(F.isEmpty(cacheName) ? null : cacheName);
 
                         restReq0.key(cacheObj.getField("key"));
                         restReq0.value(cacheObj.getField("val"));
+                        restReq0.value2(cacheObj.getField("oldVal"));
                     }
                 }
                 else {


Mime
View raw message