You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/26 18:47:01 UTC
[6/7] incubator-ignite git commit: #ignite-961: fix handleAsync in
QueryCommandHandler.
#ignite-961: fix handleAsync in QueryCommandHandler.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/1d03ca2d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/1d03ca2d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/1d03ca2d
Branch: refs/heads/ignite-964
Commit: 1d03ca2d5b5b0dc037c71c4634c42b73b668220a
Parents: de711c7
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jun 26 18:23:26 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jun 26 18:23:26 2015 +0300
----------------------------------------------------------------------
.../handlers/query/QueryCommandHandler.java | 53 ++++++++++++++------
1 file changed, 37 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1d03ca2d/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 6d2a2b7..f31e246 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
@@ -25,10 +25,10 @@ import org.apache.ignite.internal.processors.rest.handlers.*;
import org.apache.ignite.internal.processors.rest.request.*;
import org.apache.ignite.internal.util.future.*;
import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
import javax.cache.*;
import java.util.*;
+import java.util.concurrent.*;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.*;
@@ -61,25 +61,46 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
case EXECUTE_SQL_QUERY: {
assert req instanceof RestSqlQueryRequest : "Invalid type of query request.";
- return ctx.closure().callAsync(new IgniteClosure<RestSqlQueryRequest, GridRestResponse>() {
- @Override public GridRestResponse apply(RestSqlQueryRequest req0) {
- try {
- SqlQuery<String, String> qry = new SqlQuery(String.class, req0.sqlQuery());
+ return ctx.closure().callLocalSafe(new ExecuteQueryCallable(ctx, (RestSqlQueryRequest)req),false);
+ }
+ }
+
+ return new GridFinishedFuture<>();
+ }
- IgniteCache<Object, Object> cache = ctx.grid().cache(req0.cacheName());
+ /**
+ * Execute query callable.
+ */
+ private static class ExecuteQueryCallable implements Callable<GridRestResponse> {
+ /** Kernal context. */
+ private GridKernalContext ctx;
- List<Cache.Entry<String, String>> res = cache.query(qry).getAll();
+ /** Execute query request. */
+ private RestSqlQueryRequest req;
- return new GridRestResponse(res);
- }
- catch (Exception e) {
- return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
- }
- }
- }, (RestSqlQueryRequest)req, Collections.singleton(ctx.grid().localNode()));
- }
+ /**
+ * @param ctx Kernal context.
+ * @param req Execute query request.
+ */
+ public ExecuteQueryCallable(GridKernalContext ctx, RestSqlQueryRequest req) {
+ this.ctx = ctx;
+ this.req = req;
}
- return new GridFinishedFuture<>();
+ /** {@inheritDoc} */
+ @Override public GridRestResponse call() throws Exception {
+ try {
+ SqlQuery<String, String> qry = new SqlQuery(String.class, req.sqlQuery());
+
+ IgniteCache<Object, Object> cache = ctx.grid().cache(req.cacheName());
+
+ List<Cache.Entry<String, String>> res = cache.query(qry).getAll();
+
+ return new GridRestResponse(res);
+ }
+ catch (Exception e) {
+ return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+ }
+ }
}
}