You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/12/09 12:23:58 UTC

[16/51] [abbrv] ignite git commit: IGNITE-2041 Fixed JDBC cache store example. Reworked from deprecated code to new API and refactored code, made it more simple. Fixed bug in store in case of cache configured keepBinaryInStore(true). Added one more a

 IGNITE-2041 Fixed JDBC cache store example.
 Reworked from deprecated code to new API and refactored code, made it more simple.
 Fixed bug in store in case of cache configured keepBinaryInStore(true).
 Added one more auto cache store example: CacheBinaryAutoStoreExample.


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

Branch: refs/heads/ignite-843-rc2
Commit: 92ef7c7ce8229130762b64082cc9455579a05247
Parents: 6a109eb
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Fri Dec 4 17:57:57 2015 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Fri Dec 4 17:57:57 2015 +0700

----------------------------------------------------------------------
 examples/config/example-default.xml             |   7 +
 .../store/auto/CacheBinaryAutoStoreExample.java | 158 +++++++++++++++++++
 .../datagrid/store/auto/package-info.java       |  22 +++
 .../store/auto/CacheAutoStoreExample.java       |  93 +++++++++--
 .../auto/CacheAutoStoreLoadDataExample.java     |  85 ----------
 .../datagrid/store/auto/CacheConfig.java        |  81 ----------
 .../datagrid/store/auto/DbH2ServerStartup.java  |  79 ----------
 .../ignite/examples/util/DbH2ServerStartup.java |  79 ++++++++++
 .../ignite/examples/util/package-info.java      |  22 +++
 .../store/jdbc/CacheAbstractJdbcStore.java      |  12 +-
 .../cache/store/jdbc/CacheJdbcPojoStore.java    |   9 ++
 11 files changed, 390 insertions(+), 257 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/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/92ef7c7c/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/store/auto/CacheBinaryAutoStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/store/auto/CacheBinaryAutoStoreExample.java b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/store/auto/CacheBinaryAutoStoreExample.java
