ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject incubator-ignite git commit: # ignite 692 Reworked to use new SQL API.
Date Tue, 07 Apr 2015 11:42:56 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-692 [created] c06a4ae1a


# ignite 692 Reworked to use new SQL API.


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

Branch: refs/heads/ignite-692
Commit: c06a4ae1aae210ab200767b05e4da78b518fa111
Parents: d20d29b
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Tue Apr 7 18:43:06 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Tue Apr 7 18:43:06 2015 +0700

----------------------------------------------------------------------
 .../processors/cache/GridCacheProcessor.java    |  15 ++-
 .../visor/query/VisorQueryCleanupTask.java      |   2 +-
 .../internal/visor/query/VisorQueryCursor.java  |  72 ++++++++++++
 .../visor/query/VisorQueryNextPageTask.java     |  45 +++++---
 .../visor/query/VisorQueryResultEx.java         |   6 +-
 .../internal/visor/query/VisorQueryTask.java    | 111 +++++++------------
 .../internal/visor/query/VisorQueryUtils.java   |  47 ++++----
 7 files changed, 178 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c06a4ae1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 5ca4bcd..65c6e54 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -2306,12 +2306,13 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
     /**
      * @param cacheName Cache name.
+     * @param userOnly If {@code true} then throws {@link IllegalStateException} in case
of system cache.
      * @param <K> type of keys.
      * @param <V> type of values.
      * @return Cache instance for given name.
      */
     @SuppressWarnings("unchecked")
