ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject ignite git commit: IGNITE-2041 Fixed JDBC cache store example. Reworked from deprected code to new API.
Date Wed, 02 Dec 2015 16:06:43 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2041 [created] 85e73f049


IGNITE-2041 Fixed JDBC cache store example. Reworked from deprected code to new API.


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

Branch: refs/heads/ignite-2041
Commit: 85e73f049290031e69dba79f1309aa757124bca4
Parents: 3ac1504
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Wed Dec 2 23:06:29 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Wed Dec 2 23:06:29 2015 +0700

----------------------------------------------------------------------
 examples/config/example-default.xml             |  7 +++
 .../store/auto/CacheAutoStoreExample.java       |  5 +-
 .../auto/CacheAutoStoreLoadDataExample.java     |  5 +-
 .../datagrid/store/auto/CacheConfig.java        | 58 ++++++++++----------
 4 files changed, 38 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/85e73f04/examples/config/example-default.xml
----------------------------------------------------------------------
diff --git a/examples/config/example-default.xml b/examples/config/example-default.xml
index e6c359d..6bd6f16 100644
--- a/examples/config/example-default.xml
+++ b/examples/config/example-default.xml
@@ -28,6 +28,13 @@
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/util
         http://www.springframework.org/schema/util/spring-util.xsd">
+
+    <!-- Datasource for sample in-memory H2 database. -->
+    <bean id="h2-example-db" class="org.h2.jdbcx.JdbcDataSource">
+        <property name="URL" value="jdbc:h2:tcp://localhost/mem:ExampleDb" />
+        <property name="user" value="sa" />
+    </bean>
+
     <bean abstract="true" id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
         <!-- Set to true to enable distributed class loading for examples, default is
false. -->
         <property name="peerClassLoadingEnabled" value="true"/>

