You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2015/10/23 13:04:04 UTC

[6/9] ignite git commit: ignite-959-x

ignite-959-x


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

Branch: refs/heads/ignite-950-new
Commit: 6a2c2cb3655bb1f61ef2554dcfad763edc37014b
Parents: 8eeee9e
Author: S.Vladykin <sv...@gridgain.com>
Authored: Mon Jul 6 05:25:25 2015 +0300
Committer: S.Vladykin <sv...@gridgain.com>
Committed: Mon Jul 6 05:25:25 2015 +0300

----------------------------------------------------------------------
 .../configuration/CacheConfiguration.java       |  63 +++++----
 .../processors/query/GridQueryProcessor.java    | 133 +++++++++++--------
 2 files changed, 114 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6a2c2cb3/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 e73f51f..9958739 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
@@ -40,6 +40,7 @@ import java.lang.reflect.*;
 import java.util.*;
 
 import static org.apache.ignite.internal.processors.query.GridQueryIndexType.*;
+import static org.apache.ignite.internal.processors.query.GridQueryProcessor.*;
 
 /**
  * This class defines grid cache configuration. This configuration is passed to
@@ -1830,9 +1831,19 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
                 LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> grp = new LinkedHashMap<>();
 
                 for (String fieldName : idx.fields()) {
-                    ClassProperty prop = desc.props.get(fieldName);
+                    Class<?> cls;
 
-                    Class<?> cls = mask(prop.type());
+                    if (_VAL.equals(fieldName))
+                        cls = desc.valueClass();
+                    else {
+                        ClassProperty prop = desc.props.get(fieldName);
+
+                        assert prop != null : fieldName;
+
+                        cls = prop.type();
+                    }
+
+                    cls = mask(cls);
 
                     grp.put(fieldName, new IgniteBiTuple<Class<?>, Boolean>(cls, idx.descending(fieldName)));
                 }
@@ -1841,18 +1852,14 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
             }
         }
 
+        meta.setGroups(grps);
+
         if (desc.valueTextIndex())
-            txtFields.add("_val");
+            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;
 
@@ -1881,7 +1888,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
     private static Class<?> mask(Class<?> cls) {
         assert cls != null;
 
-        return GridQueryProcessor.isSqlType(cls) ? cls : Object.class;
+        return isSqlType(cls) ? cls : Object.class;
     }
 
     /**
@@ -1914,13 +1921,13 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
      */
     private static void processAnnotationsInClass(boolean key, Class<?> cls, TypeDescriptor type,
         @Nullable ClassProperty parent) {
-        if (U.isJdk(cls) || GridQueryProcessor.isGeometryClass(cls)) {
-            if (parent == null && !key && GridQueryProcessor.isSqlType(cls) ) { // We have to index primitive _val.
-                String idxName = "_val_idx";
+        if (U.isJdk(cls) || isGeometryClass(cls)) {
+            if (parent == null && !key && isSqlType(cls)) { // We have to index primitive _val.
+                String idxName = _VAL + "_idx";
 
-                type.addIndex(idxName, GridQueryProcessor.isGeometryClass(cls) ? GEO_SPATIAL : SORTED);
+                type.addIndex(idxName, isGeometryClass(cls) ? GEO_SPATIAL : SORTED);
 
-                type.addFieldToIndex(idxName, "_val", 0, false);
+                type.addFieldToIndex(idxName, _VAL, 0, false);
             }
 
             return;
@@ -1954,7 +1961,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
                 QueryTextField txtAnn = field.getAnnotation(QueryTextField.class);
 
                 if (sqlAnn != null || txtAnn != null) {
-                    ClassProperty prop = new ClassProperty(field, key);
+                    ClassProperty prop = new ClassProperty(field);
 
                     prop.parent(parent);
 
@@ -1973,7 +1980,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
                         throw new CacheException("Getter with QuerySqlField " +
                             "annotation cannot have parameters: " + mtd);
 
-                    ClassProperty prop = new ClassProperty(mtd, key);
+                    ClassProperty prop = new ClassProperty(mtd);
 
                     prop.parent(parent);
 
@@ -2004,26 +2011,26 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
                 prop.alias(sqlAnn.name());
 
             if (sqlAnn.index()) {
-                String idxName = prop.name() + "_idx";
+                String idxName = prop.alias() + "_idx";
 
-                desc.addIndex(idxName, GridQueryProcessor.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+                desc.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
-                desc.addFieldToIndex(idxName, prop.name(), 0, sqlAnn.descending());
+                desc.addFieldToIndex(idxName, prop.fullName(), 0, sqlAnn.descending());
             }
 
             if (!F.isEmpty(sqlAnn.groups())) {
                 for (String group : sqlAnn.groups())
-                    desc.addFieldToIndex(group, prop.name(), 0, false);
+                    desc.addFieldToIndex(group, prop.fullName(), 0, false);
             }
 
             if (!F.isEmpty(sqlAnn.orderedGroups())) {
                 for (QuerySqlField.Group idx : sqlAnn.orderedGroups())
-                    desc.addFieldToIndex(idx.name(), prop.name(), idx.order(), idx.descending());
+                    desc.addFieldToIndex(idx.name(), prop.fullName(), idx.order(), idx.descending());
             }
         }
 
         if (txtAnn != null)
-            desc.addFieldToTextIndex(prop.name());
+            desc.addFieldToTextIndex(prop.fullName());
     }
 
     /** {@inheritDoc} */
@@ -2172,7 +2179,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
          * @param failOnDuplicate Fail on duplicate flag.
          */
         public void addProperty(ClassProperty prop, boolean failOnDuplicate) {
-            String name = prop.name();
+            String name = prop.fullName();
 
             if (props.put(name, prop) != null && failOnDuplicate)
                 throw new CacheException("Property with name '" + name + "' already exists.");
@@ -2297,7 +2304,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
          *
          * @param member Element.
          */
-        ClassProperty(Member member, boolean key) {
+        ClassProperty(Member member) {
             this.member = member;
 
             name = member instanceof Method && member.getName().startsWith("get") && member.getName().length() > 3 ?
@@ -2314,10 +2321,10 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
         }
 
         /**
-         * @return Name.
+         * @return Alias.
          */
-        public String name() {
-            return name;
+        String alias() {
+            return F.isEmpty(alias) ? name : alias;
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/6a2c2cb3/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 afc90e8..bfc7b74 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
@@ -54,6 +54,9 @@ import static org.apache.ignite.internal.processors.query.GridQueryIndexType.*;
  */
 public class GridQueryProcessor extends GridProcessorAdapter {
     /** */
+    public static final String _VAL = "_val";
+
+    /** */
     private static final Class<?> GEOMETRY_CLASS = U.classForName("com.vividsolutions.jts.geom.Geometry", null);
 
     /** */
@@ -1031,52 +1034,14 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         assert keyCls != null;
         assert valCls != null;
 
-        for (Map.Entry<String, Class<?>> entry : meta.getAscendingFields().entrySet()) {
-            ClassProperty prop = buildClassProperty(
-                keyCls,
-                valCls,
-                entry.getKey(),
-                entry.getValue(),
-                aliases);
-
-            d.addProperty(prop, false);
-
-            String idxName = prop.name() + "_idx";
-
-            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()) {
-            ClassProperty prop = buildClassProperty(
-                keyCls,
-                valCls,
-                entry.getKey(),
-                entry.getValue(),
-                aliases);
-
-            d.addProperty(prop, false);
-
-            String idxName = prop.name() + "_idx";
-
-            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
-
-            d.addFieldToIndex(idxName, prop.name(), 0, true);
-        }
-
-        for (String txtIdx : meta.getTextFields()) {
-            ClassProperty prop = buildClassProperty(
-                keyCls,
-                valCls,
-                txtIdx,
-                String.class,
-                aliases);
+        for (Map.Entry<String, Class<?>> entry : meta.getAscendingFields().entrySet())
+            addToIndex(d, keyCls, valCls, entry.getKey(), entry.getValue(), 0, IndexType.ASC, null, aliases);
 
-            d.addProperty(prop, false);
+        for (Map.Entry<String, Class<?>> entry : meta.getDescendingFields().entrySet())
+            addToIndex(d, keyCls, valCls, entry.getKey(), entry.getValue(), 0, IndexType.DESC, null, aliases);
 
-            d.addFieldToTextIndex(prop.name());
-        }
+        for (String txtField : meta.getTextFields())
+            addToIndex(d, keyCls, valCls, txtField, String.class, 0, IndexType.TEXT, null, aliases);
 
         Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> grps = meta.getGroups();
 
@@ -1089,18 +1054,13 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 int order = 0;
 
                 for (Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>> idxField : idxFields.entrySet()) {
-                    ClassProperty prop = buildClassProperty(
-                        keyCls,
-                        valCls,
-                        idxField.getKey(),
-                        idxField.getValue().get1(),
-                        aliases);
-
-                    d.addProperty(prop, false);
-
                     Boolean descending = idxField.getValue().get2();
 
-                    d.addFieldToIndex(idxName, prop.name(), order, descending != null && descending);
+                    if (descending == null)
+                        descending = false;
+
+                    addToIndex(d, keyCls, valCls, idxField.getKey(), idxField.getValue().get1(), order,
+                        descending ? IndexType.DESC : IndexType.ASC, idxName, aliases);
 
                     order++;
                 }
@@ -1120,6 +1080,64 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @param d Type descriptor.
+     * @param keyCls Key class.
+     * @param valCls Value class.
+     * @param pathStr Path string.
+     * @param resType Result type.
+     * @param idxOrder Order number in index or {@code -1} if no need to index.
+     * @param idxType Index type.
+     * @param idxName Index name.
+     * @param aliases Aliases.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void addToIndex(
+        TypeDescriptor d,
+        Class<?> keyCls,
+        Class<?> valCls,
+        String pathStr,
+        Class<?> resType,
+        int idxOrder,
+        IndexType idxType,
+        String idxName,
+        Map<String,String> aliases
+    ) throws IgniteCheckedException {
+        String propName;
+        Class<?> propCls;
+
+        if (_VAL.equals(pathStr)) {
+            propName = _VAL;
+            propCls = valCls;
+        }
+        else {
+            ClassProperty prop = buildClassProperty(
+                keyCls,
+                valCls,
+                pathStr,
+                resType,
+                aliases);
+
+            d.addProperty(prop, false);
+
+            propName = prop.name();
+            propCls = prop.type();
+        }
+
+        if (idxType != null) {
+            if (idxName == null)
+                idxName = propName + "_idx";
+
+            if (idxOrder == 0) // Add index only on the first field.
+                d.addIndex(idxName, isGeometryClass(propCls) ? GEO_SPATIAL : SORTED);
+
+            if (idxType == IndexType.TEXT)
+                d.addFieldToTextIndex(propName);
+            else
+                d.addFieldToIndex(idxName, propName, idxOrder, idxType == IndexType.DESC);
+        }
+    }
+
+    /**
      * Processes declarative metadata for portable object.
      *
      * @param meta Declared metadata.
@@ -1993,4 +2011,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             return S.toString(TypeName.class, this);
         }
     }
+
+    /**
+     * The way to index.
+     */
+    private enum IndexType {
+        ASC, DESC, TEXT
+    }
 }