# ignite-57

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

Branch: refs/heads/ignite-sql-tests
Commit: 7d9dbf72d18fbebe885529accb3d02e16453085e
Parents: 724a3f1
Author: sboikov <sboi...@gridgain.com>
Authored: Fri Feb 6 16:55:52 2015 +0300
Committer: sboikov <sboi...@gridgain.com>
Committed: Fri Feb 6 16:55:52 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      | 102 ++++++++++++++-----
 .../processors/cache/IgniteCacheProxy.java      |  13 ++-
 2 files changed, 85 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7d9dbf72/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 68b846b..0f2158e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -4058,6 +4058,31 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         return e == null || e.obsolete() ? null : e.wrap(true);
     }
 
+    /**
+     * @return Random entry.
+     * @throws IgniteCheckedException If failed.
+     */
+    public Cache.Entry<K, V> randomCacheEntry() throws IgniteCheckedException {
+        boolean keepPortable = ctx.keepPortable();
+
+        while (true) {
+            GridCacheMapEntry<K, V> e = map.randomEntry();
+
+            if (e == null)
+                return null;
+
+            try {
+                Cache.Entry<K, V> entry = toCacheEntry(e, !keepPortable);
+
+                if (entry != null)
+                    return entry;
+            }
+            catch (GridCacheEntryRemovedException ignore) {
+                // No-op.
+            }
+        }
+    }
+
     /** {@inheritDoc} */
     @Override public int size(CachePeekMode[] peekModes) throws 
IgniteCheckedException {
         if (isLocal())
@@ -5360,32 +5385,10 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                     GridCacheEntryEx<K, V> entry = it.next();
 
                     try {
-                        V val = entry.innerGet(
-                            null,
-                            false,
-                            false,
-                            false,
-                            true,
-                            false,
-                            false,
-                            false,
-                            null,
-                            null,
-                            null,
-                            null,
-                            null);
-
-                        if (val == null)
-                            continue;
+                        next = toCacheEntry(entry, deserializePortable);
 
-                        K key = entry.key();
-
-                        if (deserializePortable && ctx.portableEnabled()) {
-                            key = (K)ctx.unwrapPortableIfNeeded(key, true);
-                            val = (V)ctx.unwrapPortableIfNeeded(val, true);
-                        }
-
-                        next = new CacheEntryImpl<>(key, val);
+                        if (next == null)
+                            continue;
 
                         break;
                     }
@@ -5395,15 +5398,58 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                     catch (GridCacheEntryRemovedException ignore) {
                         // No-op.
                     }
-                    catch (GridCacheFilterFailedException ignore) {
-                        assert false;
-                    }
                 }
             }
         };
     }
 
     /**
+     * @param entry Internal entry.
+     * @param deserializePortable Deserialize portable flag.
+     * @return Public API entry.
+     * @throws IgniteCheckedException If failed.
+     * @throws GridCacheEntryRemovedException If entry removed.
+     */
+    @Nullable private Cache.Entry<K, V> toCacheEntry(GridCacheEntryEx<K, V> 
entry,
+        boolean deserializePortable)
+        throws IgniteCheckedException, GridCacheEntryRemovedException
+    {
+        try {
+            V val = entry.innerGet(
+                null,
+                false,
+                false,
+                false,
+                true,
+                false,
+                false,
+                false,
+                null,
+                null,
+                null,
+                null,
+                null);
+
+            if (val == null)
+                return null;
+
+            K key = entry.key();
+
+            if (deserializePortable && ctx.portableEnabled()) {
+                key = (K)ctx.unwrapPortableIfNeeded(key, true);
+                val = (V)ctx.unwrapPortableIfNeeded(val, true);
+            }
+
+            return new CacheEntryImpl<>(key, val);
+        }
+        catch (GridCacheFilterFailedException ignore) {
+            assert false;
+
+            return null;
+        }
+    }
+
+    /**
      *
      */
     private static class PeekModes {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7d9dbf72/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 42c0705..c6166af 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -131,8 +131,17 @@ public class IgniteCacheProxy<K, V> extends 
IgniteAsyncSupportAdapter<IgniteCach
 
     /** {@inheritDoc} */
     @Nullable @Override public Entry<K, V> randomEntry() {
-        // TODO IGNITE-1.
-        throw new UnsupportedOperationException();
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
+        try {
+            return ctx.<K, V>cache().randomCacheEntry();
+        }
+        catch (IgniteCheckedException e) {
+            throw cacheException(e);
+        }
+        finally {
+            gate.leave(prev);
+        }
     }
 
     /** {@inheritDoc} */

Reply via email to