http://git-wip-us.apache.org/repos/asf/ignite/blob/85e73f04/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
index 37a31d7..babfde7 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
@@ -46,9 +46,6 @@ import org.apache.ignite.transactions.Transaction;
  * start node with {@code examples/config/example-ignite.xml} configuration.
  */
 public class CacheAutoStoreExample {
-    /** Cache name. */
-    public static final String CACHE_NAME = CacheAutoStoreLoadDataExample.class.getSimpleName();
-
     /** Global person ID to use across entire example. */
     private static final Long id = Math.abs(UUID.randomUUID().getLeastSignificantBits());
 
@@ -64,7 +61,7 @@ public class CacheAutoStoreExample {
             System.out.println();
             System.out.println(">>> Cache auto store example started.");
 
-            try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(CacheConfig.jdbcPojoStoreCache(CACHE_NAME)))
{
+            try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(CacheConfig.jdbcPojoStoreCache()))
{
                 try (Transaction tx = ignite.transactions().txStart()) {
                     Person val = cache.get(id);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/85e73f04/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
index 63a8c6f..4993763 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
@@ -46,9 +46,6 @@ import org.apache.ignite.examples.model.Person;
  * start node with {@code examples/config/example-ignite.xml} configuration.
  */
 public class CacheAutoStoreLoadDataExample {
-    /** Cache name. */
-    public static final String CACHE_NAME = CacheAutoStoreLoadDataExample.class.getSimpleName();
-
     /** Heap size required to run this example. */
     public static final int MIN_MEMORY = 1024 * 1024 * 1024;
 
@@ -65,7 +62,7 @@ public class CacheAutoStoreLoadDataExample {
             System.out.println();
             System.out.println(">>> Cache auto store load data example started.");
 
-            CacheConfiguration<Long, Person> cacheCfg = CacheConfig.jdbcPojoStoreCache(CACHE_NAME);
+            CacheConfiguration<Long, Person> cacheCfg = CacheConfig.jdbcPojoStoreCache();
 
             try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheCfg))
{
                 // Load cache on all data nodes with custom SQL statement.

http://git-wip-us.apache.org/repos/asf/ignite/blob/85e73f04/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
index 3b38aeb..654aec9 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
@@ -18,16 +18,13 @@
 package org.apache.ignite.examples.datagrid.store.auto;
 
 import java.sql.Types;
-import java.util.Arrays;
-import java.util.Collections;
-import javax.cache.configuration.Factory;
-import org.apache.ignite.cache.CacheTypeFieldMetadata;
-import org.apache.ignite.cache.CacheTypeMetadata;
-import org.apache.ignite.cache.store.CacheStore;
 import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore;
+import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory;
+import org.apache.ignite.cache.store.jdbc.JdbcType;
+import org.apache.ignite.cache.store.jdbc.JdbcTypeField;
+import org.apache.ignite.cache.store.jdbc.dialect.H2Dialect;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.examples.model.Person;
-import org.h2.jdbcx.JdbcConnectionPool;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
 
@@ -35,41 +32,44 @@ import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
  * Predefined configuration for examples with {@link CacheJdbcPojoStore}.
  */
 public class CacheConfig {
+    /** Cache name. */
+    public static final String CACHE_NAME = "CacheAutoStore";
+
     /**
      * Configure cache with store.
      */
-    public static CacheConfiguration<Long, Person> jdbcPojoStoreCache(String name)
{
-        CacheConfiguration<Long, Person> cfg = new CacheConfiguration<>(name);
+    public static CacheConfiguration<Long, Person> jdbcPojoStoreCache() {
+        CacheJdbcPojoStoreFactory<Long, Person> storeFactory = new CacheJdbcPojoStoreFactory<>();
 
-        // Set atomicity as transaction, since we are showing transactions in the example.
-        cfg.setAtomicityMode(TRANSACTIONAL);
+        storeFactory.setDataSourceBean("h2-example-db");
+        storeFactory.setDialect(new H2Dialect());
 
-        cfg.setCacheStoreFactory(new Factory<CacheStore<? super Long, ? super Person>>()
{
-            @Override public CacheStore<? super Long, ? super Person> create() {
-                CacheJdbcPojoStore<Long, Person> store = new CacheJdbcPojoStore<>();
+        JdbcType jdbcType = new JdbcType();
 
-                store.setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb",
"sa", ""));
+        jdbcType.setCacheName(CACHE_NAME);
+        jdbcType.setDatabaseSchema("PUBLIC");
+        jdbcType.setDatabaseTable("PERSON");
 
-                return store;
-            }
-        });
+        jdbcType.setKeyType("java.lang.Long");
+        jdbcType.setValueType("org.apache.ignite.examples.model.Person");
 
-        CacheTypeMetadata meta = new CacheTypeMetadata();
+        jdbcType.setKeyFields(new JdbcTypeField(Types.BIGINT, "ID", Long.class, "id"));
+        jdbcType.setValueFields(
+            new JdbcTypeField(Types.BIGINT, "ID", long.class, "id"),
+            new JdbcTypeField(Types.VARCHAR, "FIRST_NAME", String.class, "firstName"),
+            new JdbcTypeField(Types.VARCHAR, "LAST_NAME", String.class, "lastName")
+        );
 
-        meta.setDatabaseTable("PERSON");
+        storeFactory.setTypes(jdbcType);
 
-        meta.setKeyType("java.lang.Long");
-        meta.setValueType("org.apache.ignite.examples.model.Person");
+        CacheConfiguration<Long, Person> cfg = new CacheConfiguration<>(CACHE_NAME);
 
-        meta.setKeyFields(Collections.singletonList(new CacheTypeFieldMetadata("ID", Types.BIGINT,
"id", Long.class)));
+        cfg.setCacheStoreFactory(storeFactory);
 
-        meta.setValueFields(Arrays.asList(
-            new CacheTypeFieldMetadata("ID", Types.BIGINT, "id", long.class),
-            new CacheTypeFieldMetadata("FIRST_NAME", Types.VARCHAR, "firstName", String.class),
-            new CacheTypeFieldMetadata("LAST_NAME", Types.VARCHAR, "lastName", String.class)
-        ));
+        // Set atomicity as transaction, since we are showing transactions in the example.
+        cfg.setAtomicityMode(TRANSACTIONAL);
 
-        cfg.setTypeMetadata(Collections.singletonList(meta));
+        cfg.setKeepBinaryInStore(true);
 
         cfg.setWriteBehindEnabled(true);
 


Mime
View raw message