ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [11/15] ignite git commit: fixed https://issues.apache.org/jira/browse/IGNITE-2175
Date Thu, 17 Dec 2015 14:00:10 GMT
fixed https://issues.apache.org/jira/browse/IGNITE-2175


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

Branch: refs/heads/ignite-843-rc2
Commit: 3223b05c082732ad77462f00cb09d24af2d768f7
Parents: c1e2926
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Thu Dec 17 15:07:21 2015 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Thu Dec 17 15:07:21 2015 +0300

----------------------------------------------------------------------
 .../examples/datagrid/CacheQueryExample.java    | 11 +++---
 .../streaming/StreamVisitorExample.java         | 40 +++++++++++++++-----
 2 files changed, 36 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3223b05c/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
index 2d86cde..ace7395 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
@@ -22,6 +22,7 @@ import javax.cache.Cache;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.affinity.AffinityKey;
 import org.apache.ignite.cache.query.QueryCursor;
@@ -126,12 +127,12 @@ public class CacheQueryExample {
      * Example for scan query based on a predicate.
      */
     private static void scanQuery() {
-        IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
+        IgniteCache<BinaryObject, BinaryObject> cache = Ignition.ignite().cache(PERSON_CACHE).withKeepBinary();
 
-        ScanQuery<AffinityKey<Long>, Person> scan = new ScanQuery<>(
-            new IgniteBiPredicate<AffinityKey<Long>, Person>() {
-                @Override public boolean apply(AffinityKey<Long> key, Person person)
{
-                    return person.salary <= 1000;
+        ScanQuery<BinaryObject, BinaryObject> scan = new ScanQuery<>(
+            new IgniteBiPredicate<BinaryObject, BinaryObject>() {
+                @Override public boolean apply(BinaryObject key, BinaryObject person) {
+                    return person.<Double>field("salary") <= 1000;
                 }
             }
         );

http://git-wip-us.apache.org/repos/asf/ignite/blob/3223b05c/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
index f2e1e9f..819cfea 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
@@ -25,6 +25,8 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteDataStreamer;
 import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.configuration.CacheConfiguration;
@@ -75,21 +77,39 @@ public class StreamVisitorExample {
                     // Instead we update the instruments in the 'instCache'.
                     // Since both, 'instCache' and 'mktCache' use the same key, updates are
collocated.
                     mktStmr.receiver(new StreamVisitor<String, Double>() {
-                        @Override
-                        public void apply(IgniteCache<String, Double> cache, Map.Entry<String,
Double> e) {
+                        @Override public void apply(IgniteCache<String, Double> cache,
Map.Entry<String, Double> e) {
                             String symbol = e.getKey();
                             Double tick = e.getValue();
 
-                            Instrument inst = instCache.get(symbol);
+                            IgniteCache<String, BinaryObject> binInstCache = ignite.cache("instCache").withKeepBinary();
 
-                            if (inst == null)
-                                inst = new Instrument(symbol);
+                            BinaryObject inst = binInstCache.get(symbol);
 
-                            // Don't populate market cache, as we don't use it for querying.
-                            // Update cached instrument based on the latest market tick.
-                            inst.update(tick);
+                            BinaryObjectBuilder instBuilder;
 
-                            instCache.put(symbol, inst);
+                            if (inst == null) {
+                                instBuilder = ignite.binary().builder("Instrument");
+
+                                // Constructor logic.
+                                instBuilder.setField(
+                                    "symbol",
+                                    symbol);
+                            }
+                            else
+                                instBuilder = inst.toBuilder();
+
+                            // Instrument.update() logic.
+                            Double open = instBuilder.<Double>getField("open");
+
+                            if (open == null || open == 0)
+                                instBuilder.setField("open", tick);
+
+                            instBuilder.setField("latest", tick);
+
+                            // Build instrument object.
+                            inst = instBuilder.build();
+
+                            binInstCache.put(symbol, inst);
                         }
                     });
 
@@ -168,4 +188,4 @@ public class StreamVisitorExample {
             this.latest = price;
         }
     }
-}
\ No newline at end of file
+}


Mime
View raw message