ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsetrak...@apache.org
Subject [1/2] incubator-ignite git commit: # ignite-45 - demo fixes.
Date Tue, 24 Mar 2015 01:59:09 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-45 a1951057c -> 4f3b12854


# ignite-45 - demo fixes.


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

Branch: refs/heads/ignite-45
Commit: 5d489ff6aa57fbe1b984dc50f10134b1048f81ab
Parents: a97444a
Author: Dmitiry Setrakyan <dsetrakyan@gridgain.com>
Authored: Mon Mar 23 18:57:45 2015 -0700
Committer: Dmitiry Setrakyan <dsetrakyan@gridgain.com>
Committed: Mon Mar 23 18:57:45 2015 -0700

----------------------------------------------------------------------
 examples/schema-import/bin/db-init.sql          | 14 ++--
 .../java/org/apache/ignite/schema/Demo.java     | 79 ++++++++++++++------
 .../java/org/apache/ignite/schema/Person.java   | 16 +++-
 3 files changed, 78 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d489ff6/examples/schema-import/bin/db-init.sql
----------------------------------------------------------------------
diff --git a/examples/schema-import/bin/db-init.sql b/examples/schema-import/bin/db-init.sql
index 52fcb27..f450af7 100644
--- a/examples/schema-import/bin/db-init.sql
+++ b/examples/schema-import/bin/db-init.sql
@@ -1,10 +1,10 @@
 -- Script of database initialization for Schema Import Demo.
 drop table PERSON;
-create table PERSON(id integer not null, first_name varchar(50), last_name varchar(50), PRIMARY
KEY(id));
+create table PERSON(id integer not null, first_name varchar(50), last_name varchar(50), salary
double not null, PRIMARY KEY(id));
 
-insert into PERSON(id, first_name, last_name) values(1, 'Johannes', 'Kepler');
-insert into PERSON(id, first_name, last_name) values(2, 'Galileo', 'Galilei');
-insert into PERSON(id, first_name, last_name) values(3, 'Henry', 'More');
-insert into PERSON(id, first_name, last_name) values(4, 'Polish', 'Brethren');
-insert into PERSON(id, first_name, last_name) values(5, 'Robert', 'Boyle');
-insert into PERSON(id, first_name, last_name) values(6, 'Isaac', 'Newton');
+insert into PERSON(id, first_name, last_name) values(1, 'Johannes', 'Kepler', 1000);
+insert into PERSON(id, first_name, last_name) values(2, 'Galileo', 'Galilei', 2000);
+insert into PERSON(id, first_name, last_name) values(3, 'Henry', 'More', 3000);
+insert into PERSON(id, first_name, last_name) values(4, 'Polish', 'Brethren', 4000);
+insert into PERSON(id, first_name, last_name) values(5, 'Robert', 'Boyle', 5000);
+insert into PERSON(id, first_name, last_name) values(6, 'Isaac', 'Newton', 6000);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d489ff6/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java
----------------------------------------------------------------------
diff --git a/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java b/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java
index d5356f1..bd76166 100644
--- a/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java
+++ b/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java
@@ -20,6 +20,7 @@ package org.apache.ignite.schema;
 import org.apache.ignite.*;
 import org.apache.ignite.cache.store.jdbc.*;
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.transactions.*;
 
 import javax.cache.*;
 
@@ -55,37 +56,71 @@ public class Demo {
         try (Ignite ignite = Ignition.start(cfg)) {
             IgniteCache<PersonKey, Person> cache = ignite.jcache(CACHE_NAME);
 
-            // Demo for load cache with custom SQL.
-            cache.loadCache(null, "org.apache.ignite.schema.PersonKey",
-                "select * from PERSON where ID <= 3");
+            // Preload cache from database.
+            preload(cache);
 
-            for (Cache.Entry<PersonKey, Person> person : cache)
-                System.out.println(">>> Loaded Person: " + person);
+            // Read-through from database
+            // and store in cache.
+            readThrough(cache);
+
+            // Perform transaction and
+            // write-through to database.
+            transaction(ignite, cache);
         }
     }
 
-    /** Demonstrates cache preload from database.  */
-    private static void preload() {
-        // TODO
-    }
+    /**
+     * Demonstrates cache preload from database.
+     */
+    private static void preload(IgniteCache<PersonKey, Person> cache) {
+        System.out.println();
+        System.out.println(">>> Loading entries from database.");
 
-    /** Demonstrates cache wright through to database.  */
-    private static void writeThrough() {
-        // TODO
-    }
+        // Demo for load cache with custom SQL.
+        cache.loadCache(null, "org.apache.ignite.schema.PersonKey",
+            "select * from PERSON where ID <= 3");
 
-    /** Demonstrates cache read through from database.  */
-    private static void readThrough() {
-        // TODO
+        for (Cache.Entry<PersonKey, Person> person : cache)
+            System.out.println(">>> Loaded Person: " + person);
     }
 
-    /** Demonstrates cache remove from database.  */
-    private static void remove() {
-        // TODO
+    /**
+     * Demonstrates cache read through from database.
+     */
+    private static void readThrough(IgniteCache<PersonKey, Person> cache) {
+        PersonKey key = new PersonKey(4);
+
+        // Check that person with ID=4 is not in cache.
+        Person p = cache.localPeek(key);
+
+        assert p == null;
+
+        // Read-through form database.
+        p = cache.get(new PersonKey(4));
+
+        System.out.println("Loaded person from database: " + p);
     }
 
-    /** Demonstrates cache transaction from database.  */
-    private static void transaction() {
-        // TODO
+    /**
+     * Demonstrates cache transaction joining database transaction.
+     */
+    private static void transaction(Ignite ignite, IgniteCache<PersonKey, Person> cache)
{
+        PersonKey key = new PersonKey(5);
+
+        try (Transaction tx = ignite.transactions().txStart()) {
+            // Read-through from database.
+            Person p = cache.get(key);
+
+            double salary = p.getSalary();
+
+            // Raise salary by 20%.
+            p.setSalary(salary * 1.2);
+
+            // Write-through to database
+            // and store in cache.
+            cache.put(key, p);
+
+            tx.commit();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d489ff6/examples/schema-import/src/main/java/org/apache/ignite/schema/Person.java
----------------------------------------------------------------------
diff --git a/examples/schema-import/src/main/java/org/apache/ignite/schema/Person.java b/examples/schema-import/src/main/java/org/apache/ignite/schema/Person.java
index 6b2b312..78219b4 100644
--- a/examples/schema-import/src/main/java/org/apache/ignite/schema/Person.java
+++ b/examples/schema-import/src/main/java/org/apache/ignite/schema/Person.java
@@ -17,8 +17,6 @@
 
 package org.apache.ignite.schema;
 
-import java.io.*;
-
 /**
  * Person stub.  Will be generated by Ignite Schema Import Utility.
  */
@@ -29,5 +27,19 @@ public class Person {
     public Person() {
         throw new IllegalStateException("Person should be generated by Ignite Schema Import
Utility");
     }
+
+    /**
+     * @return Salary.
+     */
+    public double getSalary() {
+        throw new IllegalStateException("Person should be generated by Ignite Schema Import
Utility");
+    }
+
+    /**
+     * @param salary Salary.
+     */
+    public void setSalary(double salary) {
+        throw new IllegalStateException("Person should be generated by Ignite Schema Import
Utility");
+    }
 }
 


Mime
View raw message