ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject [10/18] ignite git commit: IGNITE-2832 Implemented datasource creation via factory.
Date Mon, 16 May 2016 08:11:56 GMT
IGNITE-2832 Implemented datasource creation via factory.


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

Branch: refs/heads/ignite-3098
Commit: aede4b365c7d267b3009305cc18d097f10fa3fef
Parents: a7e57e5
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Fri May 13 16:58:01 2016 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Fri May 13 16:58:01 2016 +0700

----------------------------------------------------------------------
 .../java/org/apache/ignite/schema/Demo.java     |  23 +--
 .../ignite/schema/H2DataSourceFactory.java      |  35 ++++
 .../store/jdbc/CacheJdbcPojoStoreFactory.java   |  59 ++++--
 .../CacheJdbcPojoStoreAbstractSelfTest.java     |  45 ++++-
 .../cache/store/jdbc/H2DataSourceFactory.java   |  35 ++++
 .../src/test/config/jdbc-pojo-store-builtin.xml | 194 +++++++++++++++++++
 .../src/test/config/jdbc-pojo-store-obj.xml     | 194 +++++++++++++++++++
 .../store/jdbc/CachePojoStoreXmlSelfTest.java   |  51 +++++
 8 files changed, 594 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/aede4b36/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 a8934cb..fa52a1d 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
