ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject [15/39] incubator-ignite git commit: #ignite-964: sql query works with arguments.
Date Wed, 01 Jul 2015 10:13:51 GMT
#ignite-964: sql query works with arguments.


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

Branch: refs/heads/ignite-964
Commit: 54be1060053577dce1f689cb2aeec4210866b707
Parents: 3f86e4b
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Tue Jun 30 16:00:11 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Tue Jun 30 16:00:11 2015 +0300

----------------------------------------------------------------------
 modules/nodejs/src/main/js/server.js            |  2 +-
 .../ignite/internal/NodeJsSqlQuerySelfTest.java | 60 +++++++++++++++-----
 modules/nodejs/src/test/js/test-query.js        | 22 +++----
 .../http/jetty/GridJettyRestHandler.java        |  2 -
 4 files changed, 57 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/54be1060/modules/nodejs/src/main/js/server.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/server.js b/modules/nodejs/src/main/js/server.js
index e49ed83..021fffe 100644
--- a/modules/nodejs/src/main/js/server.js
+++ b/modules/nodejs/src/main/js/server.js
@@ -151,7 +151,7 @@ Server.prototype.checkConnection = function(callback) {
  */
 Server.prototype._signature = function() {
     if (!this._secretKey) {
-        return "";
+        return {};
     }
 
     var loadTimeInMS = Date.now();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/54be1060/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
index 8d33668..a6891fb 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
@@ -18,12 +18,11 @@
 package org.apache.ignite.internal;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.cache.query.*;
 import org.apache.ignite.cache.query.annotations.*;
 import org.apache.ignite.configuration.*;
 
 import java.io.*;
-import java.util.*;
 
 /**
  * Node js sql query test.
@@ -75,29 +74,40 @@ public class NodeJsSqlQuerySelfTest extends NodeJsAbstractTest {
      * Init cache.
      */
     private void initCache() {
-        CacheConfiguration<UUID, Person> personCacheCfg = new CacheConfiguration<>("person");
-        personCacheCfg.setIndexedTypes(UUID.class, Person.class);
+        CacheConfiguration<Integer, Person> personCacheCfg = new CacheConfiguration<>("person");
+        personCacheCfg.setIndexedTypes(Integer.class, Person.class);
 
-        IgniteCache<UUID, Person> personCache = grid(0).getOrCreateCache(personCacheCfg);
+        IgniteCache<Integer, Person> personCache = grid(0).getOrCreateCache(personCacheCfg);
+
+        personCache.clear();
 
         Person p1 = new Person("John", "Doe", 2000);
         Person p2 = new Person("Jane", "Doe", 1000);
         Person p3 = new Person("John", "Smith", 1000);
         Person p4 = new Person("Jane", "Smith", 2000);
 
-        personCache.put(p4.getId(), p1);
-        personCache.put(p4.getId(), p2);
-        personCache.put(p4.getId(), p3);
+        personCache.put(p1.getId(), p1);
+        personCache.put(p2.getId(), p2);
+        personCache.put(p3.getId(), p3);
         personCache.put(p4.getId(), p4);
+
+        SqlQuery qry = new SqlQuery(Person.class, "salary > ? and salary <= ?");
+
+        qry.setArgs(1000, 2000);
+
+        assertEquals(2, personCache.query(qry).getAll().size());
     }
 
     /**
      * Person class.
      */
     public static class Person implements Serializable {
+        /** Person id. */
+        private static int PERSON_ID = 0;
+
         /** Person ID (indexed). */
         @QuerySqlField(index = true)
-        private UUID id;
+        private Integer id;
 
         /** First name (not-indexed). */
         @QuerySqlField
@@ -116,44 +126,68 @@ public class NodeJsSqlQuerySelfTest extends NodeJsAbstractTest {
          * @param lastName Last name.
          * @param salary Salary.
          */
-        Person( String firstName, String lastName, double salary) {
-            id = UUID.randomUUID();
+        Person(String firstName, String lastName, double salary) {
+            id = PERSON_ID++;
 
             this.firstName = firstName;
             this.lastName = lastName;
             this.salary = salary;
         }
 
+        /**
+         * @param firstName First name.
+         */
         public void setFirstName(String firstName) {
             this.firstName = firstName;
         }
 
+        /**
+         * @return First name.
+         */
         public String getFirstName() {
             return firstName;
         }
 
+        /**
+         * @param lastName Last name.
+         */
         public void setLastName(String lastName) {
             this.lastName = lastName;
         }
 
+        /**
+         * @return Last name.
+         */
         public String getLastName() {
             return lastName;
         }
 
-        public void setId(UUID id) {
+        /**
+         * @param id Id.
+         */
+        public void setId(Integer id) {
             this.id = id;
         }
 
+        /**
+         * @param salary Salary.
+         */
         public void setSalary(double salary) {
             this.salary = salary;
         }
 
+        /**
+         * @return Salary.
+         */
         public double getSalary() {
 
             return salary;
         }
 
-        public UUID getId() {
+        /**
+         * @return Id.
+         */
+        public Integer getId() {
             return id;
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/54be1060/modules/nodejs/src/test/js/test-query.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-query.js b/modules/nodejs/src/test/js/test-query.js
index c407816..a86c057 100644
--- a/modules/nodejs/src/test/js/test-query.js
+++ b/modules/nodejs/src/test/js/test-query.js
@@ -40,7 +40,7 @@ testSqlQuery = function() {
         qry.on("end", function(err) {
             assert(err === null, "Error on query [err=" + err + "].");
 
-            assert(fullRes.length, 1, "Result length is not correct" +
+            assert(fullRes.length === 1, "Result length is not correct" +
                 "[expected=1, val = " + fullRes.length + "]");
 
             assert(fullRes[0]["key"] === "key0", "Result value for key is not correct "+
@@ -80,7 +80,7 @@ testSqlFieldsQuery = function() {
         qry.on("end", function(err) {
             assert(err === null, "Error on query [err=" + err + "].");
 
-            assert(fullRes.length, 4, "Result length is not correct" +
+            assert(fullRes.length === 4, "Result length is not correct" +
                 "[expected=1, val = " + fullRes.length + "]");
 
             fullRes.sort();
@@ -98,7 +98,7 @@ testSqlFieldsQuery = function() {
 }
 
 testSqlQueryWithParams = function() {
-    function sqlFieldsQuery(error, ignite) {
+    function sqlQueryWithParams(error, ignite) {
         assert(error == null, "error on sql query [err=" + error + "]");
 
         var qry = new SqlQuery("salary > ? and salary <= ?");
@@ -110,23 +110,18 @@ testSqlQueryWithParams = function() {
         var fullRes = [];
 
         qry.on("page", function(res) {
-            console.log("!!!!!Page:" + res);
-            console.log("!!!!!Page2:" + res);
-
             fullRes = fullRes.concat(res);
         });
 
         qry.on("end", function(err) {
-            console.log("RES:" + fullRes);
-
             assert(err === null, "Error on query [err=" + err + "].");
 
-            //TODO:
-            assert(fullRes.length, 2, "Result length is not correct" +
+            assert(fullRes.length === 2, "Result length is not correct" +
                 "[expected=1, val = " + fullRes.length + "]");
 
-            assert(fullRes[0].indexOf("Jane Doe") > -1,
-                "Result does not contain Jane Doe [res=" + fullRes[0] + "]");
+            assert(((fullRes[0]["value"]["firstName"].indexOf("Jane") > -1) ||
+                (fullRes[0]["value"]["firstName"].indexOf("John") > -1)),
+                "Result does not contain Jane and John [res=" + fullRes[0]["value"]["firstName"]
+ "]");
 
             TestUtils.testDone();
         });
@@ -134,4 +129,5 @@ testSqlQueryWithParams = function() {
         ignite.cache("person").query(qry);
     }
 
-    TestUtils.startIgniteN
\ No newline at end of file
+    TestUtils.startIgniteNode(sqlQueryWithParams.bind(null));
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/54be1060/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 e37f422..6327c88 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
@@ -522,10 +522,8 @@ public class GridJettyRestHandler extends AbstractHandler {
                     builder.append(reader.next() + "\n");
 
                 JSONObject o = JSONObject.fromObject(builder.toString());
-                System.out.println("ARGUMENTS " + o.get("arg"));
 
                 List<Object> args = (List<Object>)o.get("arg");
-
                 restReq0.arguments(args.toArray());
 
                 restReq0.typeName((String)params.get("type"));


Mime
View raw message