new file mode 100644
index 0000000..9df9f79
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/store/auto/CacheBinaryAutoStoreExample.java
@@ -0,0 +1,158 @@
+/*
+ * 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.examples.binary.datagrid.store.auto;
+
+import java.sql.Types;
+import java.util.UUID;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.Ignition;
+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.ExampleNodeStartup;
+import org.apache.ignite.examples.util.DbH2ServerStartup;
+import org.apache.ignite.examples.model.Person;
+import org.apache.ignite.transactions.Transaction;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+
+/**
+ * Demonstrates usage of cache with underlying persistent store configured.
+ * <p>
+ * This example uses {@link CacheJdbcPojoStore} as a persistent store.
+ * <p>
+ * To start the example, you should:
+ * <ul>
+ *     <li>Start H2 database TCP server using {@link DbH2ServerStartup}.</li>
+ *     <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
+ *     <li>Start example using {@link CacheBinaryAutoStoreExample}.</li>
+ * </ul>
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * contains H2 data source bean descriptor: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
+ * <p>
+ * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-ignite.xml} configuration.
+ */
+public class CacheBinaryAutoStoreExample {
+    /** Global person ID to use across entire example. */
+    private static final Long id = Math.abs(UUID.randomUUID().getLeastSignificantBits());
+
+    /** Cache name. */
+    public static final String CACHE_NAME = CacheBinaryAutoStoreExample.class.getSimpleName();
+
+    /**
+     * Configure cache with store.
+     */
+    private static CacheConfiguration<Long, Person> cacheConfiguration() {
+        CacheJdbcPojoStoreFactory<Long, Person> storeFactory = new CacheJdbcPojoStoreFactory<>();
+
+        storeFactory.setDataSourceBean("h2-example-db");
+        storeFactory.setDialect(new H2Dialect());
+
+        JdbcType jdbcType = new JdbcType();
+
+        jdbcType.setCacheName(CACHE_NAME);
+        jdbcType.setDatabaseSchema("PUBLIC");
+        jdbcType.setDatabaseTable("PERSON");
+
+        jdbcType.setKeyType("java.lang.Long");
+        jdbcType.setKeyFields(new JdbcTypeField(Types.BIGINT, "ID", Long.class, "id"));
+
+        jdbcType.setValueType("org.apache.ignite.examples.model.Person");
+        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")
+        );
+
+        storeFactory.setTypes(jdbcType);
+
+        CacheConfiguration<Long, Person> cfg = new CacheConfiguration<>(CACHE_NAME);
+
+        cfg.setCacheStoreFactory(storeFactory);
+
+        // Set atomicity as transaction, since we are showing transactions in the example.
+        cfg.setAtomicityMode(TRANSACTIONAL);
+
+        // This option will allow to start remote nodes without having user classes in classpath.
+        cfg.setKeepBinaryInStore(true);
+
+        cfg.setReadThrough(true);
+        cfg.setWriteThrough(true);
+
+        return cfg;
+    }
+
+    /**
+     * Executes example.
+     *
+     * @param args Command line arguments, none required.
+     * @throws IgniteException If example execution failed.
+     */
+    public static void main(String[] args) throws IgniteException {
+        // To start ignite with desired configuration uncomment the appropriate line.
+        try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+            System.out.println();
+            System.out.println(">>> Cache auto store example started.");
+
+            try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheConfiguration())) {
+                try (Transaction tx = ignite.transactions().txStart()) {
+                    Person val = cache.get(id);
+
+                    System.out.println("Read value: " + val);
+
+                    val = cache.getAndPut(id, new Person(id, "Isaac", "Newton"));
+
+                    System.out.println("Overwrote old value: " + val);
+
+                    val = cache.get(id);
+
+                    System.out.println("Read value: " + val);
+
+                    tx.commit();
+                }
+
+                System.out.println("Read value after commit: " + cache.get(id));
+
+                cache.clear();
+
+                System.out.println(">>> ------------------------------------------");
+                System.out.println(">>> Load data to cache from DB with cusom SQL...");
+
+                // Load cache on all data nodes with custom SQL statement.
+                cache.loadCache(null, "java.lang.Long", "select * from PERSON where id <= 3");
+
+                System.out.println("Loaded cache entries: " + cache.size());
+
+                cache.clear();
+
+                // Load cache on all data nodes with default SQL statement.
+                System.out.println(">>> Load ALL data to cache from DB...");
+                cache.loadCache(null);
+
+                System.out.println("Loaded cache entries: " + cache.size());
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/store/auto/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/store/auto/package-info.java b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/store/auto/package-info.java
new file mode 100644
index 0000000..153f210
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/store/auto/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains automatic JDBC store example.
+ */
+package org.apache.ignite.examples.binary.datagrid.store.auto;

http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/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..a262c38 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
@@ -17,15 +17,25 @@
 
 package org.apache.ignite.examples.datagrid.store.auto;
 
+import java.sql.Types;
 import java.util.UUID;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.Ignition;
 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.ExampleNodeStartup;
 import org.apache.ignite.examples.model.Person;
+import org.apache.ignite.examples.util.DbH2ServerStartup;
 import org.apache.ignite.transactions.Transaction;
+import org.h2.jdbcx.JdbcConnectionPool;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
 
 /**
  * Demonstrates usage of cache with underlying persistent store configured.
@@ -35,23 +45,70 @@ import org.apache.ignite.transactions.Transaction;
  * To start the example, you should:
  * <ul>
  *     <li>Start H2 database TCP server using {@link DbH2ServerStartup}.</li>
- *     <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
+ *     <li>Start a few nodes using {@link ExampleNodeStartup}.</li>
  *     <li>Start example using {@link CacheAutoStoreExample}.</li>
  * </ul>
  * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
+ * Remote nodes can be started with {@link ExampleNodeStartup} in another JVM which will
  * 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());
 
+    /** Cache name. */
+    public static final String CACHE_NAME = CacheAutoStoreExample.class.getSimpleName();
+
+    /**
+     * Example store factory.
+     */
+    private static final class CacheJdbcPojoStoreExampleFactory extends CacheJdbcPojoStoreFactory<Long, Person> {
+        /** {@inheritDoc} */
+        @Override public CacheJdbcPojoStore<Long, Person> create() {
+            JdbcType jdbcType = new JdbcType();
+
+            jdbcType.setCacheName(CACHE_NAME);
+            jdbcType.setDatabaseSchema("PUBLIC");
+            jdbcType.setDatabaseTable("PERSON");
+
+            jdbcType.setKeyType("java.lang.Long");
+            jdbcType.setKeyFields(new JdbcTypeField(Types.BIGINT, "ID", Long.class, "id"));
+
+            jdbcType.setValueType("org.apache.ignite.examples.model.Person");
+            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")
+            );
+
+            CacheJdbcPojoStore<Long, Person> store = new CacheJdbcPojoStore<>();
+
+            store.setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", ""));
+            store.setDialect(new H2Dialect());
+
+            store.setTypes(jdbcType);
+
+            return store;
+        }
+    }
+
+    /**
+     * Configure cache with store.
+     */
+    private static CacheConfiguration<Long, Person> cacheConfiguration() {
+        CacheConfiguration<Long, Person> cfg = new CacheConfiguration<>(CACHE_NAME);
+
+        cfg.setCacheStoreFactory(new CacheJdbcPojoStoreExampleFactory());
+
+        // Set atomicity as transaction, since we are showing transactions in the example.
+        cfg.setAtomicityMode(TRANSACTIONAL);
+
+        cfg.setReadThrough(true);
+        cfg.setWriteThrough(true);
+
+        return cfg;
+    }
+
     /**
      * Executes example.
      *
@@ -64,7 +121,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(cacheConfiguration())) {
                 try (Transaction tx = ignite.transactions().txStart()) {
                     Person val = cache.get(id);
 
@@ -82,6 +139,24 @@ public class CacheAutoStoreExample {
                 }
 
                 System.out.println("Read value after commit: " + cache.get(id));
+
+                cache.clear();
+
+                System.out.println(">>> ------------------------------------------");
+                System.out.println(">>> Load data to cache from DB with cusom SQL...");
+
+                // Load cache on all data nodes with custom SQL statement.
+                cache.loadCache(null, "java.lang.Long", "select * from PERSON where id <= 3");
+
+                System.out.println("Loaded cache entries: " + cache.size());
+
+                cache.clear();
+
+                // Load cache on all data nodes with default SQL statement.
+                System.out.println(">>> Load ALL data to cache from DB...");
+                cache.loadCache(null);
+
+                System.out.println("Loaded cache entries: " + cache.size());
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/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
deleted file mode 100644
index 63a8c6f..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.examples.datagrid.store.auto;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.examples.ExamplesUtils;
-import org.apache.ignite.examples.model.Person;
-
-/**
- * Demonstrates how to load data from database.
- * <p>
- * This example uses {@link CacheJdbcPojoStore} as a persistent store.
- * <p>
- * To start the example, you should:
- * <ul>
- *     <li>Start H2 database TCP server using {@link DbH2ServerStartup}.</li>
- *     <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
- *     <li>Start example using {@link CacheAutoStoreLoadDataExample}.</li>
- * </ul>
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
- * 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;
-
-    /**
-     * Executes example.
-     *
-     * @param args Command line arguments, none required.
-     * @throws IgniteException If example execution failed.
-     */
-    public static void main(String[] args) throws IgniteException {
-        ExamplesUtils.checkMinMemory(MIN_MEMORY);
-
-        try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
-            System.out.println();
-            System.out.println(">>> Cache auto store load data example started.");
-
-            CacheConfiguration<Long, Person> cacheCfg = CacheConfig.jdbcPojoStoreCache(CACHE_NAME);
-
-            try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheCfg)) {
-                // Load cache on all data nodes with custom SQL statement.
-                cache.loadCache(null, "java.lang.Long", "select * from PERSON where id <= 3");
-
-                System.out.println("Loaded cache entries: " + cache.size());
-
-                cache.clear();
-
-                // Load cache on all data nodes with default SQL statement.
-                cache.loadCache(null);
-
-                System.out.println("Loaded cache entries: " + cache.size());
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/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
deleted file mode 100644
index 3b38aeb..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.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.configuration.CacheConfiguration;
-import org.apache.ignite.examples.model.Person;
-import org.h2.jdbcx.JdbcConnectionPool;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-
-/**
- * Predefined configuration for examples with {@link CacheJdbcPojoStore}.
- */
-public class CacheConfig {
-    /**
-     * Configure cache with store.
-     */
-    public static CacheConfiguration<Long, Person> jdbcPojoStoreCache(String name) {
-        CacheConfiguration<Long, Person> cfg = new CacheConfiguration<>(name);
-
-        // Set atomicity as transaction, since we are showing transactions in the example.
-        cfg.setAtomicityMode(TRANSACTIONAL);
-
-        cfg.setCacheStoreFactory(new Factory<CacheStore<? super Long, ? super Person>>() {
-            @Override public CacheStore<? super Long, ? super Person> create() {
-                CacheJdbcPojoStore<Long, Person> store = new CacheJdbcPojoStore<>();
-
-                store.setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", ""));
-
-                return store;
-            }
-        });
-
-        CacheTypeMetadata meta = new CacheTypeMetadata();
-
-        meta.setDatabaseTable("PERSON");
-
-        meta.setKeyType("java.lang.Long");
-        meta.setValueType("org.apache.ignite.examples.model.Person");
-
-        meta.setKeyFields(Collections.singletonList(new CacheTypeFieldMetadata("ID", Types.BIGINT, "id", Long.class)));
-
-        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)
-        ));
-
-        cfg.setTypeMetadata(Collections.singletonList(meta));
-
-        cfg.setWriteBehindEnabled(true);
-
-        cfg.setReadThrough(true);
-        cfg.setWriteThrough(true);
-
-        return cfg;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/DbH2ServerStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/DbH2ServerStartup.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/DbH2ServerStartup.java
deleted file mode 100644
index f5e07a8..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/DbH2ServerStartup.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.examples.datagrid.store.auto;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.sql.SQLException;
-import org.apache.ignite.IgniteException;
-import org.h2.jdbcx.JdbcConnectionPool;
-import org.h2.tools.RunScript;
-import org.h2.tools.Server;
-
-/**
- * Start H2 database TCP server in order to access sample in-memory database from other processes.
- */
-public class DbH2ServerStartup {
-    /** Create table script. */
-    private static final String CREATE_TABLE =
-        "create table PERSON(id bigint not null, first_name varchar(50), last_name varchar(50), PRIMARY KEY(id));";
-
-    /** Sample data script. */
-    private static final String POPULATE_TABLE =
-        "insert into PERSON(id, first_name, last_name) values(1, 'Johannes', 'Kepler');\n" +
-        "insert into PERSON(id, first_name, last_name) values(2, 'Galileo', 'Galilei');\n" +
-        "insert into PERSON(id, first_name, last_name) values(3, 'Henry', 'More');\n" +
-        "insert into PERSON(id, first_name, last_name) values(4, 'Polish', 'Brethren');\n" +
-        "insert into PERSON(id, first_name, last_name) values(5, 'Robert', 'Boyle');\n" +
-        "insert into PERSON(id, first_name, last_name) values(6, 'Isaac', 'Newton');";
-
-    /**
-     * Start H2 database TCP server.
-     *
-     * @param args Command line arguments, none required.
-     * @throws IgniteException If start H2 database TCP server failed.
-     */
-    public static void main(String[] args) throws IgniteException {
-        try {
-            // Start H2 database TCP server in order to access sample in-memory database from other processes.
-            Server.createTcpServer("-tcpDaemon").start();
-
-            // Try to connect to database TCP server.
-            JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", "");
-
-            // Create Person table in database.
-            RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_TABLE));
-
-            // Populates Person table with sample data in database.
-            RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_TABLE));
-        }
-        catch (SQLException e) {
-            throw new IgniteException("Failed to start database TCP server", e);
-        }
-
-        try {
-            do {
-                System.out.println("Type 'q' and press 'Enter' to stop H2 TCP server...");
-            }
-            while ('q' != System.in.read());
-        }
-        catch (IOException ignored) {
-            // No-op.
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/examples/src/main/java/org/apache/ignite/examples/util/DbH2ServerStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/util/DbH2ServerStartup.java b/examples/src/main/java/org/apache/ignite/examples/util/DbH2ServerStartup.java
new file mode 100644
index 0000000..01717d0
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/util/DbH2ServerStartup.java
@@ -0,0 +1,79 @@
+/*
+ * 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.examples.util;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.sql.SQLException;
+import org.apache.ignite.IgniteException;
+import org.h2.jdbcx.JdbcConnectionPool;
+import org.h2.tools.RunScript;
+import org.h2.tools.Server;
+
+/**
+ * Start H2 database TCP server in order to access sample in-memory database from other processes.
+ */
+public class DbH2ServerStartup {
+    /** Create table script. */
+    private static final String CREATE_TABLE =
+        "create table PERSON(id bigint not null, first_name varchar(50), last_name varchar(50), PRIMARY KEY(id));";
+
+    /** Sample data script. */
+    private static final String POPULATE_TABLE =
+        "insert into PERSON(id, first_name, last_name) values(1, 'Johannes', 'Kepler');\n" +
+        "insert into PERSON(id, first_name, last_name) values(2, 'Galileo', 'Galilei');\n" +
+        "insert into PERSON(id, first_name, last_name) values(3, 'Henry', 'More');\n" +
+        "insert into PERSON(id, first_name, last_name) values(4, 'Polish', 'Brethren');\n" +
+        "insert into PERSON(id, first_name, last_name) values(5, 'Robert', 'Boyle');\n" +
+        "insert into PERSON(id, first_name, last_name) values(6, 'Isaac', 'Newton');";
+
+    /**
+     * Start H2 database TCP server.
+     *
+     * @param args Command line arguments, none required.
+     * @throws IgniteException If start H2 database TCP server failed.
+     */
+    public static void main(String[] args) throws IgniteException {
+        try {
+            // Start H2 database TCP server in order to access sample in-memory database from other processes.
+            Server.createTcpServer("-tcpDaemon").start();
+
+            // Try to connect to database TCP server.
+            JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", "");
+
+            // Create Person table in database.
+            RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_TABLE));
+
+            // Populates Person table with sample data in database.
+            RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_TABLE));
+        }
+        catch (SQLException e) {
+            throw new IgniteException("Failed to start database TCP server", e);
+        }
+
+        try {
+            do {
+                System.out.println("Type 'q' and press 'Enter' to stop H2 TCP server...");
+            }
+            while ('q' != System.in.read());
+        }
+        catch (IOException ignored) {
+            // No-op.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/examples/src/main/java/org/apache/ignite/examples/util/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/util/package-info.java b/examples/src/main/java/org/apache/ignite/examples/util/package-info.java
new file mode 100644
index 0000000..1d87d02
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/util/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains utility classes for examples.
+ */
+package org.apache.ignite.examples.util;

http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
index 7617e48..366262c 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
@@ -49,6 +49,7 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.cache.CacheTypeFieldMetadata;
 import org.apache.ignite.cache.CacheTypeMetadata;
 import org.apache.ignite.cache.store.CacheStore;
@@ -1442,8 +1443,7 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>,
      * @return Next index for parameters.
      * @throws CacheException If failed to set statement parameters.
      */
-    protected int fillKeyParameters(PreparedStatement stmt, int idx, EntryMapping em,
-        Object key) throws CacheException {
+    protected int fillKeyParameters(PreparedStatement stmt, int idx, EntryMapping em, Object key) throws CacheException {
         for (JdbcTypeField field : em.keyColumns()) {
             Object fieldVal = extractParameter(em.cacheName, em.keyType(), em.keyKind(), field.getJavaFieldName(), key);
 
@@ -1474,8 +1474,14 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>,
      */
     protected int fillValueParameters(PreparedStatement stmt, int idx, EntryMapping em, Object val)
         throws CacheWriterException {
+        TypeKind valKind = em.valueKind();
+
+        // Object could be passed by cache in binary format in case of cache configured with setKeepBinaryInStore(true).
+        if (valKind == TypeKind.POJO && val instanceof BinaryObject)
+            valKind = TypeKind.BINARY;
+
         for (JdbcTypeField field : em.uniqValFlds) {
-            Object fieldVal = extractParameter(em.cacheName, em.valueType(), em.valueKind(), field.getJavaFieldName(), val);
+            Object fieldVal = extractParameter(em.cacheName, em.valueType(), valKind, field.getJavaFieldName(), val);
 
             fillParameter(stmt, idx++, field, fieldVal);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/92ef7c7c/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java
index abc4b2e..a25df04 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java
@@ -354,6 +354,15 @@ public class CacheJdbcPojoStore<K, V> extends CacheAbstractJdbcStore<K, V> {
             this.getter = getter;
             this.setter = setter;
             this.field = field;
+
+            if (getter != null)
+                getter.setAccessible(true);
+
+            if (setter != null)
+                setter.setAccessible(true);
+
+            if (field != null)
+                field.setAccessible(true);
         }
 
         /**