-    public <K, V> IgniteCache<K, V> publicJCache(@Nullable String cacheName)
{
+    public <K, V> IgniteCache<K, V> privateJCache(@Nullable String cacheName,
boolean userOnly) {
         if (log.isDebugEnabled())
             log.debug("Getting public cache for name: " + cacheName);
 
@@ -2322,7 +2323,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
             DynamicCacheDescriptor desc = registeredCaches.get(masked);
 
-            if (desc != null && !desc.cacheType().userCache())
+            if (userOnly && desc != null && !desc.cacheType().userCache())
                 throw new IllegalStateException("Failed to get cache because it is a system
cache: " + cacheName);
 
             if (cache == null) {
@@ -2361,6 +2362,16 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @param cacheName Cache name.
+     * @param <K> type of keys.
+     * @param <V> type of values.
+     * @return Cache instance for given name.
+     */
+    public <K, V> IgniteCache<K, V> publicJCache(@Nullable String cacheName)
{
+        return privateJCache(cacheName, true);
+    }
+
+    /**
      * @param name Cache name.
      * @return Cache instance for given name.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c06a4ae1/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryCleanupTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryCleanupTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryCleanupTask.java
index 11e5c81..1386638 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryCleanupTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryCleanupTask.java
@@ -86,7 +86,7 @@ public class VisorQueryCleanupTask extends VisorMultiNodeTask<Map<UUID,
Collecti
 
         /** {@inheritDoc} */
         @Override protected Void run(Collection<String> qryIds) {
-            ConcurrentMap<String, VisorQueryTask.VisorFutureResultSetHolder> locMap
= ignite.cluster().nodeLocalMap();
+            ConcurrentMap<String, VisorQueryTask.VisorQueryCursorHolder> locMap = ignite.cluster().nodeLocalMap();
 
             for (String qryId : qryIds)
                 locMap.remove(qryId);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c06a4ae1/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryCursor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryCursor.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryCursor.java
new file mode 100644
index 0000000..981b297
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryCursor.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.visor.query;
+
+import org.apache.ignite.cache.query.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.query.*;
+
+import java.util.*;
+
+/**
+ * Wrapper for query cursor.
+ */
+public class VisorQueryCursor<T> implements Iterator<T>, AutoCloseable {
+    /** */
+    private final QueryCursor<T> cur;
+
+    /** */
+    private final Iterator<T> itr;
+
+    /**
+     * @param cur Cursor.
+     */
+    public VisorQueryCursor(QueryCursor<T> cur) {
+        this.cur = cur;
+
+        itr = cur.iterator();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasNext() {
+        return itr.hasNext();
+    }
+
+    /** {@inheritDoc} */
+    @Override public T next() {
+        return itr.next();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void remove() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close() throws Exception {
+        cur.close();
+    }
+
+    /**
+     * @return SQL Fields query result metadata.
+     */
+    @SuppressWarnings("unchecked")
+    public Collection<GridQueryFieldMetadata> fieldsMeta() {
+        return ((QueryCursorImpl)cur).fieldsMeta();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c06a4ae1/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryNextPageTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryNextPageTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryNextPageTask.java
index d922ad1..8d21fcf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryNextPageTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryNextPageTask.java
@@ -67,53 +67,68 @@ public class VisorQueryNextPageTask extends VisorOneNodeTask<IgniteBiTuple<Strin
             }
         }
 
-        /** Collect data from SQL query */
+        /**
+         * Collect data from SQL query.
+         *
+         * @param arg
+         * @return
+         * @throws IgniteCheckedException
+         */
         private VisorQueryResult nextSqlPage(IgniteBiTuple<String, Integer> arg) throws
IgniteCheckedException {
             long start = U.currentTimeMillis();
 
-            ConcurrentMap<String, VisorQueryTask.VisorFutureResultSetHolder<List<?>>>
storage =
+            ConcurrentMap<String, VisorQueryTask.VisorQueryCursorHolder> storage =
                 ignite.cluster().nodeLocalMap();
 
-            VisorQueryTask.VisorFutureResultSetHolder<List<?>> t = storage.get(arg.get1());
+            VisorQueryTask.VisorQueryCursorHolder t = storage.get(arg.get1());
 
             if (t == null)
                 throw new GridInternalException("SQL query results are expired.");
 
-            IgniteBiTuple<List<Object[]>, List<?>> nextRows = VisorQueryUtils.fetchSqlQueryRows(t.future(),
t.next(), arg.get2());
+            VisorQueryCursor cur = t.cursor();
+
+            List<Object[]> nextRows = VisorQueryUtils.fetchSqlQueryRows(cur, arg.get2());
 
-            boolean hasMore = nextRows.get2() != null;
+            boolean hasMore = cur.hasNext();
 
             if (hasMore)
-                storage.put(arg.get1(), new VisorQueryTask.VisorFutureResultSetHolder<>(t.future(),
nextRows.get2(), true));
+                storage.put(arg.get1(), new VisorQueryTask.VisorQueryCursorHolder(t.cursor(),
true));
             else
                 storage.remove(arg.get1());
 
-            return new VisorQueryResult(nextRows.get1(), hasMore, U.currentTimeMillis() -
start);
+            return new VisorQueryResult(nextRows, hasMore, U.currentTimeMillis() - start);
         }
 
-        /** Collect data from SCAN query */
+        /**
+         * Collect data from SCAN query
+         *
+         * @param arg
+         * @return
+         * @throws IgniteCheckedException
+         */
         private VisorQueryResult nextScanPage(IgniteBiTuple<String, Integer> arg) throws
IgniteCheckedException {
             long start = U.currentTimeMillis();
 
-            ConcurrentMap<String, VisorQueryTask.VisorFutureResultSetHolder<Map.Entry<Object,
Object>>> storage =
+            ConcurrentMap<String, VisorQueryTask.VisorQueryCursorHolder> storage =
                 ignite.cluster().nodeLocalMap();
 
-            VisorQueryTask.VisorFutureResultSetHolder<Map.Entry<Object, Object>>
t = storage.get(arg.get1());
+            VisorQueryTask.VisorQueryCursorHolder t = storage.get(arg.get1());
 
             if (t == null)
                 throw new GridInternalException("Scan query results are expired.");
 
-            IgniteBiTuple<List<Object[]>, Map.Entry<Object, Object>> rows
=
-                VisorQueryUtils.fetchScanQueryRows(t.future(), t.next(), arg.get2());
+            VisorQueryCursor cur = t.cursor();
+
+            List<Object[]> rows = VisorQueryUtils.fetchScanQueryRows(cur, arg.get2());
 
-            Boolean hasMore = rows.get2() != null;
+            Boolean hasMore = cur.hasNext();
 
             if (hasMore)
-                storage.put(arg.get1(), new VisorQueryTask.VisorFutureResultSetHolder<>(t.future(),
rows.get2(), true));
+                storage.put(arg.get1(), new VisorQueryTask.VisorQueryCursorHolder(cur, true));
             else
                 storage.remove(arg.get1());
 
-            return new VisorQueryResult(rows.get1(), hasMore, U.currentTimeMillis() - start);
+            return new VisorQueryResult(rows, hasMore, U.currentTimeMillis() - start);
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c06a4ae1/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryResultEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryResultEx.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryResultEx.java
index ace9929..35ed790 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryResultEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryResultEx.java
@@ -35,7 +35,7 @@ public class VisorQueryResultEx extends VisorQueryResult {
     private final String qryId;
 
     /** Query columns descriptors. */
-    private final VisorQueryField[] colNames;
+    private final Collection<VisorQueryField> colNames;
 
     /**
      * @param resNodeId Node where query executed.
@@ -48,7 +48,7 @@ public class VisorQueryResultEx extends VisorQueryResult {
     public VisorQueryResultEx(
         UUID resNodeId,
         String qryId,
-        VisorQueryField[] colNames,
+        Collection<VisorQueryField> colNames,
         List<Object[]> rows,
         Boolean hasMore,
         long duration
@@ -77,7 +77,7 @@ public class VisorQueryResultEx extends VisorQueryResult {
     /**
      * @return Columns names.
      */
-    public VisorQueryField[] columnNames() {
+    public Collection<VisorQueryField> columnNames() {
         return colNames;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c06a4ae1/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTask.java
index 5744f62..ae63e3c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryTask.java
@@ -18,8 +18,8 @@
 package org.apache.ignite.internal.visor.query;
 
 import org.apache.ignite.*;
+import org.apache.ignite.cache.query.*;
 import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.processors.task.*;
 import org.apache.ignite.internal.processors.timeout.*;
@@ -27,13 +27,13 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.internal.visor.*;
 import org.apache.ignite.lang.*;
 
+import javax.cache.*;
 import java.io.*;
 import java.sql.*;
 import java.util.*;
 import java.util.concurrent.*;
 
 import static org.apache.ignite.internal.visor.query.VisorQueryUtils.*;
-import static org.apache.ignite.internal.visor.util.VisorTaskUtils.*;
 
 /**
  * Task for execute SCAN or SQL query and get first page of results.
@@ -115,42 +115,30 @@ public class VisorQueryTask extends VisorOneNodeTask<VisorQueryTask.VisorQueryAr
      * ResultSet future holder.
      */
     @SuppressWarnings("PublicInnerClass")
-    public static class VisorFutureResultSetHolder<R> implements Serializable {
+    public static class VisorQueryCursorHolder implements Serializable {
         /** */
         private static final long serialVersionUID = 0L;
 
-        /** Future with query results. */
-        private final CacheQueryFuture<R> fut;
-
-        /** Next record from future. */
-        private final R next;
+        /** Query cursor. */
+        private final VisorQueryCursor cur;
 
         /** Flag indicating that this future was read from last check. */
-        private Boolean accessed;
+        private boolean accessed;
 
         /**
-         * @param fut Future.
-         * @param next Next value.
+         * @param cur Future.
          * @param accessed {@code true} if query was accessed before remove timeout expired.
          */
-        public VisorFutureResultSetHolder(CacheQueryFuture<R> fut, R next, Boolean
accessed) {
-            this.fut = fut;
-            this.next = next;
+        public VisorQueryCursorHolder(VisorQueryCursor cur, boolean accessed) {
+            this.cur = cur;
             this.accessed = accessed;
         }
 
         /**
-         * @return Future with query results.
+         * @return Query cursor.
          */
-        public CacheQueryFuture<R> future() {
-            return fut;
-        }
-
-        /**
-         * @return Next record from future.
-         */
-        public R next() {
-            return next;
+        public VisorQueryCursor cursor() {
+            return cur;
         }
 
         /**
@@ -194,78 +182,59 @@ public class VisorQueryTask extends VisorOneNodeTask<VisorQueryTask.VisorQueryAr
                 String qryId = (scan ? SCAN_QRY_NAME : SQL_QRY_NAME) + "-" +
                     UUID.randomUUID();
 
-                GridCache<Object, Object> c = ignite.cachex(arg.cacheName());
-
-                if (c == null)
-                    return new IgniteBiTuple<>(new IgniteCheckedException("Cache not
found: " +
-                        escapeName(arg.cacheName())), null);
+                GridCacheProcessor cacheProcessor = ignite.context().cache();
 
-                CacheProjection<Object, Object> cp = c.keepPortable();
+                IgniteCache<Object, Object> c = cacheProcessor.privateJCache(arg.cacheName(),
false);
 
                 if (scan) {
-                    CacheQueryFuture<Map.Entry<Object, Object>> fut = cp.queries().createScanQuery(null)
-                        .pageSize(arg.pageSize())
-                        .projection(ignite.cluster().forNodeIds(arg.proj()))
-                        .execute();
+                    ScanQuery<Object, Object> qry = new ScanQuery<>(null);
+                    qry.setPageSize(arg.pageSize());
 
                     long start = U.currentTimeMillis();
 
-                    IgniteBiTuple<List<Object[]>, Map.Entry<Object, Object>>
rows =
-                        fetchScanQueryRows(fut, null, arg.pageSize());
-
-                    long fetchDuration = U.currentTimeMillis() - start;
+                    VisorQueryCursor<Cache.Entry<Object, Object>> cur = new VisorQueryCursor<>(c.query(qry));
 
-                    long duration = fut.duration() + fetchDuration; // Scan duration + fetch
duration.
+                    List<Object[]> rows = fetchScanQueryRows(cur, arg.pageSize());
 
-                    Map.Entry<Object, Object> next = rows.get2();
+                    long duration = U.currentTimeMillis() - start; // Scan duration + fetch
duration.
 
-                    ignite.cluster().<String, VisorFutureResultSetHolder>nodeLocalMap().put(qryId,
-                        new VisorFutureResultSetHolder<>(fut, next, false));
+                    ignite.cluster().<String, VisorQueryCursorHolder>nodeLocalMap().put(qryId,
+                        new VisorQueryCursorHolder(cur, false));
 
                     scheduleResultSetHolderRemoval(qryId);
 
                     return new IgniteBiTuple<>(null, new VisorQueryResultEx(ignite.localNode().id(),
qryId,
-                        SCAN_COL_NAMES, rows.get1(), next != null, duration));
+                        SCAN_COL_NAMES, rows, cur.hasNext(), duration));
                 }
                 else {
-                    CacheQueryFuture<List<?>> fut = ((GridCacheQueriesEx<?,
?>)cp.queries())
-                        .createSqlFieldsQuery(arg.queryTxt(), true)
-                        .pageSize(arg.pageSize())
-                        .projection(ignite.cluster().forNodeIds(arg.proj()))
-                        .execute();
+                    SqlFieldsQuery qry = new SqlFieldsQuery(arg.queryTxt());
+                    qry.setPageSize(arg.pageSize());
 
-                    List<Object> firstRow = (List<Object>)fut.next();
+                    long start = U.currentTimeMillis();
+
+                    VisorQueryCursor<List<?>> cur = new VisorQueryCursor<>(c.query(qry));
 
-                    List<GridQueryFieldMetadata> meta = ((GridCacheQueryMetadataAware)fut).metadata().get();
+                    Collection<GridQueryFieldMetadata> meta = cur.fieldsMeta();
 
                     if (meta == null)
                         return new IgniteBiTuple<Exception, VisorQueryResultEx>(
                             new SQLException("Fail to execute query. No metadata available."),
null);
                     else {
-                        VisorQueryField[] names = new VisorQueryField[meta.size()];
-
-                        for (int i = 0; i < meta.size(); i++) {
-                            GridQueryFieldMetadata col = meta.get(i);
-
-                            names[i] = new VisorQueryField(col.typeName(), col.fieldName());
-                        }
-
-                        long start = U.currentTimeMillis();
+                        List<VisorQueryField> names = new ArrayList<>(meta.size());
 
-                        IgniteBiTuple<List<Object[]>, List<?>> rows =
-                            fetchSqlQueryRows(fut, firstRow, arg.pageSize());
+                        for (GridQueryFieldMetadata col : meta)
+                            names.add(new VisorQueryField(col.typeName(), col.fieldName()));
 
-                        long fetchDuration = U.currentTimeMillis() - start;
+                        List<Object[]> rows = fetchSqlQueryRows(cur, arg.pageSize());
 
-                        long duration = fut.duration() + fetchDuration; // Query duration
+ fetch duration.
+                        long duration = U.currentTimeMillis() - start; // Query duration
+ fetch duration.
 
-                        ignite.cluster().<String, VisorFutureResultSetHolder>nodeLocalMap().put(qryId,
-                            new VisorFutureResultSetHolder<>(fut, rows.get2(), false));
+                        ignite.cluster().<String, VisorQueryCursorHolder>nodeLocalMap().put(qryId,
new VisorQueryCursorHolder(cur, false));
 
                         scheduleResultSetHolderRemoval(qryId);
 
                         return new IgniteBiTuple<>(null, new VisorQueryResultEx(ignite.localNode().id(),
qryId,
-                            names, rows.get1(), rows.get2() != null, duration));
+                            names, rows, cur.hasNext(), duration));
                     }
                 }
             }
@@ -280,14 +249,14 @@ public class VisorQueryTask extends VisorOneNodeTask<VisorQueryTask.VisorQueryAr
         private void scheduleResultSetHolderRemoval(final String id) {
             ignite.context().timeout().addTimeoutObject(new GridTimeoutObjectAdapter(RMV_DELAY)
{
                 @Override public void onTimeout() {
-                    ConcurrentMap<String, VisorFutureResultSetHolder> storage = ignite.cluster().nodeLocalMap();
+                    ConcurrentMap<String, VisorQueryCursorHolder> storage = ignite.cluster().nodeLocalMap();
 
-                    VisorFutureResultSetHolder<?> t = storage.get(id);
+                    VisorQueryCursorHolder holder = storage.get(id);
 
-                    if (t != null) {
+                    if (holder != null) {
                         // If future was accessed since last scheduling,  set access flag
to false and reschedule.
-                        if (t.accessed()) {
-                            t.accessed(false);
+                        if (holder.accessed()) {
+                            holder.accessed(false);
 
                             scheduleResultSetHolderRemoval(id);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c06a4ae1/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
index ff847d2..f8f795d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
@@ -17,11 +17,9 @@
 
 package org.apache.ignite.internal.visor.query;
 
-import org.apache.ignite.*;
-import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.util.*;
-import org.apache.ignite.lang.*;
 
+import javax.cache.*;
 import java.math.*;
 import java.net.*;
 import java.util.*;
@@ -40,10 +38,10 @@ public class VisorQueryUtils {
     public static final String SCAN_QRY_NAME = "VISOR_SCAN_QUERY";
 
     /** Columns for SCAN queries. */
-    public static final VisorQueryField[] SCAN_COL_NAMES = new VisorQueryField[] {
+    public static final Collection<VisorQueryField> SCAN_COL_NAMES = Arrays.asList(
         new VisorQueryField("", "Key Class"), new VisorQueryField("", "Key"),
         new VisorQueryField("", "Value Class"), new VisorQueryField("", "Value")
-    };
+    );
 
     /**
      * @param o - Object.
@@ -114,32 +112,27 @@ public class VisorQueryUtils {
     /**
      * Fetch rows from SCAN query future.
      *
-     * @param fut Query future to fetch rows from.
-     * @param savedNext Last processed element from future.
+     * @param cur Query future to fetch rows from.
      * @param pageSize Number of rows to fetch.
-     * @return Fetched rows and last processed element.
+     * @return Fetched rows.
      */
-    public static IgniteBiTuple<List<Object[]>, Map.Entry<Object, Object>>
fetchScanQueryRows(
-        CacheQueryFuture<Map.Entry<Object, Object>> fut, Map.Entry<Object,
Object> savedNext, int pageSize)
-        throws IgniteCheckedException {
+    public static List<Object[]> fetchScanQueryRows(VisorQueryCursor<Cache.Entry<Object,
Object>> cur, int pageSize) {
         List<Object[]> rows = new ArrayList<>();
 
         int cnt = 0;
 
-        Map.Entry<Object, Object> next = savedNext != null ? savedNext : fut.next();
+        while (cur.hasNext() && cnt < pageSize) {
+            Cache.Entry<Object, Object> next = cur.next();
 
-        while (next != null && cnt < pageSize) {
             Object k = next.getKey();
             Object v = next.getValue();
 
             rows.add(new Object[] {typeOf(k), valueOf(k), typeOf(v), valueOf(v)});
 
             cnt++;
-
-            next = fut.next();
         }
 
-        return new IgniteBiTuple<>(rows, next);
+        return rows;
     }
 
     /**
@@ -165,23 +158,23 @@ public class VisorQueryUtils {
     /**
      * Collects rows from sql query future, first time creates meta and column names arrays.
      *
-     * @param fut Query future to fetch rows from.
-     * @param savedNext Last processed element from future.
+     * @param cur Query cursor to fetch rows from.
      * @param pageSize Number of rows to fetch.
-     * @return Fetched rows and last processed element.
+     * @return Fetched rows.
      */
-    public static IgniteBiTuple<List<Object[]>, List<?>> fetchSqlQueryRows(CacheQueryFuture<List<?>>
fut,
-        List<?> savedNext, int pageSize) throws IgniteCheckedException {
+    public static List<Object[]> fetchSqlQueryRows(VisorQueryCursor<List<?>>
cur, int pageSize) {
         List<Object[]> rows = new ArrayList<>();
 
         int cnt = 0;
 
-        List<?> next = savedNext != null ? savedNext : fut.next();
+        while (cur.hasNext() && cnt < pageSize) {
+            List<?> next = cur.next();
+
+            int sz = next.size();
 
-        while (next != null && cnt < pageSize) {
-            Object[] row = new Object[next.size()];
+            Object[] row = new Object[sz];
 
-            for (int i = 0; i < next.size(); i++) {
+            for (int i = 0; i < sz; i++) {
                 Object o = next.get(i);
 
                 if (o == null)
@@ -195,10 +188,8 @@ public class VisorQueryUtils {
             rows.add(row);
 
             cnt++;
-
-            next = fut.next();
         }
 
-        return new IgniteBiTuple<List<Object[]>, List<?>>(rows, next);
+        return rows;
     }
 }


Mime
View raw message