Repository: incubator-ignite Updated Branches: refs/heads/ignite-964-1 d218dfb1d -> 3f86e4b46
#ignite-964: remove error function for nodejs 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/576c4350 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/576c4350 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/576c4350 Branch: refs/heads/ignite-964-1 Commit: 576c43501702f8c8de0103bc50f355ac35d3bee9 Parents: f260e9b Author: ivasilinets <ivasilin...@gridgain.com> Authored: Tue Jun 30 13:46:57 2015 +0300 Committer: ivasilinets <ivasilin...@gridgain.com> Committed: Tue Jun 30 13:46:57 2015 +0300 ---------------------------------------------------------------------- .../handlers/query/QueryCommandHandler.java | 8 +-- .../rest/request/RestSqlQueryRequest.java | 10 ++-- modules/nodejs/src/main/js/cache.js | 9 +--- modules/nodejs/src/main/js/sql-fields-query.js | 23 ++------ modules/nodejs/src/test/js/test-query.js | 55 +++++++++----------- 5 files changed, 43 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/576c4350/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 496243e..a9f7b0f 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 @@ -190,12 +190,12 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter { /** {@inheritDoc} */ @Override public GridRestResponse call() throws Exception { try { - if (curs.contains(req.queryId())) + Iterator<Cache.Entry<String, String>> cur = curs.get(req.queryId()); + + if (cur == null) return new GridRestResponse(GridRestResponse.STATUS_FAILED, "Cannot find query [qryId=" + req.queryId() + "]"); - Iterator<Cache.Entry<String, String>> cur = curs.get(req.queryId()); - List<Cache.Entry<String, String>> res = new ArrayList<>(); CacheQueryResult response = new CacheQueryResult(); @@ -215,6 +215,8 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter { return new GridRestResponse(response); } catch (Exception e) { + curs.remove(req.queryId()); + return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage()); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/576c4350/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 830011a..5ba3a50 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 @@ -28,7 +28,7 @@ public class RestSqlQueryRequest extends GridRestRequest { private Object[] args; /** Page size. */ - private Integer pageSz; + private Integer pageSize; /** Cache name. */ private String cacheName; @@ -68,17 +68,17 @@ public class RestSqlQueryRequest extends GridRestRequest { } /** - * @param pageSz Page size. + * @param pageSize Page size. */ - public void pageSize(Integer pageSz) { - this.pageSz = pageSz; + public void pageSize(Integer pageSize) { + this.pageSize = pageSize; } /** * @return Page size. */ public int pageSize() { - return pageSz; + return pageSize; } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/576c4350/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 fc988da..8f074e3 100644 --- a/modules/nodejs/src/main/js/cache.js +++ b/modules/nodejs/src/main/js/cache.js @@ -138,20 +138,15 @@ Cache.prototype.getAll = function(keys, callback) { Cache.prototype.query = function(qry) { function onQueryExecute(qry, error, res) { if (error !== null) { - qry.error(error); - qry.end(); + qry.end(error); return; } - console.log("Qry: " + qry.type()); - - console.log("Error: " + error); - console.log("Result: " + res); qry.page(res["items"]); if (res["last"]) { - qry.end(); + qry.end(null); } else { this._server.runCommand("qryfetch", [ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/576c4350/modules/nodejs/src/main/js/sql-fields-query.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/sql-fields-query.js b/modules/nodejs/src/main/js/sql-fields-query.js index 02205cf..13c6df8 100644 --- a/modules/nodejs/src/main/js/sql-fields-query.js +++ b/modules/nodejs/src/main/js/sql-fields-query.js @@ -25,17 +25,16 @@ function SqlFieldsQuery(sql) { this._arg = []; this._pageSz = 1; this._type = null; - this._endFunc = function(res) {console.log("Empty end function is called [res=" + res + "]")}; + this._endFunc = function(err) {console.log("Empty end function is called [err=" + err + "]")}; 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 {SqlFieldsQuery} - * @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. + * @param {string} code Function code could be "end", "page" + * @param function Functions "end" and "page" are one argument functions. */ SqlFieldsQuery.prototype.on = function(code, f) { switch(code) { @@ -47,10 +46,6 @@ SqlFieldsQuery.prototype.on = function(code, f) { this._pageFunc = f; break; - case "error" : - this._errFunc = f; - - break; default : throw "Sql do not have method " + code; } @@ -60,16 +55,8 @@ SqlFieldsQuery.prototype.on = function(code, f) { * @this {SqlFieldsQuery} * @param res Query result */ -SqlFieldsQuery.prototype.end = function(res) { - this._endFunc(res); -} - -/** - * @this {SqlFieldsQuery} - * @param err Query error - */ -SqlFieldsQuery.prototype.error = function(err) { - this._errFunc(err); +SqlFieldsQuery.prototype.end = function(err) { + this._endFunc(err); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/576c4350/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 794e71a..77bbad1 100644 --- a/modules/nodejs/src/test/js/test-query.js +++ b/modules/nodejs/src/test/js/test-query.js @@ -33,26 +33,24 @@ testSqlQuery = function() { var fullRes = []; - qry.on("error", function(err) { - TestUtils.testFails(); - }); - qry.on("page", function(res) { fullRes = fullRes.concat(res); }); - qry.on("end", function() { - assert(fullRes.length, 1, "Result length is not correct" + - "[expected=1, val = " + fullRes.length + "]"); + qry.on("end", function(err) { + assert(err === null, "Error on query [err=" + err + "]."); - assert(fullRes[0]["key"] === "key0", "Result value for key is not correct "+ - "[expected=key0, real=" + fullRes[0]["key"] + "]"); + assert(fullRes.length, 1, "Result length is not correct" + + "[expected=1, val = " + fullRes.length + "]"); - assert(fullRes[0]["value"] === "val0", "Result value for key is not correct "+ - "[expected=val0, real=" + fullRes[0]["value"] + "]"); + assert(fullRes[0]["key"] === "key0", "Result value for key is not correct "+ + "[expected=key0, real=" + fullRes[0]["key"] + "]"); - TestUtils.testDone(); - }); + assert(fullRes[0]["value"] === "val0", "Result value for key is not correct "+ + "[expected=val0, real=" + fullRes[0]["value"] + "]"); + + TestUtils.testDone(); + }); ignite.cache("mycache").query(qry); } @@ -74,23 +72,24 @@ testSqlFieldsQuery = function() { var fullRes = []; - qry.on("error", function(err) { - TestUtils.testFails(); - }); - qry.on("page", function(res) { + console.log("PAGE:" + res); fullRes = fullRes.concat(res); }); - qry.on("end", function() { - assert(fullRes.length, 1, "Result length is not correct" + - "[expected=1, val = " + fullRes.length + "]"); + qry.on("end", function(err) { + assert(err === null, "Error on query [err=" + err + "]."); - assert(fullRes[0].indexOf("Jane Doe") > -1, - "Result does not contain Jane Doe [res=" + fullRes[0] + "]"); + assert(fullRes.length, 4, "Result length is not correct" + + "[expected=1, val = " + fullRes.length + "]"); - TestUtils.testDone(); - }); + fullRes.sort(); + + assert(fullRes[0].indexOf("Jane Doe") > -1, + "Result does not contain Jane Doe [res=" + fullRes[0] + "]"); + + TestUtils.testDone(); + }); ignite.cache("person").query(qry); } @@ -110,15 +109,13 @@ testSqlQueryWithParams = function() { var fullRes = []; - qry.on("error", function(err) { - TestUtils.testFails(); - }); - qry.on("page", function(res) { fullRes = fullRes.concat(res); }); - qry.on("end", function() { + qry.on("end", function(err) { + assert(err === null, "Error on query [err=" + err + "]."); + //TODO: assert(fullRes.length, 1, "Result length is not correct" + "[expected=1, val = " + fullRes.length + "]");