ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [40/41] incubator-ignite git commit: #ignite-496: add type to sql query.
Date Mon, 29 Jun 2015 17:40:20 GMT
#ignite-496: add type to sql query.


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

Branch: refs/heads/ignite-964
Commit: 2a245b2906043704f6b2dcafda64952b33c1353c
Parents: 7dbdc6a
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Mon Jun 29 19:30:11 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Mon Jun 29 19:30:11 2015 +0300

----------------------------------------------------------------------
 .../handlers/query/QueryCommandHandler.java     |  2 +-
 .../rest/request/RestSqlQueryRequest.java       | 17 ++++
 modules/nodejs/src/main/js/cache.js             | 17 +++-
 modules/nodejs/src/main/js/server.js            |  4 -
 modules/nodejs/src/main/js/sql-query.js         | 85 +++++++++++++++++++-
 .../testsuites/IgniteNodeJsTestSuite.java       |  1 +
 modules/nodejs/src/test/js/test-query.js        |  2 +
 .../http/jetty/GridJettyRestHandler.java        |  1 +
 8 files changed, 118 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a245b29/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
index 82f3726..60efbd2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
@@ -114,7 +114,7 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter
{
         /** {@inheritDoc} */
         @Override public GridRestResponse call() throws Exception {
             try {
-                SqlQuery<String, String> qry = new SqlQuery(String.class, req.sqlQuery());
+                SqlQuery<String, String> qry = new SqlQuery(req.typeName(), req.sqlQuery());
 
                 Iterator<Cache.Entry<String, String>> cur =
                     ctx.grid().cache(req.cacheName()).query(qry).iterator();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a245b29/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
index 3a0005c..09b2fa3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
@@ -36,6 +36,9 @@ public class RestSqlQueryRequest extends GridRestRequest {
     /** Query id. */
     private Long qryId;
 
+    /** Query type name. */
+    private String typeName;
+
     /**
      * @param sqlQry Sql query.
      */
@@ -105,4 +108,18 @@ public class RestSqlQueryRequest extends GridRestRequest {
     public Long queryId() {
         return qryId;
     }
+
+    /**
+     * @param typeName Query type name.
+     */
+    public void typeName(String typeName) {
+        this.typeName = typeName;
+    }
+
+    /**
+     * @return Query type name.
+     */
+    public String typeName() {
+        return typeName;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a245b29/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 56a2def..03f9231 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -155,11 +155,22 @@ Cache.prototype.query = function(qry) {
         }
     }
 
-    this._server.runCommand("qryexecute", [
-        Server.pair("cacheName", this._cacheName),
+    var params = [Server.pair("cacheName", this._cacheName),
         Server.pair("qry", qry.query()),
         Server.pair("arg", qry.arguments()),
-        Server.pair("psz", qry.pageSize())],
+        Server.pair("psz", qry.pageSize())]
+
+    if (qry.returnType() != null) {
+        params.push(Server.pair("type", qry.returnType()));
+    }
+    else {
+        qry.error("No type for sql query.");
+        qry.end();
+
+        return;
+    }
+
+    this._server.runCommand("qryexecute", params,
         onQueryExecute.bind(this, qry));
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a245b29/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 376e981..d0ce68f 100644
--- a/modules/nodejs/src/main/js/server.js
+++ b/modules/nodejs/src/main/js/server.js
@@ -87,10 +87,6 @@ Server.prototype.runCommand = function(cmdName, params, callback) {
         });
 
         response.on('end', function () {
-            console.log("END " + response);
-            console.log("End status code " + response.statusCode);
-            console.log("Full response " + fullResponseString);
-
             if (response.statusCode !== 200) {
                 if (response.statusCode === 401) {
                     callback.call(null, "Authentication failed. Status code 401.");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a245b29/modules/nodejs/src/main/js/sql-query.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/sql-query.js b/modules/nodejs/src/main/js/sql-query.js
index ba554a3..0c57638 100644
--- a/modules/nodejs/src/main/js/sql-query.js
+++ b/modules/nodejs/src/main/js/sql-query.js
@@ -23,11 +23,19 @@ function SqlQuery(sql) {
     this._sql = sql;
     this._arg = [];
     this._pageSz = 1;
+    this._type = null;
     this._endFunc = function(res) {console.log("Empty end function is called [res=" + res
+ "]")};
     this._pageFunc = function(res) {console.log("Empty page function is called [res=" + res
+ "]")}
     this._errFunc = function(err) {console.log("Empty error function is called [err=" + err
+ "]")}
 }
 
+/**
+ * Set the callbacks for query events.
+ *
+ * @this {SqlQuery}
+ * @param {string} code Function code could be "end", "page", "error"
+ * @param function Functions "error" and "page" are one argument functions and "end" is function
without arguments.
+ */
 SqlQuery.prototype.on = function(code, f) {
     switch(code) {
         case "end":
@@ -47,28 +55,99 @@ SqlQuery.prototype.on = function(code, f) {
     }
 }
 
+/**
+ * @this {SqlQuery}
+ * @param res Query result
+ */
 SqlQuery.prototype.end = function(res) {
-    return this._endFunc(res);
+    this._endFunc(res);
 }
 
+/**
+ * @this {SqlQuery}
+ * @param err Query error
+ */
 SqlQuery.prototype.error = function(err) {
-    return this._errFunc(err);
+    this._errFunc(err);
 }
 
+/**
+ * @this {SqlQuery}
+ * @param res Query data
+ */
 SqlQuery.prototype.page = function(res) {
-    return this._pageFunc(res);
+    this._pageFunc(res);
 }
 
+/**
+ * @this {SqlQuery}
+ * @param {int} pageSz Page size.
+ */
+SqlQuery.prototype.setPageSize = function(pageSz) {
+    this._pageSize = pageSz;
+}
+
+/**
+ * @this {SqlQuery}
+ * @param args Arguments
+ */
+SqlQuery.prototype.setArguments = function(args) {
+    this._arg = args;
+}
+
+/**
+ * @this {SqlQuery}
+ * @param type Return class name
+ */
+SqlQuery.prototype.setReturnType = function(type) {
+    this._type = type;
+}
+
+/**
+ * @this {SqlQuery}
+ * @returns Sql query
+ */
 SqlQuery.prototype.query = function() {
     return this._sql;
 }
 
+/**
+ * @this {SqlQuery}
+ * @returns arguments
+ */
 SqlQuery.prototype.arguments = function() {
     return this._arg;
 }
 
+/**
+ * @this {SqlQuery}
+ * @returns pageSize
+ */
 SqlQuery.prototype.pageSize = function() {
     return this._pageSz;
 }
 
+/**
+ * @this {SqlQuery}
+ * @returns Return class name
+ */
+SqlQuery.prototype.returnType = function() {
+    return this._type;
+}
+
+/**
+ * @this {SqlQuery}
+ * @returns "Sql"
+ */
+SqlQuery.prototype.type = function() {
+    return SqlQuery.type();
+}
+
+/**
+ * @returns "Sql"
+ */
+SqlQuery.type = function() {
+    return "Sql"
+}
+
 exports.SqlQuery = SqlQuery;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a245b29/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
b/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
index 62360f2..f848b43 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
@@ -36,6 +36,7 @@ public class IgniteNodeJsTestSuite extends TestSuite {
         suite.addTest(new TestSuite(NodeJsSecretKeySelfTest.class));
         suite.addTest(new TestSuite(NodeJsComputeSelfTest.class));
         suite.addTest(new TestSuite(NodeJsIgniteSelfTest.class));
+        suite.addTest(new TestSuite(NodeJsSqlQuery.class));
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a245b29/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 bc0fdc2..cb97619 100644
--- a/modules/nodejs/src/test/js/test-query.js
+++ b/modules/nodejs/src/test/js/test-query.js
@@ -28,6 +28,8 @@ testSqlQuery = function() {
 
         var qry = new SqlQuery("select * from String");
 
+        qry.setReturnType("String");
+
         var fullRes = [];
 
         qry.on("error", function(err) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a245b29/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 361b713..27db356 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
@@ -476,6 +476,7 @@ public class GridJettyRestHandler extends AbstractHandler {
 
                 restReq0.sqlQuery((String)params.get("qry"));
                 restReq0.arguments(params.get("arg"));
+                restReq0.typeName((String)params.get("type"));
                 restReq0.pageSize(Integer.parseInt((String) params.get("psz")));
                 restReq0.cacheName((String)params.get("cacheName"));
 


Mime
View raw message