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/24 01:57:37 UTC

incubator-ignite git commit: ignite-959 Avoid sending key-value class definitions to servers

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-959 b295f91a8 -> 769d051cf


ignite-959 Avoid sending key-value class definitions to servers


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

Branch: refs/heads/ignite-959
Commit: 769d051cff85de9404ed3e36ad128b880ff051a1
Parents: b295f91
Author: agura <ag...@gridgain.com>
Authored: Wed Jun 24 02:56:41 2015 +0300
Committer: agura <ag...@gridgain.com>
Committed: Wed Jun 24 02:56:41 2015 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    | 79 ++++++++++++++++----
 1 file changed, 63 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/769d051c/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 1b7edac..32ec942 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
@@ -159,8 +159,32 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             meta.setKeyType(keyCls);
             meta.setValueType(valCls);
 
-            processClassAnnotations(keyCls, meta, null);
-            processClassAnnotations(valCls, meta, null);
+            Map<String, TreeMap<Integer, T3<String, Class<?>, Boolean>>> orderedGroups = new HashMap<>();
+
+            processClassAnnotations(keyCls, meta, null, orderedGroups);
+            processClassAnnotations(valCls, meta, null, orderedGroups);
+
+            for (Map.Entry<String, TreeMap<Integer, T3<String, Class<?>, Boolean>>> entry : orderedGroups.entrySet()) {
+                String grp = entry.getKey();
+
+                Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> groups = meta.getGroups();
+
+                LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> fields = groups.get(grp);
+
+                if (fields == null)
+                    groups.put(grp, fields = new LinkedHashMap<>());
+
+                for (Map.Entry<Integer, T3<String, Class<?>, Boolean>> ordFields : entry.getValue().entrySet()) {
+                    String name = ordFields.getValue().get1();
+
+                    Class<?> cls = ordFields.getValue().get2();
+
+                    Boolean desc = ordFields.getValue().get3();
+
+                    if (fields.put(name, new T2<Class<?>, Boolean>(cls, desc)) != null)
+                        throw new IgniteCheckedException("Field " + name + " already exists in group " + grp);
+                }
+            }
 
             metadata.add(meta);
         }
@@ -173,8 +197,10 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param meta Type metadata.
      * @param parentField Parent field name.
      */
-    private void processClassAnnotations(Class<?> cls, CacheTypeMetadata meta, String parentField)
-        throws IgniteCheckedException {
+    private void processClassAnnotations(Class<?> cls, CacheTypeMetadata meta,
+        String parentField, Map<String, TreeMap<Integer, T3<String, Class<?>, Boolean>>> orderedGroups)
+        throws IgniteCheckedException
+    {
         if (U.isJdk(cls) || idx.isGeometryClass(cls))
             return;
 
@@ -197,7 +223,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                     String pathStr = parentField == null ? name : parentField + '.' + name;
 
-                    processClassAnnotations(field.getType(), meta, pathStr);
+                    processClassAnnotations(field.getType(), meta, pathStr, orderedGroups);
 
                     if (sqlAnn.index()) {
                         Map<String, Class<?>> fields =
@@ -215,24 +241,29 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                         for (String grp : sqlAnn.groups()) {
                             LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> fields = meta.getGroups().get(grp);
 
-                            if (fields == null) {
-                                fields = new LinkedHashMap<>();
-
-                                meta.getGroups().put(grp, fields);
-                            }
+                            if (fields == null)
+                                meta.getGroups().put(grp, fields = new LinkedHashMap<>());
 
                             if (fields.put(pathStr, new IgniteBiTuple<Class<?>, Boolean>(field.getType(), false)) != null)
                                 throw new IgniteCheckedException("Field " + pathStr + " already exists in group " + grp);
                         }
                     }
 
-/*
                     if (!F.isEmpty(sqlAnn.orderedGroups())) {
-                        for (QuerySqlField.Group idx : sqlAnn.orderedGroups())
-                            desc.addFieldToIndex(idx.name(), prop.name(), idx.order(), idx.descending());
-                    }
-*/
+                        for (QuerySqlField.Group idx : sqlAnn.orderedGroups()) {
+                            TreeMap<Integer, T3<String, Class<?>, Boolean>> orderedFields = orderedGroups.get(idx.name());
+
+                            if (orderedFields == null)
+                                orderedGroups.put(idx.name(), orderedFields = new TreeMap<>());
 
+                            T3<String, Class<?>, Boolean> grp =
+                                new T3<String, Class<?>, Boolean>(pathStr, field.getType(), idx.descending());
+
+                            if (orderedFields.put(idx.order(), grp) != null)
+                                throw new IgniteCheckedException("Field " + pathStr + " has duplicated order " +
+                                    idx.order() + " in group " + idx.name());
+                        }
+                    }
                 }
             }
 
@@ -263,7 +294,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                         name = parentField == null ? name : parentField + '.' + name;
 
-                        processClassAnnotations(mtd.getReturnType(), meta, name);
+                        processClassAnnotations(mtd.getReturnType(), meta, name, orderedGroups);
 
                         if (sqlAnn.index()) {
                             Map<String, Class<?>> fields =
@@ -291,6 +322,22 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                                     throw new IgniteCheckedException("Field " + name + " already exists in group " + grp);
                             }
                         }
+
+                        if (!F.isEmpty(sqlAnn.orderedGroups())) {
+                            for (QuerySqlField.Group idx : sqlAnn.orderedGroups()) {
+                                TreeMap<Integer, T3<String, Class<?>, Boolean>> orderedFields = orderedGroups.get(idx.name());
+
+                                if (orderedFields == null)
+                                    orderedGroups.put(idx.name(), orderedFields = new TreeMap<>());
+
+                                T3<String, Class<?>, Boolean> grp =
+                                    new T3<String, Class<?>, Boolean>(name, mtd.getReturnType(), idx.descending());
+
+                                if (orderedFields.put(idx.order(), grp) != null)
+                                    throw new IgniteCheckedException("Field " + name + " has duplicated order " +
+                                        idx.order() + " in group " + idx.name());
+                            }
+                        }
                     }
                 }
             }