@@ -24,10 +24,8 @@ 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.dialect.H2Dialect;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.transactions.Transaction;
-import org.h2.jdbcx.JdbcConnectionPool;
 
 /**
  * This demo demonstrates the use of cache with {@link CacheJdbcPojoStore}
@@ -38,20 +36,6 @@ import org.h2.jdbcx.JdbcConnectionPool;
  */
 public class Demo {
     /**
-     * Constructs and returns a fully configured instance of a {@link CacheJdbcPojoStoreFactory}.
-     */
-    private static class H2DemoStoreFactory<K, V> extends CacheJdbcPojoStoreFactory<K, V> {
-        /** {@inheritDoc} */
-        @Override public CacheJdbcPojoStore<K, V> create() {
-            setDialect(new H2Dialect());
-
-            setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/~/schema-import/demo", "sa", ""));
-
-            return super.create();
-        }
-    }
-
-    /**
      * Executes demo.
      *
      * @param args Command line arguments, none required.
@@ -62,9 +46,12 @@ public class Demo {
 
         // Start Ignite node.
         try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+            CacheJdbcPojoStoreFactory<PersonKey, Person> pojoStoreFactory = new CacheJdbcPojoStoreFactory<>();
+
+            pojoStoreFactory.setDataSourceFactory(new H2DataSourceFactory());
+
             // Configure cache store.
-            CacheConfiguration<PersonKey, Person> cfg =
-                CacheConfig.cache("PersonCache", new H2DemoStoreFactory<PersonKey, Person>());
+            CacheConfiguration<PersonKey, Person> cfg = CacheConfig.cache("PersonCache", pojoStoreFactory);
 
             try (IgniteCache<PersonKey, Person> cache = ignite.getOrCreateCache(cfg)) {
                 // Preload cache from database.

http://git-wip-us.apache.org/repos/asf/ignite/blob/aede4b36/examples/schema-import/src/main/java/org/apache/ignite/schema/H2DataSourceFactory.java
----------------------------------------------------------------------
diff --git a/examples/schema-import/src/main/java/org/apache/ignite/schema/H2DataSourceFactory.java b/examples/schema-import/src/main/java/org/apache/ignite/schema/H2DataSourceFactory.java
new file mode 100644
index 0000000..6a4ea0a
--- /dev/null
+++ b/examples/schema-import/src/main/java/org/apache/ignite/schema/H2DataSourceFactory.java
@@ -0,0 +1,35 @@
+/*
+ * 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.schema;
+
+import javax.cache.configuration.Factory;
+import javax.sql.DataSource;
+import org.h2.jdbcx.JdbcConnectionPool;
+
+/**
+ * Datasource to use for store tests.
+ */
+public class H2DataSourceFactory implements Factory<DataSource> {
+    /** DB connection URL. */
+    private static final String DFLT_CONN_URL = "jdbc:h2:tcp://localhost/~/schema-import/demo";
+
+    /** {@inheritDoc} */
+    @Override public DataSource create() {
+        return JdbcConnectionPool.create(DFLT_CONN_URL, "sa", "");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/aede4b36/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreFactory.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreFactory.java
index ded83ce..0fca3ab 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreFactory.java
@@ -31,6 +31,10 @@ import org.apache.ignite.resources.SpringApplicationContextResource;
  * {@link Factory} implementation for {@link CacheJdbcPojoStore}.
  *
  * Use this factory to pass {@link CacheJdbcPojoStore} to {@link CacheConfiguration}.
+ * <p>
+ * Please note, that {@link CacheJdbcPojoStoreFactory#setDataSource(DataSource)} is deprecated and
+ * {@link CacheJdbcPojoStoreFactory#setDataSourceFactory(Factory)} or
+ * {@link CacheJdbcPojoStoreFactory#setDataSourceBean(String)} should be used instead.
  *
  * <h2 class="header">Spring Example</h2>
  * <pre name="code" class="xml">
@@ -133,6 +137,9 @@ public class CacheJdbcPojoStoreFactory<K, V> implements Factory<CacheAbstractJdb
     /** Data source. */
     private transient DataSource dataSrc;
 
+    /** Data source factory. */
+    private Factory<DataSource> dataSrcFactory;
+
     /** Application context. */
     @SpringApplicationContextResource
     private transient Object appCtx;
@@ -150,26 +157,26 @@ public class CacheJdbcPojoStoreFactory<K, V> implements Factory<CacheAbstractJdb
 
         if (dataSrc != null)
             store.setDataSource(dataSrc);
-        else {
-            if (dataSrcBean != null) {
-                if (appCtx == null)
-                    throw new IgniteException("Spring application context resource is not injected.");
+        else if (dataSrcBean != null) {
+            if (appCtx == null)
+                throw new IgniteException("Spring application context resource is not injected.");
 
-                IgniteSpringHelper spring;
+            IgniteSpringHelper spring;
 
-                try {
-                    spring = IgniteComponentType.SPRING.create(false);
+            try {
+                spring = IgniteComponentType.SPRING.create(false);
 
-                    DataSource data = spring.loadBeanFromAppContext(appCtx, dataSrcBean);
+                DataSource data = spring.loadBeanFromAppContext(appCtx, dataSrcBean);
 
-                    store.setDataSource(data);
-                }
-                catch (Exception e) {
-                    throw new IgniteException("Failed to load bean in application context [beanName=" + dataSrcBean +
-                        ", igniteConfig=" + appCtx + ']', e);
-                }
+                store.setDataSource(data);
+            }
+            catch (Exception e) {
+                throw new IgniteException("Failed to load bean in application context [beanName=" + dataSrcBean +
+                    ", igniteConfig=" + appCtx + ']', e);
             }
         }
+        else if (dataSrcFactory != null)
+            store.setDataSource(dataSrcFactory.create());
 
         return store;
     }
@@ -181,6 +188,7 @@ public class CacheJdbcPojoStoreFactory<K, V> implements Factory<CacheAbstractJdb
      * @return {@code This} for chaining.
      * @see CacheJdbcPojoStore#setDataSource(DataSource)
      */
+    @Deprecated
     public CacheJdbcPojoStoreFactory<K, V> setDataSource(DataSource dataSrc) {
         this.dataSrc = dataSrc;
 
@@ -355,6 +363,29 @@ public class CacheJdbcPojoStoreFactory<K, V> implements Factory<CacheAbstractJdb
         return this;
     }
 
+    /**
+     * Gets factory for underlying datasource.
+     *
+     * @return Cache store factory.
+     */
+    @SuppressWarnings("unchecked")
+    public Factory<DataSource> getDataSourceFactory() {
+        return dataSrcFactory;
+    }
+
+    /**
+     * Sets factory for underlying datasource.
+
+     * @param dataSrcFactory Datasource factory.
+     * @return {@code this} for chaining.
+     */
+    @SuppressWarnings("unchecked")
+    public CacheJdbcPojoStoreFactory<K, V> setDataSourceFactory(Factory<DataSource> dataSrcFactory) {
+        this.dataSrcFactory = dataSrcFactory;
+
+        return this;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(CacheJdbcPojoStoreFactory.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/aede4b36/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java
index a526b8c..41a6136 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java
@@ -39,7 +39,6 @@ import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.h2.jdbcx.JdbcConnectionPool;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
@@ -61,6 +60,9 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
     /** Person count. */
     protected static final int PERSON_CNT = 100000;
 
+    /** Test cache name. */
+    protected static final String CACHE_NAME = "test-cache";
+
     /** Flag indicating that tests should use transactional cache. */
     protected static boolean transactional;
 
@@ -147,11 +149,12 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
         JdbcType[] storeTypes = new JdbcType[2];
 
         storeTypes[0] = new JdbcType();
+        storeTypes[0].setCacheName(CACHE_NAME);
         storeTypes[0].setDatabaseSchema("PUBLIC");
         storeTypes[0].setDatabaseTable("ORGANIZATION");
 
         if (builtinKeys) {
-            storeTypes[0].setKeyType("java.lang.Integer");
+            storeTypes[0].setKeyType("java.lang.Long");
             storeTypes[0].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"));
         }
         else {
@@ -166,11 +169,12 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
             new JdbcTypeField(Types.VARCHAR, "CITY", String.class, "city"));
 
         storeTypes[1] = new JdbcType();
+        storeTypes[1].setCacheName(CACHE_NAME);
         storeTypes[1].setDatabaseSchema("PUBLIC");
         storeTypes[1].setDatabaseTable("PERSON");
 
         if (builtinKeys) {
-            storeTypes[1].setKeyType("java.lang.Long");
+            storeTypes[1].setKeyType("java.lang.Integer");
             storeTypes[1].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Long.class, "id"));
         }
         else {
@@ -195,6 +199,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
     protected CacheConfiguration cacheConfiguration() throws Exception {
         CacheConfiguration cc = defaultCacheConfiguration();
 
+        cc.setName(CACHE_NAME);
         cc.setCacheMode(PARTITIONED);
         cc.setAtomicityMode(transactional ? TRANSACTIONAL : ATOMIC);
         cc.setSwapEnabled(false);
@@ -203,7 +208,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
         CacheJdbcPojoStoreFactory<Object, Object> storeFactory = new CacheJdbcPojoStoreFactory<>();
         storeFactory.setDialect(new H2Dialect());
         storeFactory.setTypes(storeTypes());
-        storeFactory.setDataSource(JdbcConnectionPool.create(DFLT_CONN_URL, "sa", "")); // H2 DataSource
+        storeFactory.setDataSourceFactory(new H2DataSourceFactory()); // H2 DataSource factory.
 
         cc.setCacheStoreFactory(storeFactory);
         cc.setReadThrough(true);
@@ -283,7 +288,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
      * Check that data was loaded correctly.
      */
     protected void checkCacheContent() {
-        IgniteCache<Object, Object> c1 = grid().cache(null);
+        IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME);
 
         c1.loadCache(null);
 
@@ -332,7 +337,7 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
      * @throws Exception If failed.
      */
     private void checkPut() throws Exception {
-        IgniteCache<PersonKey, Person> c1 = grid().cache(null);
+        IgniteCache<Object, Person> c1 = grid().cache(CACHE_NAME);
 
         Connection conn = getConnection();
         try {
@@ -346,12 +351,14 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
 
             U.closeQuiet(rs);
 
-            // Test put-insert.
-            PersonKey key = new PersonKey(-1);
-
             Date testDate = Date.valueOf("2001-05-05");
 
-            c1.put(key, new Person(-1, -2, testDate, "Person-to-test-put-insert", 999));
+            Person val = new Person(-1, -2, testDate, "Person-to-test-put-insert", 999);
+
+            Object key = builtinKeys ? Integer.valueOf(-1) : new PersonKey(-1);
+
+            // Test put-insert.
+            c1.put(key, val);
 
             rs = stmt.executeQuery();
 
@@ -392,6 +399,15 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
     /**
      * @throws Exception If failed.
      */
+    public void testPutBuiltIn() throws Exception {
+        startTestGrid(true, false, false, false);
+
+        checkPut();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testPut() throws Exception {
         startTestGrid(false, false, false, false);
 
@@ -401,6 +417,15 @@ public abstract class CacheJdbcPojoStoreAbstractSelfTest extends GridCommonAbstr
     /**
      * @throws Exception If failed.
      */
+    public void testPutTxBuiltIn() throws Exception {
+        startTestGrid(true, false, false, true);
+
+        checkPut();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testPutTx() throws Exception {
         startTestGrid(false, false, false, true);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/aede4b36/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/H2DataSourceFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/H2DataSourceFactory.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/H2DataSourceFactory.java
new file mode 100644
index 0000000..e8f447a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/H2DataSourceFactory.java
@@ -0,0 +1,35 @@
+/*
+ * 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.cache.store.jdbc;
+
+import javax.cache.configuration.Factory;
+import javax.sql.DataSource;
+import org.h2.jdbcx.JdbcConnectionPool;
+
+/**
+ * Datasource to use for store tests.
+ */
+public class H2DataSourceFactory implements Factory<DataSource> {
+    /** DB connection URL. */
+    private static final String DFLT_CONN_URL = "jdbc:h2:mem:TestDatabase;DB_CLOSE_DELAY=-1";
+
+    /** {@inheritDoc} */
+    @Override public DataSource create() {
+        return JdbcConnectionPool.create(DFLT_CONN_URL, "sa", "");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/aede4b36/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml b/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml
new file mode 100644
index 0000000..3480ece
--- /dev/null
+++ b/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml
@@ -0,0 +1,194 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                           http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/util
+                           http://www.springframework.org/schema/util/spring-util.xsd">
+    <bean class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="gridName" value="test-cluster"/>
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47503</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+
+        <property name="cacheConfiguration">
+            <list>
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="test-cache"/>
+                    <property name="cacheMode" value="PARTITIONED"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="readFromBackup" value="true"/>
+                    <property name="copyOnRead" value="true"/>
+
+                    <property name="cacheStoreFactory">
+                        <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
+                            <property name="dataSourceFactory">
+                                <bean class="org.apache.ignite.cache.store.jdbc.H2DataSourceFactory"/>
+                            </property>
+
+                            <property name="dialect">
+                                <bean class="org.apache.ignite.cache.store.jdbc.dialect.H2Dialect"/>
+                            </property>
+                            <property name="types">
+                                <list>
+                                    <bean class="org.apache.ignite.cache.store.jdbc.JdbcType">
+                                        <property name="cacheName" value="test-cache"/>
+                                        <property name="keyType" value="java.lang.Long"/>
+                                        <property name="valueType" value="org.apache.ignite.cache.store.jdbc.model.Organization"/>
+                                        <property name="databaseSchema" value="PUBLIC"/>
+                                        <property name="databaseTable" value="ORGANIZATION"/>
+
+                                        <property name="keyFields">
+                                            <list>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="id"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.INTEGER"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="id"/>
+                                                    <property name="javaFieldType" value="java.lang.Integer"/>
+                                                </bean>
+                                            </list>
+                                        </property>
+
+                                        <property name="valueFields">
+                                            <list>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="name"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="name"/>
+                                                    <property name="javaFieldType" value="java.lang.String"/>
+                                                </bean>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="city"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="city"/>
+                                                    <property name="javaFieldType" value="java.lang.String"/>
+                                                </bean>
+                                            </list>
+                                        </property>
+                                    </bean>
+
+                                    <bean class="org.apache.ignite.cache.store.jdbc.JdbcType">
+                                        <property name="cacheName" value="test-cache"/>
+                                        <property name="keyType" value="java.lang.Integer"/>
+                                        <property name="valueType" value="org.apache.ignite.cache.store.jdbc.model.Person"/>
+                                        <property name="databaseSchema" value="PUBLIC"/>
+                                        <property name="databaseTable" value="PERSON"/>
+
+                                        <property name="keyFields">
+                                            <list>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="id"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.INTEGER"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="id"/>
+                                                    <property name="javaFieldType" value="java.lang.Integer"/>
+                                                </bean>
+                                            </list>
+                                        </property>
+
+                                        <property name="valueFields">
+                                            <list>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="name"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="name"/>
+                                                    <property name="javaFieldType" value="java.lang.String"/>
+                                                </bean>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="birthday"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.DATE"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="birthday"/>
+                                                    <property name="javaFieldType" value="java.sql.Date"/>
+                                                </bean>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="ORG_ID"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.INTEGER"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="orgId"/>
+                                                    <property name="javaFieldType" value="java.lang.Integer"/>
+                                                </bean>
+                                            </list>
+                                        </property>
+                                    </bean>
+                                </list>
+                            </property>
+                        </bean>
+                    </property>
+
+                    <property name="readThrough" value="true"/>
+                    <property name="writeThrough" value="true"/>
+
+                    <property name="queryEntities">
+                        <list>
+                            <bean class="org.apache.ignite.cache.QueryEntity">
+                                <property name="keyType" value="java.lang.Long"/>
+                                <property name="valueType" value="org.apache.ignite.cache.store.jdbc.model.Organization"/>
+                                <property name="fields">
+                                    <map>
+                                        <entry key="id" value="java.lang.Integer"/>
+                                        <entry key="name" value="java.lang.String"/>
+                                        <entry key="city" value="java.lang.String"/>
+                                    </map>
+                                </property>
+                            </bean>
+
+                            <bean class="org.apache.ignite.cache.QueryEntity">
+                                <property name="keyType" value="java.lang.Integer"/>
+                                <property name="valueType" value="org.apache.ignite.cache.store.jdbc.model.Person"/>
+                                <property name="fields">
+                                    <map>
+                                        <entry key="id" value="java.lang.Integer"/>
+                                        <entry key="name" value="java.lang.String"/>
+                                        <entry key="birthday" value="java.sql.Date"/>
+                                        <entry key="orgId" value="java.lang.Integer"/>
+                                    </map>
+                                </property>
+                            </bean>
+                        </list>
+                    </property>
+                </bean>
+            </list>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/aede4b36/modules/spring/src/test/config/jdbc-pojo-store-obj.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/config/jdbc-pojo-store-obj.xml b/modules/spring/src/test/config/jdbc-pojo-store-obj.xml
new file mode 100644
index 0000000..ee761d0
--- /dev/null
+++ b/modules/spring/src/test/config/jdbc-pojo-store-obj.xml
@@ -0,0 +1,194 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                           http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/util
+                           http://www.springframework.org/schema/util/spring-util.xsd">
+    <bean class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="gridName" value="test-cluster"/>
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47503</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+
+        <property name="cacheConfiguration">
+            <list>
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="test-cache"/>
+                    <property name="cacheMode" value="PARTITIONED"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="readFromBackup" value="true"/>
+                    <property name="copyOnRead" value="true"/>
+
+                    <property name="cacheStoreFactory">
+                        <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
+                            <property name="dataSourceFactory">
+                                <bean class="org.apache.ignite.cache.store.jdbc.H2DataSourceFactory"/>
+                            </property>
+
+                            <property name="dialect">
+                                <bean class="org.apache.ignite.cache.store.jdbc.dialect.H2Dialect"/>
+                            </property>
+                            <property name="types">
+                                <list>
+                                    <bean class="org.apache.ignite.cache.store.jdbc.JdbcType">
+                                        <property name="cacheName" value="test-cache"/>
+                                        <property name="keyType" value="org.apache.ignite.cache.store.jdbc.model.OrganizationKey"/>
+                                        <property name="valueType" value="org.apache.ignite.cache.store.jdbc.model.Organization"/>
+                                        <property name="databaseSchema" value="PUBLIC"/>
+                                        <property name="databaseTable" value="ORGANIZATION"/>
+
+                                        <property name="keyFields">
+                                            <list>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="id"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.INTEGER"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="id"/>
+                                                    <property name="javaFieldType" value="java.lang.Integer"/>
+                                                </bean>
+                                            </list>
+                                        </property>
+
+                                        <property name="valueFields">
+                                            <list>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="name"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="name"/>
+                                                    <property name="javaFieldType" value="java.lang.String"/>
+                                                </bean>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="city"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="city"/>
+                                                    <property name="javaFieldType" value="java.lang.String"/>
+                                                </bean>
+                                            </list>
+                                        </property>
+                                    </bean>
+
+                                    <bean class="org.apache.ignite.cache.store.jdbc.JdbcType">
+                                        <property name="cacheName" value="test-cache"/>
+                                        <property name="keyType" value="org.apache.ignite.cache.store.jdbc.model.PersonKey"/>
+                                        <property name="valueType" value="org.apache.ignite.cache.store.jdbc.model.Person"/>
+                                        <property name="databaseSchema" value="PUBLIC"/>
+                                        <property name="databaseTable" value="PERSON"/>
+
+                                        <property name="keyFields">
+                                            <list>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="id"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.INTEGER"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="id"/>
+                                                    <property name="javaFieldType" value="java.lang.Integer"/>
+                                                </bean>
+                                            </list>
+                                        </property>
+
+                                        <property name="valueFields">
+                                            <list>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="name"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="name"/>
+                                                    <property name="javaFieldType" value="java.lang.String"/>
+                                                </bean>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="birthday"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.DATE"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="birthday"/>
+                                                    <property name="javaFieldType" value="java.sql.Date"/>
+                                                </bean>
+                                                <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                                    <property name="databaseFieldName" value="ORG_ID"/>
+                                                    <property name="databaseFieldType">
+                                                        <util:constant static-field="java.sql.Types.INTEGER"/>
+                                                    </property>
+                                                    <property name="javaFieldName" value="orgId"/>
+                                                    <property name="javaFieldType" value="java.lang.Integer"/>
+                                                </bean>
+                                            </list>
+                                        </property>
+                                    </bean>
+                                </list>
+                            </property>
+                        </bean>
+                    </property>
+
+                    <property name="readThrough" value="true"/>
+                    <property name="writeThrough" value="true"/>
+
+                    <property name="queryEntities">
+                        <list>
+                            <bean class="org.apache.ignite.cache.QueryEntity">
+                                <property name="keyType" value="org.apache.ignite.cache.store.jdbc.model.OrganizationKey"/>
+                                <property name="valueType" value="org.apache.ignite.cache.store.jdbc.model.Organization"/>
+                                <property name="fields">
+                                    <map>
+                                        <entry key="id" value="java.lang.Integer"/>
+                                        <entry key="name" value="java.lang.String"/>
+                                        <entry key="city" value="java.lang.String"/>
+                                    </map>
+                                </property>
+                            </bean>
+
+                            <bean class="org.apache.ignite.cache.QueryEntity">
+                                <property name="keyType" value="org.apache.ignite.cache.store.jdbc.model.PersonKey"/>
+                                <property name="valueType" value="org.apache.ignite.cache.store.jdbc.model.Person"/>
+                                <property name="fields">
+                                    <map>
+                                        <entry key="id" value="java.lang.Integer"/>
+                                        <entry key="name" value="java.lang.String"/>
+                                        <entry key="birthday" value="java.sql.Date"/>
+                                        <entry key="orgId" value="java.lang.Integer"/>
+                                    </map>
+                                </property>
+                            </bean>
+                        </list>
+                    </property>
+                </bean>
+            </list>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/aede4b36/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CachePojoStoreXmlSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CachePojoStoreXmlSelfTest.java b/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CachePojoStoreXmlSelfTest.java
new file mode 100644
index 0000000..c712f88
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/cache/store/jdbc/CachePojoStoreXmlSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.cache.store.jdbc;
+
+import java.net.URL;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteComponentType;
+import org.apache.ignite.internal.util.spring.IgniteSpringHelper;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.Marshaller;
+
+/**
+ * Tests for {@code PojoCacheStore} created via XML.
+ */
+public class CachePojoStoreXmlSelfTest extends CacheJdbcPojoStoreAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        String path = builtinKeys ?  "modules/spring/src/test/config/jdbc-pojo-store-builtin.xml" :
+            "modules/spring/src/test/config/jdbc-pojo-store-obj.xml";
+
+        URL url = U.resolveIgniteUrl(path);
+
+        IgniteSpringHelper spring = IgniteComponentType.SPRING.create(false);
+
+        IgniteConfiguration cfg = spring.loadConfigurations(url).get1().iterator().next();
+
+        cfg.setGridName(gridName);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Marshaller marshaller() {
+        return null;
+    }
+}


Mime
View raw message