You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/25 02:17:02 UTC

incubator-ignite git commit: ignite-959

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-959 97e5c62cb -> 165334720


ignite-959


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

Branch: refs/heads/ignite-959
Commit: 1653347203e182ea98a53a26ca4e400e0b461632
Parents: 97e5c62
Author: agura <ag...@gridgain.com>
Authored: Thu Jun 25 03:16:25 2015 +0300
Committer: agura <ag...@gridgain.com>
Committed: Thu Jun 25 03:16:25 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/cache/CacheTypeMetadata.java  | 38 +++++++++-
 .../processors/query/GridQueryProcessor.java    | 79 +++++++++++++++++++-
 2 files changed, 115 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/16533472/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
index d6b0c79..470785b 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.cache;
 
 import org.apache.ignite.internal.util.tostring.*;
+import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 
@@ -43,6 +44,12 @@ public class CacheTypeMetadata implements Serializable {
     /** Value class used to store value in cache. */
     private String valType;
 
+    /** Key type name. */
+    private String keyTypeName;
+
+    /** Value type name. */
+    private String valTypeName;
+
     /** Key fields. */
     @GridToStringInclude
     private Collection<CacheTypeFieldMetadata> keyFields;
@@ -186,6 +193,7 @@ public class CacheTypeMetadata implements Serializable {
      */
     public void setKeyType(Class<?> cls) {
         setKeyType(cls.getName());
+        keyTypeName = typeName(cls);
     }
 
     /**
@@ -212,7 +220,35 @@ public class CacheTypeMetadata implements Serializable {
      * @param cls Value type class.
      */
     public void setValueType(Class<?> cls) {
-        setValueType(cls.getName());
+        setValueType(typeName(cls));
+        valTypeName = typeName(cls);
+    }
+
+    public String getKeyTypeName() {
+        return keyTypeName;
+    }
+
+    public String getValTypeName() {
+        return valTypeName;
+    }
+
+    private static String typeName(Class<?> cls) {
+        String typeName = cls.getSimpleName();
+
+        // To protect from failure on anonymous classes.
+        if (F.isEmpty(typeName)) {
+            String pkg = cls.getPackage().getName();
+
+            typeName = cls.getName().substring(pkg.length() + (pkg.isEmpty() ? 0 : 1));
+        }
+
+        if (cls.isArray()) {
+            assert typeName.endsWith("[]");
+
+            typeName = typeName.substring(0, typeName.length() - 2) + "_array";
+        }
+
+        return typeName;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/16533472/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 19cc9f0..fa34a9e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -408,7 +408,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             Class<?> valCls = U.classForName(meta.getValueType(), null);
 
-            desc.name(valCls != null ? typeName(valCls) : meta.getValueType());
+            //desc.name(valCls != null ? typeName(valCls) : meta.getValueType());
+
+            desc.name(meta.getValTypeName());
 
             desc.valueClass(valCls != null ? valCls : Object.class);
             desc.keyClass(
@@ -1088,6 +1090,65 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         return typeName;
     }
 
+    public static String typeName(String name) {
+        int idx = Math.max(name.lastIndexOf('.'), name.lastIndexOf('$'));
+
+        boolean arr = name.endsWith("[]");
+
+        String typeName = name.substring(idx > -1 ? idx + 1 : 0, arr ? name.length() - 2 : name.length());
+
+        return arr ? typeName + "_array" : typeName;
+    }
+
+    public static void prn(Class<?> cls) {
+        System.out.println("Name: " + cls.getName());
+        System.out.println("Simple name: " + cls.getSimpleName());
+        System.out.println("Canonical name: " + cls.getCanonicalName());
+        System.out.println("Type name:" + typeName(cls));
+        System.out.println();
+    }
+
+    public static void main(String[] args) {
+        //System.out.println(typeName(new HashMap<Long, Long>(){{put(1l, 1l);}}.getClass()));
+        //System.out.println(typeName(new HashMap<Long, Long>(){{put(1l, 1l);}}.getClass().getName()));
+
+        prn(String.class);
+
+        prn(String[].class);
+
+        prn(Map.Entry.class);
+
+        prn(Map.Entry[].class);
+
+        prn(A.B.class);
+
+        prn(A.B.C.class);
+
+        prn(new HashMap<Long, Long>() {{
+            put(1l, 1l);
+        }
+        }.getClass());
+
+        prn(new HashMap<Long, Long>() {{
+            put(1l, 1l);
+        }
+            X x = new X();
+            class X {
+
+            }
+        }.x.getClass());
+
+        prn(new HashMap<Long, Long>() {{
+            put(1l, 1l);
+        }
+            Object x = new HashMap<Long, Long>(){{}};
+        }.x.getClass());
+
+        prn($prb.class);
+
+        prn($p$r$b.class);
+    }
+
     /**
      * @param space Space.
      * @param clause Clause.
@@ -2371,4 +2432,20 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             return S.toString(TypeName.class, this);
         }
     }
+
+    class A {
+        class B {
+            class C {
+
+            }
+        }
+    }
+
+    class $prb {
+
+    }
+
+    class $p$r$b {
+
+    }
 }