ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject [2/4] incubator-ignite git commit: #ignite-964: add CACHE_GET_AND_REPLACE for nodejs cache.
Date Wed, 01 Jul 2015 14:08:50 GMT
#ignite-964: add CACHE_GET_AND_REPLACE 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/cb366d43
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/cb366d43
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/cb366d43

Branch: refs/heads/ignite-964
Commit: cb366d43cb1a1be7cc21240d44875f3ca48b786c
Parents: 2496ac3
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Wed Jul 1 16:46:08 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Wed Jul 1 16:46:08 2015 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cb366d43/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 86237b8..3887b4e 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
@@ -75,6 +75,9 @@ public enum GridRestCommand {
     /** Replace cache value only if there is currently a mapping for it. */
     CACHE_REPLACE("rep"),
 
+    /** Replace cache value only if there is currently a mapping for it. */
+    CACHE_GET_AND_REPLACE("getandreplace"),
+
     /** Compare and set. */
     CACHE_CAS("cas"),
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cb366d43/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 a19fde7..3eca643 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
@@ -549,6 +549,7 @@ public class GridRestProcessor extends GridProcessorAdapter {
             case CACHE_APPEND:
             case CACHE_PREPEND:
             case CACHE_GET_AND_PUT:
+            case CACHE_GET_AND_REPLACE:
             case CACHE_GET_AND_PUT_IF_ABSENT:
             case CACHE_PUT_IF_ABSENT:
                 perm = SecurityPermission.CACHE_PUT;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cb366d43/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 6db6c23..5631d87 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
@@ -57,6 +57,7 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
         CACHE_CONTAINS_KEY,
         CACHE_GET,
         CACHE_GET_AND_PUT,
+        CACHE_GET_AND_REPLACE,
         CACHE_GET_AND_PUT_IF_ABSENT,
         CACHE_PUT_IF_ABSENT,
         CACHE_GET_ALL,
@@ -79,6 +80,7 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
         CACHE_CONTAINS_KEY,
         CACHE_GET,
         CACHE_GET_AND_PUT,
+        CACHE_GET_AND_REPLACE,
         CACHE_GET_AND_PUT_IF_ABSENT,
         CACHE_PUT_IF_ABSENT,
         CACHE_PUT,
@@ -178,6 +180,13 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
                     break;
                 }
 
+                case CACHE_GET_AND_REPLACE: {
+                    fut = executeCommand(req.destinationId(), req.clientId(), cacheName,
skipStore, key,
+                        new GetAndReplaceCommand(key, getValue(req0)));
+
+                    break;
+                }
+
                 case CACHE_GET_AND_PUT_IF_ABSENT: {
                     fut = executeCommand(req.destinationId(), req.clientId(), cacheName,
skipStore, key,
                         new GetAndPutIfAbsentCommand(key, getValue(req0)));
@@ -866,6 +875,25 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
     }
 
     /** */
+    private static class GetAndReplaceCommand extends GetAndPutCommand {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /**
+         * @param key Key.
+         * @param val Value.
+         */
+        GetAndReplaceCommand(Object key, Object val) {
+            super(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public IgniteInternalFuture<?> applyx(IgniteInternalCache<Object,
Object> c, GridKernalContext ctx) {
+            return c.getAndReplaceAsync(key, val);
+        }
+    }
+
+    /** */
     private static class GetAndPutIfAbsentCommand extends GetAndPutCommand {
         /** */
         private static final long serialVersionUID = 0L;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cb366d43/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 d5bf7ae..3d42d94 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
@@ -196,4 +196,11 @@ public class NodeJsCacheApiSelfTest extends NodeJsAbstractTest {
     public void testReplaceObject() throws Exception {
         runJsScript("testReplaceObject");
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAndReplaceObject() throws Exception {
+        runJsScript("testGetAndReplaceObject");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cb366d43/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 cca7e10..864b4c1 100644
--- a/modules/nodejs/src/test/js/test-cache-api.js
+++ b/modules/nodejs/src/test/js/test-cache-api.js
@@ -202,6 +202,24 @@ testReplaceObject = function() {
     startTest("mycache", {trace: [put, replace], entry: [key, val]});
 }
 
+testGetAndReplaceObject = function() {
+    function getAndReplace(cache, entry, next) {
+        var newKey = {"key" :"7"};
+        cache.getAndReplace(entry[0], newKey, onGetAndReplace.bind(null, cache));
+
+        function onGetAndReplace(cache, err, res) {
+            assert(err === null, "Get error on get and put [err=" + err + "]");
+            assert(TestUtils.compareObject(val, res), "Get incorrect value on get.");
+            TestUtils.testDone();
+        }
+    }
+
+    var key = {"name" : "Paul"};
+    var val = {"age" : 12, "books" : ["1", "Book"]};
+
+    startTest("mycache", {trace: [put, getAndReplace], 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/cb366d43/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 b96b066..e1a56da 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
@@ -333,7 +333,8 @@ public class GridJettyRestHandler extends AbstractHandler {
 
             cmdRes.setResponse(res);
         } else if (cmd == CACHE_GET || cmd == CACHE_GET_AND_PUT ||
-            cmd == CACHE_GET_AND_PUT_IF_ABSENT || cmd == CACHE_GET_AND_REMOVE) {
+            cmd == CACHE_GET_AND_PUT_IF_ABSENT || cmd == CACHE_GET_AND_REMOVE ||
+            cmd == CACHE_GET_AND_REPLACE) {
             Object o = cmdRes.getResponse();
 
             if (o instanceof JSONCacheObject)
@@ -373,6 +374,7 @@ public class GridJettyRestHandler extends AbstractHandler {
             case CACHE_GET:
             case CACHE_GET_ALL:
             case CACHE_GET_AND_PUT:
+            case CACHE_GET_AND_REPLACE:
             case CACHE_PUT_IF_ABSENT:
             case CACHE_GET_AND_PUT_IF_ABSENT:
             case CACHE_PUT:
@@ -427,7 +429,8 @@ public class GridJettyRestHandler extends AbstractHandler {
                     else if (cmd == CACHE_GET || cmd == CACHE_PUT || cmd == CACHE_REMOVE
||
                         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_PUT_IF_ABSENT || cmd == CACHE_REMOVE_VALUE || cmd ==
CACHE_REPLACE ||
+                        cmd == CACHE_GET_AND_REPLACE) {
                         JSONCacheObject cacheObj = new JSONCacheObject(o);
 
                         restReq0.cacheName(F.isEmpty(cacheName) ? null : cacheName);


Mime
View raw message