ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [09/50] [abbrv] ignite git commit: IGNITE-1951: Safe default type/field ID calculation: zeros are not allowed.
Date Mon, 23 Nov 2015 06:38:37 GMT
IGNITE-1951: Safe default type/field ID calculation: zeros are not allowed.


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

Branch: refs/heads/ignite-sql-opt
Commit: 60b805e6829b7076490bd3727472cc96a216adb3
Parents: d69b177
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Fri Nov 20 10:39:59 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Fri Nov 20 10:39:59 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryInternalIdMapper.java  | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/60b805e6/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
index dd434ff..2b5a53a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.portable;
 
 import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryObjectException;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -79,7 +80,7 @@ public class BinaryInternalIdMapper implements BinaryIdMapper {
     public int typeId(String typeName) {
         assert typeName != null;
 
-        return lowerCaseHashCode(typeName);
+        return lowerCaseHashCode(typeName, true);
     }
 
     /**
@@ -92,16 +93,17 @@ public class BinaryInternalIdMapper implements BinaryIdMapper {
     public int fieldId(int typeId, String fieldName) {
         assert fieldName != null;
 
-        return lowerCaseHashCode(fieldName);
+        return lowerCaseHashCode(fieldName, false);
     }
 
     /**
      * Routine to calculate string hash code an
      *
      * @param str String.
+     * @param type {@code True} if this is type name, false otherwise.
      * @return Hash code for given string converted to lower case.
      */
-    private static int lowerCaseHashCode(String str) {
+    private static int lowerCaseHashCode(String str, boolean type) {
         int len = str.length();
 
         int h = 0;
@@ -114,7 +116,14 @@ public class BinaryInternalIdMapper implements BinaryIdMapper {
             h = 31 * h + c;
         }
 
-        return h;
+        if (h != 0)
+            return h;
+        else {
+            String what = type ? "type" : "field";
+
+            throw new BinaryObjectException("Default binary ID mapper resolved " + what +
" ID to zero " +
+                "(either change " + what + "'s name or use custom ID mapper) [name=" + str
+ ']');
+        }
     }
 
     /**


Mime
View raw message