ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject ignite git commit: IGNITE-1753 Reworked hasher. Added some loggin in tests.
Date Fri, 30 Oct 2015 08:25:00 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1753-1282 22961db9e -> 952ecf813


IGNITE-1753 Reworked hasher. Added some loggin in tests.


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

Branch: refs/heads/ignite-1753-1282
Commit: 952ecf81393fe3879cbe36a8f5c13e11c218aacc
Parents: 22961db
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Fri Oct 30 15:25:05 2015 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Fri Oct 30 15:25:05 2015 +0700

----------------------------------------------------------------------
 .../cache/store/jdbc/CacheJdbcPojoStore.java    | 51 ++++----------------
 .../cache/store/jdbc/JdbcTypeDefaultHasher.java |  7 +--
 .../ignite/cache/store/jdbc/JdbcTypeHasher.java |  7 +--
 .../jdbc/CacheJdbcStoreAbstractSelfTest.java    |  8 +++
 4 files changed, 21 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/952ecf81/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 63784c5..7605502 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
@@ -236,16 +236,23 @@ public class CacheJdbcPojoStore<K, V> extends CacheAbstractJdbcStore<K,
V> {
             else {
                 PortableBuilder builder = ignite.portables().builder(tuple.get2());
 
+                boolean calcHash = hashFields != null;
+
+                Collection<Object> hashValues = calcHash ? new ArrayList<>(hashFields.size())
: null;
+
                 for (JdbcTypeField field : fields) {
                     Integer colIdx = loadColIdxs.get(field.getDatabaseFieldName());
 
                     Object colVal = getColumnValue(rs, colIdx, field.getJavaFieldType());
 
                     builder.setField(field.getJavaFieldName(), colVal);
+
+                    if (calcHash)
+                        hashValues.add(colVal);
                 }
 
-                if (hashFields != null)
-                    builder.hashCode(hasher.hashCode(new PortableBuilderWrapper(builder),
hashFields));
+                if (calcHash)
+                    builder.hashCode(hasher.hashCode(hashValues));
 
                 return builder.build();
             }
@@ -373,46 +380,6 @@ public class CacheJdbcPojoStore<K, V> extends CacheAbstractJdbcStore<K,
V> {
     }
 
     /**
-     * Thin wrapper over {@link PortableBuilder} to use it as {@link IgniteObject} for hash
code calculation.
-     */
-    private static class PortableBuilderWrapper implements IgniteObject {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Wrapped builder. */
-        private final PortableBuilder builder;
-
-        /**
-         * Create wrapper.
-         *
-         * @param builder Builder to wrap.
-         */
-        private PortableBuilderWrapper(final PortableBuilder builder) {
-            this.builder = builder;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int typeId() {
-            return 0; // No need to wrap.
-        }
-
-        /** {@inheritDoc} */
-        @Nullable @Override public <F> F field(String fieldName) throws PortableException
{
-            return builder.getField(fieldName);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean hasField(String fieldName) {
-            return false; // No need to wrap.
-        }
-
-        /** {@inheritDoc} */
-        @Nullable @Override public <T> T deserialize() throws PortableException {
-            return null; // No need to wrap.
-        }
-    }
-
-    /**
      * POJO methods cache.
      */
     private static class PojoMethodsCache {

http://git-wip-us.apache.org/repos/asf/ignite/blob/952ecf81/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeDefaultHasher.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeDefaultHasher.java
b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeDefaultHasher.java
index 3c0a330..e7de753 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeDefaultHasher.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeDefaultHasher.java
@@ -34,14 +34,11 @@ public class JdbcTypeDefaultHasher implements JdbcTypeHasher {
     public static final JdbcTypeHasher INSTANCE = new JdbcTypeDefaultHasher();
 
     /** {@inheritDoc} */
-    @Override public int hashCode(IgniteObject obj, Collection<String> fields) {
+    @Override public int hashCode(Collection<?> values) {
         int hash = 0;
 
-        for (String field : fields) {
-            Object val = obj.field(field);
-
+        for (Object val : values)
             hash = 31 * hash + (val != null ? val.hashCode() : 0);
-        }
 
         return hash;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/952ecf81/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeHasher.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeHasher.java
b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeHasher.java
index bb6bbf8..ed35899 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeHasher.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcTypeHasher.java
@@ -17,8 +17,6 @@
 
 package org.apache.ignite.cache.store.jdbc;
 
-import org.apache.ignite.cache.IgniteObject;
-
 import java.io.Serializable;
 import java.util.Collection;
 
@@ -29,9 +27,8 @@ public interface JdbcTypeHasher extends Serializable {
     /**
      * Calculate hash code for specified object and fields.
      *
-     * @param obj Object to calculate hash code for.
-     * @param fields Collection of field names that should participate in hash code calculation.
+     * @param values Collection of values that should participate in hash code calculation.
      * @return Hash code.
      */
-    public int hashCode(IgniteObject obj, Collection<String> fields);
+    public int hashCode(Collection<?> values);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/952ecf81/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 8334077..3f0e794 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
@@ -160,6 +160,8 @@ public abstract class CacheJdbcStoreAbstractSelfTest extends GridCommonAbstractT
      * @throws SQLException In case of filling database with sample data failed.
      */
     protected void fillSampleDatabase(Connection conn) throws SQLException {
+        info("Start to fill sample database...");
+
         PreparedStatement orgStmt = conn.prepareStatement("INSERT INTO Organization(id, name,
city) VALUES (?, ?, ?)");
 
         for (int i = 0; i < ORGANIZATION_CNT; i++) {
@@ -191,6 +193,8 @@ public abstract class CacheJdbcStoreAbstractSelfTest extends GridCommonAbstractT
         conn.commit();
 
         U.closeQuiet(prnStmt);
+
+        info("Sample database prepared.");
     }
 
     /**
@@ -201,6 +205,8 @@ public abstract class CacheJdbcStoreAbstractSelfTest extends GridCommonAbstractT
 
         startGrid();
 
+        info("Execute testLoadCache...");
+
         IgniteCache<Object, Object> c1 = grid().cache(null);
 
         c1.loadCache(null);
@@ -216,6 +222,8 @@ public abstract class CacheJdbcStoreAbstractSelfTest extends GridCommonAbstractT
 
         startGrid();
 
+        info("Execute testLoadCachePrimitiveKeys...");
+
         IgniteCache<Object, Object> c1 = grid().cache(null);
 
         c1.loadCache(null);


Mime
View raw message