ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [3/9] ignite git commit: ignite-959-x - wip
Date Fri, 23 Oct 2015 11:04:01 GMT
ignite-959-x - wip


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

Branch: refs/heads/ignite-950-new
Commit: 3f38513fb00b472a5b30be4da61a6838154e5e57
Parents: 9379828
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Tue Jun 30 18:25:33 2015 -0700
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Tue Jun 30 18:25:33 2015 -0700

----------------------------------------------------------------------
 .../apache/ignite/cache/CacheTypeMetadata.java  |  66 +++--
 .../configuration/CacheConfiguration.java       | 260 ++++++++---------
 .../processors/query/GridQueryIndexing.java     |  16 --
 .../processors/query/GridQueryProcessor.java    | 283 ++++++-------------
 .../ignite/internal/util/IgniteUtils.java       |   5 +-
 .../processors/query/h2/IgniteH2Indexing.java   |  17 --
 6 files changed, 254 insertions(+), 393 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3f38513f/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 20129b7..f2b004e 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
@@ -17,10 +17,12 @@
 
 package org.apache.ignite.cache;
 
+import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 
+import javax.cache.*;
 import java.io.*;
 import java.util.*;
 
@@ -43,6 +45,9 @@ public class CacheTypeMetadata implements Serializable {
     /** Value class used to store value in cache. */
     private String valType;
 
+    /** Simple value type name that will be used as SQL table name.*/
+    private String simpleValType;
+
     /** Key fields. */
     @GridToStringInclude
     private Collection<CacheTypeFieldMetadata> keyFields;
@@ -71,22 +76,20 @@ public class CacheTypeMetadata implements Serializable {
     @GridToStringInclude
     private Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>>
grps;
 
+    /** */
+    @GridToStringInclude
+    private Map<String,String> aliases;
+
     /**
      * Default constructor.
      */
     public CacheTypeMetadata() {
         keyFields = new ArrayList<>();
-
         valFields = new ArrayList<>();
-
         qryFlds = new LinkedHashMap<>();
-
         ascFlds = new LinkedHashMap<>();
-
         descFlds = new LinkedHashMap<>();
-
         txtFlds = new LinkedHashSet<>();
-
         grps = new LinkedHashMap<>();
     }
 
@@ -95,25 +98,16 @@ public class CacheTypeMetadata implements Serializable {
      */
     public CacheTypeMetadata(CacheTypeMetadata src) {
         dbSchema = src.getDatabaseSchema();
-
         dbTbl = src.getDatabaseTable();
-
         keyType = src.getKeyType();
-
         valType = src.getValueType();
-
+        simpleValType = src.simpleValType;
         keyFields = new ArrayList<>(src.getKeyFields());
-
         valFields = new ArrayList<>(src.getValueFields());
-
         qryFlds = new LinkedHashMap<>(src.getQueryFields());
-
         ascFlds = new LinkedHashMap<>(src.getAscendingFields());
-
         descFlds = new LinkedHashMap<>(src.getDescendingFields());
-
         txtFlds = new LinkedHashSet<>(src.getTextFields());
-
         grps = new LinkedHashMap<>(src.getGroups());
     }
 
@@ -190,12 +184,28 @@ public class CacheTypeMetadata implements Serializable {
     }
 
     /**
+     * Gets simple value type.
+     *
+     * @return Simple value type.
+     */
+    public String getSimpleValueType() {
+        return simpleValType;
+    }
+
+    /**
      * Sets value type.
      *
      * @param valType Value type.
      */
     public void setValueType(String valType) {
+        if (this.valType != null)
+            throw new CacheException("Value type can be set only once.");
+
         this.valType = valType;
+
+        Class<?> cls = U.classForName(valType, null);
+
+        simpleValType = cls == null ? valType : GridQueryProcessor.typeName(cls);
     }
 
     /**
@@ -276,7 +286,10 @@ public class CacheTypeMetadata implements Serializable {
      * @param ascFlds Map of ascending-indexed fields.
      */
     public void setAscendingFields(Map<String, Class<?>> ascFlds) {
-        this.ascFlds = ascFlds;
+        if (ascFlds == null)
+            this.ascFlds = ascFlds;
+        else
+            this.ascFlds.putAll(ascFlds);
     }
 
     /**
@@ -333,6 +346,25 @@ public class CacheTypeMetadata implements Serializable {
         this.grps = grps;
     }
 
+    /**
+     * Sets mapping from full property name in dot notation to an alias that will be used
as SQL column name.
+     * Example: {"parent.name" -> "parentName"}.
+     *
+     * @param aliases Aliases.
+     */
+    public void setAliases(Map<String,String> aliases) {
+        this.aliases = aliases;
+    }
+
+    /**
+     * Gets aliases mapping.
+     *
+     * @return Aliases.
+     */
+    public Map<String,String> getAliases() {
+        return aliases;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(CacheTypeMetadata.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/3f38513f/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index 50ba040..1f32cf3 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -1798,15 +1798,92 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
      * @param desc Type descriptor.
      * @return Type metadata.
      */
-    private CacheTypeMetadata convert(TypeDescriptor desc) {
+    private static CacheTypeMetadata convert(TypeDescriptor desc) {
         CacheTypeMetadata meta = new CacheTypeMetadata();
 
-        // TODO
+        // Key and val types.
+        meta.setKeyType(desc.keyClass());
+        meta.setValueType(desc.valueClass());
+
+        // Query fields.
+        Map<String, Class<?>> qryFields = new HashMap<>();
+
+        for (ClassProperty prop : desc.props.values())
+            qryFields.put(prop.fullName(), mask(prop.type()));
+
+        meta.setQueryFields(qryFields);
+
+        // Indexes.
+        Collection<String> txtFields = new ArrayList<>();
+        Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>>
grps = new HashMap<>();
+
+        for (Map.Entry<String,GridQueryIndexDescriptor> idxEntry : desc.indexes().entrySet())
{
+            GridQueryIndexDescriptor idx = idxEntry.getValue();
+
+            if (idx.type() == FULLTEXT) {
+                assert txtFields.isEmpty();
+
+                txtFields.addAll(idx.fields());
+            }
+            else {
+                LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>
grp = new LinkedHashMap<>();
+
+                for (String fieldName : idx.fields()) {
+                    ClassProperty prop = desc.props.get(fieldName);
+
+                    Class<?> cls = mask(prop.type());
+
+                    grp.put(fieldName, new IgniteBiTuple<Class<?>, Boolean>(cls,
idx.descending(fieldName)));
+                }
+
+                grps.put(idxEntry.getKey(), grp);
+            }
+        }
+
+        if (desc.valueTextIndex())
+            txtFields.add("_val");
+
+        if (!txtFields.isEmpty())
+            meta.setTextFields(txtFields);
+
+        meta.setGroups(grps);
+
+        // Index primitive types.
+        if (GridQueryProcessor.isSqlType(desc.valueClass()))
+            meta.setAscendingFields(Collections.<String, Class<?>>singletonMap("_val",
desc.valueClass()));
+
+        // Aliases.
+        Map<String,String> aliases = null;
+
+        for (ClassProperty prop : desc.props.values()) {
+            while (prop != null) {
+                if (!F.isEmpty(prop.alias)) {
+                    if (aliases == null)
+                        aliases = new HashMap<>();
+
+                    aliases.put(prop.fullName(), prop.alias);
+                }
+
+                prop = prop.parent;
+            }
+        }
+
+        meta.setAliases(aliases);
 
         return meta;
     }
 
     /**
+     * @param cls Class.
+     * @return Masked class.
+     */
+    private static Class<?> mask(Class<?> cls) {
+        assert cls != null;
+
+        return GridQueryProcessor.isSqlType(cls) ? cls : Object.class;
+    }
+
+    /**
      * @param keyCls Key class.
      * @param valCls Value class.
      * @return Type descriptor.
@@ -1821,11 +1898,6 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
         d.valueClass(valCls);
 
         processAnnotationsInClass(true, d.keyCls, d, null);
-
-        String valTypeName = GridQueryProcessor.typeName(valCls);
-
-        d.name(valTypeName);
-
         processAnnotationsInClass(false, d.valCls, d, null);
 
         return d;
@@ -1847,7 +1919,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
 
                 type.addIndex(idxName, GridQueryProcessor.isGeometryClass(cls) ? GEO_SPATIAL
: SORTED);
 
-                type.addFieldToIndex(idxName, "_VAL", 0, false);
+                type.addFieldToIndex(idxName, "_val", 0, false);
             }
 
             return;
@@ -1928,7 +2000,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
             processAnnotationsInClass(key, cls, desc, prop);
 
             if (!sqlAnn.name().isEmpty())
-                prop.name(sqlAnn.name());
+                prop.alias(sqlAnn.name());
 
             if (sqlAnn.index()) {
                 String idxName = prop.name() + "_idx";
@@ -1979,17 +2051,14 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
     /**
      * Descriptor of type.
      */
-    private static class TypeDescriptor implements GridQueryTypeDescriptor {
-        /** */
-        private String name;
-
+    private static class TypeDescriptor {
         /** Value field names and types with preserved order. */
         @GridToStringInclude
         private final Map<String, Class<?>> fields = new LinkedHashMap<>();
 
         /** */
         @GridToStringExclude
-        private final Map<String, Property> props = new HashMap<>();
+        private final Map<String, ClassProperty> props = new HashMap<>();
 
         /** */
         @GridToStringInclude
@@ -2007,57 +2076,10 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
         /** */
         private boolean valTextIdx;
 
-        /** SPI can decide not to register this type. */
-        private boolean registered;
-
-        /**
-         * @return {@code True} if type registration in SPI was finished and type was not
rejected.
-         */
-        boolean registered() {
-            return registered;
-        }
-
         /**
-         * @param registered Sets registered flag.
+         * @return Indexes.
          */
-        void registered(boolean registered) {
-            this.registered = registered;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String name() {
-            return name;
-        }
-
-        /**
-         * Sets type name.
-         *
-         * @param name Name.
-         */
-        void name(String name) {
-            this.name = name;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Map<String, Class<?>> fields() {
-            return fields;
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings("unchecked")
-        @Override public <T> T value(String field, Object key, Object val) throws IgniteCheckedException
{
-            assert field != null;
-
-            Property prop = props.get(field);
-
-            if (prop == null)
-                throw new IgniteCheckedException("Failed to find field '" + field + "' in
type '" + name + "'.");
-
-            return (T)prop.value(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Map<String, GridQueryIndexDescriptor> indexes() {
+        public Map<String, GridQueryIndexDescriptor> indexes() {
             return Collections.<String, GridQueryIndexDescriptor>unmodifiableMap(indexes);
         }
 
@@ -2110,8 +2132,10 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
             fullTextIdx.addField(field, 0, false);
         }
 
-        /** {@inheritDoc} */
-        @Override public Class<?> valueClass() {
+        /**
+         * @return Value class.
+         */
+        public Class<?> valueClass() {
             return valCls;
         }
 
@@ -2124,8 +2148,10 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
             this.valCls = valCls;
         }
 
-        /** {@inheritDoc} */
-        @Override public Class<?> keyClass() {
+        /**
+         * @return Key class.
+         */
+        public Class<?> keyClass() {
             return keyCls;
         }
 
@@ -2144,7 +2170,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
          * @param prop Property.
          * @param failOnDuplicate Fail on duplicate flag.
          */
-        public void addProperty(Property prop, boolean failOnDuplicate) {
+        public void addProperty(ClassProperty prop, boolean failOnDuplicate) {
             String name = prop.name();
 
             if (props.put(name, prop) != null && failOnDuplicate)
@@ -2153,8 +2179,10 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
             fields.put(name, prop.type());
         }
 
-        /** {@inheritDoc} */
-        @Override public boolean valueTextIndex() {
+        /**
+         * @return {@code true} If we need to have a fulltext index on value.
+         */
+        public boolean valueTextIndex() {
             return valTextIdx;
         }
 
@@ -2248,34 +2276,9 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
     }
 
     /**
-     *
-     */
-    private abstract static class Property {
-        /**
-         * Gets this property value from the given object.
-         *
-         * @param key Key.
-         * @param val Value.
-         * @return Property value.
-         * @throws IgniteCheckedException If failed.
-         */
-        public abstract Object value(Object key, Object val) throws IgniteCheckedException;
-
-        /**
-         * @return Property name.
-         */
-        public abstract String name();
-
-        /**
-         * @return Class member type.
-         */
-        public abstract Class<?> type();
-    }
-
-    /**
      * Description of type property.
      */
-    private static class ClassProperty extends Property {
+    private static class ClassProperty {
         /** */
         private final Member member;
 
@@ -2286,10 +2289,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
         private String name;
 
         /** */
-        private boolean field;
-
-        /** */
-        private boolean key;
+        private String alias;
 
         /**
          * Constructor.
@@ -2298,57 +2298,31 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
          */
         ClassProperty(Member member, boolean key) {
             this.member = member;
-            this.key = key;
 
             name = member instanceof Method && member.getName().startsWith("get")
&& member.getName().length() > 3 ?
                 member.getName().substring(3) : member.getName();
 
             ((AccessibleObject) member).setAccessible(true);
-
-            field = member instanceof Field;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object value(Object key, Object val) throws IgniteCheckedException
{
-            Object x = this.key ? key : val;
-
-            if (parent != null)
-                x = parent.value(key, val);
-
-            if (x == null)
-                return null;
-
-            try {
-                if (field) {
-                    Field field = (Field)member;
-
-                    return field.get(x);
-                }
-                else {
-                    Method mtd = (Method)member;
-
-                    return mtd.invoke(x);
-                }
-            }
-            catch (Exception e) {
-                throw new IgniteCheckedException(e);
-            }
         }
 
         /**
-         * @param name Property name.
+         * @param alias Alias.
          */
-        public void name(String name) {
-            this.name = name;
+        public void alias(String alias) {
+            this.alias = alias;
         }
 
-        /** {@inheritDoc} */
-        @Override public String name() {
+        /**
+         * @return Name.
+         */
+        public String name() {
             return name;
         }
 
-        /** {@inheritDoc} */
-        @Override public Class<?> type() {
+        /**
+         * @return Type.
+         */
+        public Class<?> type() {
             return member instanceof Field ? ((Field)member).getType() : ((Method)member).getReturnType();
         }
 
@@ -2371,5 +2345,17 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
         public boolean knowsClass(Class<?> cls) {
             return member.getDeclaringClass() == cls || (parent != null && parent.knowsClass(cls));
         }
+
+        /**
+         * @return Full name with all parents in dot notation.
+         */
+        public String fullName() {
+            assert name != null;
+
+            if (parent == null)
+                return name;
+
+            return parent.fullName() + '.' + name;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/3f38513f/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index 0cbb77a..fd5de66 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@ -151,22 +151,6 @@ public interface GridQueryIndexing {
     public void unregisterCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException;
 
     /**
-     * Checks if the given class can be mapped to a simple SQL type.
-     *
-     * @param cls Class.
-     * @return {@code true} If can.
-     */
-    public boolean isSqlType(Class<?> cls);
-
-    /**
-     * Checks if the given class is GEOMETRY.
-     *
-     * @param cls Class.
-     * @return {@code true} If this is geometry.
-     */
-    public boolean isGeometryClass(Class<?> cls);
-
-    /**
      * Registers type if it was not known before or updates it otherwise.
      *
      * @param spaceName Space name.

http://git-wip-us.apache.org/repos/asf/ignite/blob/3f38513f/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 f6cff33..afc90e8 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
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.processors.query;
 import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.query.*;
-import org.apache.ignite.cache.query.annotations.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
@@ -152,9 +151,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                     TypeDescriptor desc = new TypeDescriptor();
 
+                    // Key and value classes still can be available if they are primitive
or JDK part.
+                    // We need that to set correct types for _key and _val columns.
                     Class<?> valCls = U.classForName(meta.getValueType(), null);
 
-                    desc.name(valCls != null ? typeName(valCls) : meta.getValueType());
+                    desc.name(meta.getSimpleValueType());
 
                     desc.valueClass(valCls != null ? valCls : Object.class);
                     desc.keyClass(
@@ -182,21 +183,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 }
             }
 
-            Class<?>[] clss = ccfg.getIndexedTypes();
-
-            if (!F.isEmpty(clss)) {
-                for (int i = 0; i < clss.length; i += 2) {
-                    Class<?> keyCls = clss[i];
-                    Class<?> valCls = clss[i + 1];
-
-                    TypeDescriptor desc = processKeyAndValueClasses(keyCls, valCls);
-
-                    addTypeByName(ccfg, desc);
-                    types.put(new TypeId(ccfg.getName(), valCls), desc);
-
-                    desc.registered(idx.registerType(ccfg.getName(), desc));
-                }
-            }
+            // Indexed types must be translated to CacheTypeMetadata in CacheConfiguration.
         }
         catch (IgniteCheckedException | RuntimeException e) {
             idx.unregisterCache(ccfg);
@@ -216,33 +203,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 "in cache '" + ccfg.getName() + "'.");
     }
 
-    /**
-     * @param keyCls Key class.
-     * @param valCls Value class.
-     * @return Type descriptor.
-     * @throws IgniteCheckedException If failed.
-     */
-    private TypeDescriptor processKeyAndValueClasses(
-        Class<?> keyCls,
-        Class<?> valCls
-    )
-        throws IgniteCheckedException {
-        TypeDescriptor d = new TypeDescriptor();
-
-        d.keyClass(keyCls);
-        d.valueClass(valCls);
-
-        processAnnotationsInClass(true, d.keyCls, d, null);
-
-        String valTypeName = typeName(valCls);
-
-        d.name(valTypeName);
-
-        processAnnotationsInClass(false, d.valCls, d, null);
-
-        return d;
-    }
-
     /** {@inheritDoc} */
     @Override public void onKernalStop(boolean cancel) {
         super.onKernalStop(cancel);
@@ -831,7 +791,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @return {@code true} If can.
      */
     public static boolean isSqlType(Class<?> cls) {
-        return SQL_TYPES.contains(cls);
+        cls = U.box(cls);
+
+        return SQL_TYPES.contains(cls) || isGeometryClass(cls);
     }
 
     /**
@@ -1050,130 +1012,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * Process annotations for class.
-     *
-     * @param key If given class relates to key.
-     * @param cls Class.
-     * @param type Type descriptor.
-     * @param parent Parent in case of embeddable.
-     * @throws IgniteCheckedException In case of error.
-     */
-    private void processAnnotationsInClass(boolean key, Class<?> cls, TypeDescriptor
type,
-        @Nullable ClassProperty parent) throws IgniteCheckedException {
-        if (U.isJdk(cls) || idx.isGeometryClass(cls)) {
-            if (parent == null && !key && idx.isSqlType(cls) ) { // We have
to index primitive _val.
-                String idxName = "_val_idx";
-
-                type.addIndex(idxName, idx.isGeometryClass(cls) ? GEO_SPATIAL : SORTED);
-
-                type.addFieldToIndex(idxName, "_VAL", 0, false);
-            }
-
-            return;
-        }
-
-        if (parent != null && parent.knowsClass(cls))
-            throw new IgniteCheckedException("Recursive reference found in type: " + cls.getName());
-
-        if (parent == null) { // Check class annotation at top level only.
-            QueryTextField txtAnnCls = cls.getAnnotation(QueryTextField.class);
-
-            if (txtAnnCls != null)
-                type.valueTextIndex(true);
-
-            QueryGroupIndex grpIdx = cls.getAnnotation(QueryGroupIndex.class);
-
-            if (grpIdx != null)
-                type.addIndex(grpIdx.name(), SORTED);
-
-            QueryGroupIndex.List grpIdxList = cls.getAnnotation(QueryGroupIndex.List.class);
-
-            if (grpIdxList != null && !F.isEmpty(grpIdxList.value())) {
-                for (QueryGroupIndex idx : grpIdxList.value())
-                    type.addIndex(idx.name(), SORTED);
-            }
-        }
-
-        for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass())
{
-            for (Field field : c.getDeclaredFields()) {
-                QuerySqlField sqlAnn = field.getAnnotation(QuerySqlField.class);
-                QueryTextField txtAnn = field.getAnnotation(QueryTextField.class);
-
-                if (sqlAnn != null || txtAnn != null) {
-                    ClassProperty prop = new ClassProperty(field, key);
-
-                    prop.parent(parent);
-
-                    processAnnotation(key, sqlAnn, txtAnn, field.getType(), prop, type);
-
-                    type.addProperty(prop, true);
-                }
-            }
-
-            for (Method mtd : c.getDeclaredMethods()) {
-                QuerySqlField sqlAnn = mtd.getAnnotation(QuerySqlField.class);
-                QueryTextField txtAnn = mtd.getAnnotation(QueryTextField.class);
-
-                if (sqlAnn != null || txtAnn != null) {
-                    if (mtd.getParameterTypes().length != 0)
-                        throw new IgniteCheckedException("Getter with QuerySqlField " +
-                            "annotation cannot have parameters: " + mtd);
-
-                    ClassProperty prop = new ClassProperty(mtd, key);
-
-                    prop.parent(parent);
-
-                    processAnnotation(key, sqlAnn, txtAnn, mtd.getReturnType(), prop, type);
-
-                    type.addProperty(prop, true);
-                }
-            }
-        }
-    }
-
-    /**
-     * Processes annotation at field or method.
-     *
-     * @param key If given class relates to key.
-     * @param sqlAnn SQL annotation, can be {@code null}.
-     * @param txtAnn H2 text annotation, can be {@code null}.
-     * @param cls Class of field or return type for method.
-     * @param prop Current property.
-     * @param desc Class description.
-     * @throws IgniteCheckedException In case of error.
-     */
-    private void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTextField txtAnn,
-        Class<?> cls, ClassProperty prop, TypeDescriptor desc) throws IgniteCheckedException
{
-        if (sqlAnn != null) {
-            processAnnotationsInClass(key, cls, desc, prop);
-
-            if (!sqlAnn.name().isEmpty())
-                prop.name(sqlAnn.name());
-
-            if (sqlAnn.index()) {
-                String idxName = prop.name() + "_idx";
-
-                desc.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
-
-                desc.addFieldToIndex(idxName, prop.name(), 0, sqlAnn.descending());
-            }
-
-            if (!F.isEmpty(sqlAnn.groups())) {
-                for (String group : sqlAnn.groups())
-                    desc.addFieldToIndex(group, prop.name(), 0, false);
-            }
-
-            if (!F.isEmpty(sqlAnn.orderedGroups())) {
-                for (QuerySqlField.Group idx : sqlAnn.orderedGroups())
-                    desc.addFieldToIndex(idx.name(), prop.name(), idx.order(), idx.descending());
-            }
-        }
-
-        if (txtAnn != null)
-            desc.addFieldToTextIndex(prop.name());
-    }
-
-    /**
      * Processes declarative metadata for class.
      *
      * @param meta Type metadata.
@@ -1182,6 +1020,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      */
     private void processClassMeta(CacheTypeMetadata meta, TypeDescriptor d)
         throws IgniteCheckedException {
+        Map<String,String> aliases = meta.getAliases();
+
+        if (aliases == null)
+            aliases = Collections.emptyMap();
+
         Class<?> keyCls = d.keyClass();
         Class<?> valCls = d.valueClass();
 
@@ -1193,13 +1036,14 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 keyCls,
                 valCls,
                 entry.getKey(),
-                entry.getValue());
+                entry.getValue(),
+                aliases);
 
             d.addProperty(prop, false);
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, false);
         }
@@ -1209,13 +1053,14 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 keyCls,
                 valCls,
                 entry.getKey(),
-                entry.getValue());
+                entry.getValue(),
+                aliases);
 
             d.addProperty(prop, false);
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, true);
         }
@@ -1225,7 +1070,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 keyCls,
                 valCls,
                 txtIdx,
-                String.class);
+                String.class,
+                aliases);
 
             d.addProperty(prop, false);
 
@@ -1247,7 +1093,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                         keyCls,
                         valCls,
                         idxField.getKey(),
-                        idxField.getValue().get1());
+                        idxField.getValue().get1(),
+                        aliases);
 
                     d.addProperty(prop, false);
 
@@ -1265,7 +1112,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 keyCls,
                 valCls,
                 entry.getKey(),
-                entry.getValue());
+                entry.getValue(),
+                aliases);
 
             d.addProperty(prop, false);
         }
@@ -1280,32 +1128,37 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      */
     private void processPortableMeta(CacheTypeMetadata meta, TypeDescriptor d)
         throws IgniteCheckedException {
+        Map<String,String> aliases = meta.getAliases();
+
+        if (aliases == null)
+            aliases = Collections.emptyMap();
+
         for (Map.Entry<String, Class<?>> entry : meta.getAscendingFields().entrySet())
{
-            PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue());
+            PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue(),
aliases);
 
             d.addProperty(prop, false);
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, false);
         }
 
         for (Map.Entry<String, Class<?>> entry : meta.getDescendingFields().entrySet())
{
-            PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue());
+            PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue(),
aliases);
 
             d.addProperty(prop, false);
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, true);
         }
 
         for (String txtIdx : meta.getTextFields()) {
-            PortableProperty prop = buildPortableProperty(txtIdx, String.class);
+            PortableProperty prop = buildPortableProperty(txtIdx, String.class, aliases);
 
             d.addProperty(prop, false);
 
@@ -1323,7 +1176,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 int order = 0;
 
                 for (Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>>
idxField : idxFields.entrySet()) {
-                    PortableProperty prop = buildPortableProperty(idxField.getKey(), idxField.getValue().get1());
+                    PortableProperty prop = buildPortableProperty(idxField.getKey(), idxField.getValue().get1(),
aliases);
 
                     d.addProperty(prop, false);
 
@@ -1337,7 +1190,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }
 
         for (Map.Entry<String, Class<?>> entry : meta.getQueryFields().entrySet())
{
-            PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue());
+            PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue(),
aliases);
 
             if (!d.props.containsKey(prop.name()))
                 d.addProperty(prop, false);
@@ -1350,15 +1203,26 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param pathStr String representing path to the property. May contains dots '.' to
identify
      *      nested fields.
      * @param resType Result type.
+     * @param aliases Aliases.
      * @return Portable property.
      */
-    private PortableProperty buildPortableProperty(String pathStr, Class<?> resType)
{
+    private PortableProperty buildPortableProperty(String pathStr, Class<?> resType,
Map<String,String> aliases) {
         String[] path = pathStr.split("\\.");
 
         PortableProperty res = null;
 
-        for (String prop : path)
-            res = new PortableProperty(prop, res, resType);
+        StringBuilder fullName = new StringBuilder();
+
+        for (String prop : path) {
+            if (fullName.length() != 0)
+                fullName.append('.');
+
+            fullName.append(prop);
+
+            String alias = aliases.get(fullName.toString());
+
+            res = new PortableProperty(prop, res, resType, alias);
+        }
 
         return res;
     }
@@ -1368,19 +1232,21 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param valCls Value class.
      * @param pathStr Path string.
      * @param resType Result type.
+     * @param aliases Aliases.
      * @return Class property.
      * @throws IgniteCheckedException If failed.
      */
-    private static ClassProperty buildClassProperty(Class<?> keyCls, Class<?>
valCls, String pathStr, Class<?> resType)
-        throws IgniteCheckedException {
+    private static ClassProperty buildClassProperty(Class<?> keyCls, Class<?>
valCls, String pathStr, Class<?> resType,
+        Map<String,String> aliases) throws IgniteCheckedException {
         ClassProperty res = buildClassProperty(
             true,
             keyCls,
             pathStr,
-            resType);
+            resType,
+            aliases);
 
         if (res == null) // We check key before value consistently with PortableProperty.
-            res = buildClassProperty(false, valCls, pathStr, resType);
+            res = buildClassProperty(false, valCls, pathStr, resType, aliases);
 
         if (res == null)
             throw new IgniteCheckedException("Failed to initialize property '" + pathStr
+ "' for " +
@@ -1395,16 +1261,27 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param cls Source type class.
      * @param pathStr String representing path to the property. May contains dots '.' to
identify nested fields.
      * @param resType Expected result type.
+     * @param aliases Aliases.
      * @return Property instance corresponding to the given path.
      * @throws IgniteCheckedException If property cannot be created.
      */
-    static ClassProperty buildClassProperty(boolean key, Class<?> cls, String pathStr,
Class<?> resType)
+    static ClassProperty buildClassProperty(boolean key, Class<?> cls, String pathStr,
Class<?> resType,
+        Map<String,String> aliases)
         throws IgniteCheckedException {
         String[] path = pathStr.split("\\.");
 
         ClassProperty res = null;
 
+        StringBuilder fullName = new StringBuilder();
+
         for (String prop : path) {
+            if (fullName.length() != 0)
+                fullName.append('.');
+
+            fullName.append(prop);
+
+            String alias = aliases.get(fullName.toString());
+
             ClassProperty tmp;
 
             try {
@@ -1414,11 +1291,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                 bld.setCharAt(3, Character.toUpperCase(bld.charAt(3)));
 
-                tmp = new ClassProperty(cls.getMethod(bld.toString()), key);
+                tmp = new ClassProperty(cls.getMethod(bld.toString()), key, alias);
             }
             catch (NoSuchMethodException ignore) {
                 try {
-                    tmp = new ClassProperty(cls.getDeclaredField(prop), key);
+                    tmp = new ClassProperty(cls.getDeclaredField(prop), key, alias);
                 }
                 catch (NoSuchFieldException ignored) {
                     return null;
@@ -1577,11 +1454,12 @@ public class GridQueryProcessor extends GridProcessorAdapter {
          *
          * @param member Element.
          */
-        ClassProperty(Member member, boolean key) {
+        ClassProperty(Member member, boolean key, String name) {
             this.member = member;
             this.key = key;
 
-            name = member instanceof Method && member.getName().startsWith("get")
&& member.getName().length() > 3 ?
+            this.name = !F.isEmpty(name) ? name :
+                member instanceof Method && member.getName().startsWith("get") &&
member.getName().length() > 3 ?
                 member.getName().substring(3) : member.getName();
 
             ((AccessibleObject) member).setAccessible(true);
@@ -1616,13 +1494,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             }
         }
 
-        /**
-         * @param name Property name.
-         */
-        public void name(String name) {
-            this.name = name;
-        }
-
         /** {@inheritDoc} */
         @Override public String name() {
             return name;
@@ -1661,6 +1532,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         /** Property name. */
         private String propName;
 
+        /** */
+        private String alias;
+
         /** Parent property. */
         private PortableProperty parent;
 
@@ -1677,8 +1551,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
          * @param parent Parent property.
          * @param type Result type.
          */
-        private PortableProperty(String propName, PortableProperty parent, Class<?>
type) {
+        private PortableProperty(String propName, PortableProperty parent, Class<?>
type, String alias) {
             this.propName = propName;
+            this.alias = F.isEmpty(alias) ? propName : alias;
             this.parent = parent;
             this.type = type;
         }
@@ -1723,7 +1598,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
         /** {@inheritDoc} */
         @Override public String name() {
-            return propName;
+            return alias;
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/3f38513f/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index 6623e85..e5e93c3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -7872,9 +7872,10 @@ public abstract class IgniteUtils {
         if (cls == null)
             return null;
 
-        Class<?> boxed = boxedClsMap.get(cls);
+        if (!cls.isPrimitive())
+            return cls;
 
-        return boxed != null ? boxed : cls;
+        return boxedClsMap.get(cls);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/3f38513f/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 359341a..dfa1e5d 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -1483,23 +1483,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
     }
 
-    /** {@inheritDoc} */
-    @Override public boolean isSqlType(Class<?> cls) {
-        switch (DBTypeEnum.fromClass(cls)) {
-            case OTHER:
-            case ARRAY:
-                return false;
-
-            default:
-                return true;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isGeometryClass(Class<?> cls) {
-        return DataType.isGeometryClass(cls);
-    }
-
     /**
      * Enum that helps to map java types to database types.
      */


Mime
View raw message