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/10/29 05:04:13 UTC
ignite git commit: IGNITE-1753 Added more tests. Minor fixes.
Repository: ignite
Updated Branches:
refs/heads/ignite-1753-1282 8379b659c -> c483f10cb
IGNITE-1753 Added more tests. Minor fixes.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c483f10c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c483f10c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c483f10c
Branch: refs/heads/ignite-1753-1282
Commit: c483f10cb6643261f10eb486a0be93d279b5b59c
Parents: 8379b65
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Thu Oct 29 11:04:18 2015 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Thu Oct 29 11:04:18 2015 +0700
----------------------------------------------------------------------
.../store/jdbc/CacheAbstractJdbcStore.java | 8 +++--
.../store/jdbc/CacheJdbcPojoStoreFactory.java | 2 +-
.../ignite/cache/store/jdbc/JdbcType.java | 6 ++++
.../store/jdbc/CacheJdbcPojoStoreSelfTest.java | 24 +++++++++++---
.../jdbc/CacheJdbcStoreAbstractSelfTest.java | 35 ++++++++++++++------
5 files changed, 58 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/c483f10c/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 787e9e6..9a4ce75 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
@@ -68,6 +68,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiInClosure;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.lifecycle.LifecycleAware;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.resources.CacheStoreSessionResource;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.apache.ignite.resources.LoggerResource;
@@ -123,7 +124,6 @@ import static org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreConfiguration
* ...
* </pre>
*/
-@Deprecated
public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>, LifecycleAware {
/** Connection attribute property name. */
protected static final String ATTR_CONN_PROP = "JDBC_STORE_CONNECTION";
@@ -672,7 +672,9 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>,
// If no types configured, check CacheTypeMetadata for backward compatibility.
if (types == null) {
- CacheConfiguration ccfg = ignite().cache(cacheName).getConfiguration(CacheConfiguration.class);
+ boolean keepSerialized = ignite.configuration().getMarshaller() instanceof PortableMarshaller;
+
+ CacheConfiguration ccfg = ignite.cache(cacheName).getConfiguration(CacheConfiguration.class);
Collection<CacheTypeMetadata> oldTypes = ccfg.getTypeMetadata();
@@ -683,6 +685,8 @@ public abstract class CacheAbstractJdbcStore<K, V> implements CacheStore<K, V>,
for (CacheTypeMetadata oldType : oldTypes) {
JdbcType newType = new JdbcType();
+ newType.setKeepSerialized(keepSerialized);
+
newType.setCacheName(cacheName);
newType.setDatabaseSchema(oldType.getDatabaseSchema());
http://git-wip-us.apache.org/repos/asf/ignite/blob/c483f10c/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 5545343..9488749 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
@@ -57,7 +57,7 @@ import org.apache.ignite.resources.SpringApplicationContextResource;
* <br>
* For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
*/
-public class CacheJdbcPojoStoreFactory<K, V> implements Factory<CacheJdbcPojoStore<K, V>> {
+public class CacheJdbcPojoStoreFactory<K, V> implements Factory<CacheAbstractJdbcStore<K, V>> {
/** */
private static final long serialVersionUID = 0L;
http://git-wip-us.apache.org/repos/asf/ignite/blob/c483f10c/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcType.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcType.java
index cb08fc1..518ad8a 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcType.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcType.java
@@ -19,6 +19,7 @@ package org.apache.ignite.cache.store.jdbc;
import java.io.Serializable;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
/**
* Description for type that could be stored into database by store.
@@ -269,4 +270,9 @@ public class JdbcType implements Serializable {
return this;
}
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(JdbcType.class, this);
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c483f10c/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreSelfTest.java
index 7566572..f32d864 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreSelfTest.java
@@ -37,8 +37,16 @@ public class CacheJdbcPojoStoreSelfTest extends CacheJdbcStoreAbstractSelfTest {
storeTypes[0] = new JdbcType();
storeTypes[0].setDatabaseSchema("PUBLIC");
storeTypes[0].setDatabaseTable("ORGANIZATION");
- storeTypes[0].setKeyType("org.apache.ignite.cache.store.jdbc.model.OrganizationKey");
- storeTypes[0].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"));
+
+ if (primitiveKeys) {
+ storeTypes[0].setKeyType("java.lang.Integer");
+ storeTypes[0].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"));
+ }
+ else {
+ storeTypes[0].setKeyType("org.apache.ignite.cache.store.jdbc.model.OrganizationKey");
+ storeTypes[0].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"));
+ }
+
storeTypes[0].setValueType("org.apache.ignite.cache.store.jdbc.model.Organization");
storeTypes[0].setValueFields(
new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"),
@@ -48,8 +56,16 @@ public class CacheJdbcPojoStoreSelfTest extends CacheJdbcStoreAbstractSelfTest {
storeTypes[1] = new JdbcType();
storeTypes[1].setDatabaseSchema("PUBLIC");
storeTypes[1].setDatabaseTable("PERSON");
- storeTypes[1].setKeyType("org.apache.ignite.cache.store.jdbc.model.PersonKey");
- storeTypes[1].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"));
+
+ if (primitiveKeys) {
+ storeTypes[1].setKeyType("java.lang.Long");
+ storeTypes[1].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Long.class, "id"));
+ }
+ else {
+ storeTypes[1].setKeyType("org.apache.ignite.cache.store.jdbc.model.PersonKey");
+ storeTypes[1].setKeyFields(new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"));
+ }
+
storeTypes[1].setValueType("org.apache.ignite.cache.store.jdbc.model.Person");
storeTypes[1].setValueFields(
new JdbcTypeField(Types.INTEGER, "ID", Integer.class, "id"),
http://git-wip-us.apache.org/repos/asf/ignite/blob/c483f10c/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractSelfTest.java
index bc9e73d..8334077 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractSelfTest.java
@@ -54,6 +54,9 @@ public abstract class CacheJdbcStoreAbstractSelfTest extends GridCommonAbstractT
/** Person count. */
protected static final int PERSON_CNT = 100000;
+ /** Flag indicating that tests should use primitive classes like java.lang.Integer for keys. */
+ protected static boolean primitiveKeys = false;
+
/**
* @return Connection to test in-memory H2 database.
* @throws SQLException
@@ -78,9 +81,9 @@ public abstract class CacheJdbcStoreAbstractSelfTest extends GridCommonAbstractT
U.closeQuiet(stmt);
- U.closeQuiet(conn);
+ fillSampleDatabase(conn);
- startGrid();
+ U.closeQuiet(conn);
}
/** {@inheritDoc} */
@@ -153,11 +156,10 @@ public abstract class CacheJdbcStoreAbstractSelfTest extends GridCommonAbstractT
/**
* Fill in-memory database with sample data.
*
+ * @param conn Connection to database.
* @throws SQLException In case of filling database with sample data failed.
*/
- protected void fillSampleDatabase() throws SQLException {
- Connection conn = getConnection();
-
+ protected void fillSampleDatabase(Connection conn) throws SQLException {
PreparedStatement orgStmt = conn.prepareStatement("INSERT INTO Organization(id, name, city) VALUES (?, ?, ?)");
for (int i = 0; i < ORGANIZATION_CNT; i++) {
@@ -189,22 +191,35 @@ public abstract class CacheJdbcStoreAbstractSelfTest extends GridCommonAbstractT
conn.commit();
U.closeQuiet(prnStmt);
-
- U.closeQuiet(conn);
}
/**
* @throws Exception If failed.
*/
public void testLoadCache() throws Exception {
- fillSampleDatabase();
+ primitiveKeys = false;
+
+ startGrid();
IgniteCache<Object, Object> c1 = grid().cache(null);
- info("Cache load started...");
+ c1.loadCache(null);
+
+ assertEquals(ORGANIZATION_CNT + PERSON_CNT, c1.size());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLoadCachePrimitiveKeys() throws Exception {
+ primitiveKeys = true;
+
+ startGrid();
+
+ IgniteCache<Object, Object> c1 = grid().cache(null);
c1.loadCache(null);
- info("Cache load finished!");
+ assertEquals(ORGANIZATION_CNT + PERSON_CNT, c1.size());
}
}