ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [10/50] incubator-ignite git commit: # IGNITE-330 Added code generation for query fields. Remember choice -> Apply to all.
Date Tue, 24 Mar 2015 17:47:21 GMT
# IGNITE-330 Added code generation for query fields. Remember choice -> Apply to all.


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

Branch: refs/heads/ignite-45-ipc-debug
Commit: fac29f0e6e28c5b6f0d6c15643963a4165907a54
Parents: 90b6303
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Tue Mar 24 17:07:56 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Tue Mar 24 17:07:56 2015 +0700

----------------------------------------------------------------------
 .../ignite/schema/generator/CodeGenerator.java  | 125 +++++++++++++++++--
 .../ignite/schema/generator/XmlGenerator.java   |  12 +-
 .../apache/ignite/schema/model/IndexItem.java   |  16 +--
 .../ignite/schema/model/PojoDescriptor.java     |  16 +--
 .../ignite/schema/ui/ConfirmCallable.java       |   2 +-
 .../org/apache/ignite/schema/ui/MessageBox.java |  21 ++--
 6 files changed, 148 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fac29f0e/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
index 07ab422..861c6fd 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
@@ -109,13 +109,19 @@ public class CodeGenerator {
     }
 
     /**
+     * @param type Full type name.
+     * @return Field java type name.
+     */
+    private static String javaTypeName(String type) {
+        return type.startsWith("java.lang.") ? type.substring(10) : type;
+    }
+
+    /**
      * @param field POJO field descriptor.
      * @return Field java type name.
      */
     private static String javaTypeName(PojoField field) {
-        String javaTypeName = field.javaTypeName();
-
-        return javaTypeName.startsWith("java.lang.") ? javaTypeName.substring(10) : javaTypeName;
+        return javaTypeName(field.javaTypeName());
     }
 
     /**
@@ -478,6 +484,32 @@ public class CodeGenerator {
     }
 
     /**
+     * Add query fields.
+     *
+     * @param src Source code lines.
+     * @param fields List of fields to add.
+     * @param varName Variable name to generate.
+     * @param mtdName Method name to generate.
+     * @param comment Commentary text.
+     * @param first {@code true} if varable should be declared.
+     */
+    private static void addQueryFields(Collection<String> src, Collection<PojoField>
fields, String varName,
+        String mtdName, String comment, boolean first) {
+        if (!fields.isEmpty()) {
+            add2(src, comment);
+            add2(src, (first ? "Map<String, Class<?>> " : "") + varName + " =
new LinkedHashMap<>();");
+            add0(src, "");
+
+            for (PojoField field : fields)
+                add2(src, varName + ".put(\"" + field.javaName() + "\", " + javaTypeName(field)
+ ".class);");
+
+            add0(src, "");
+            add2(src, "type." + mtdName + "(" + varName + ");");
+            add0(src, "");
+        }
+    }
+
+    /**
      * Generate java snippet for cache configuration with JDBC store and types metadata.
      *
      * @param pojos POJO descriptors.
@@ -506,14 +538,15 @@ public class CodeGenerator {
         Collection<String> src = new ArrayList<>(256);
 
         header(src, pkg, "org.apache.ignite.cache.*;org.apache.ignite.cache.store.*;" +
-                "org.apache.ignite.configuration.*;;javax.cache.configuration.*;java.sql.*;java.util.*",
+                "org.apache.ignite.configuration.*;org.apache.ignite.lang.*;;" +
+                "javax.cache.configuration.*;java.sql.*;java.util.*",
             "CacheConfig", "CacheConfig");
 
         add1(src, "/**");
-        add1(src, "/* Configure cache.");
-        add1(src, "/*");
-        add1(src, "/* @param name Cache name.");
-        add1(src, "/* @param storeFactory Cache store factory.");
+        add1(src, "* Configure cache.");
+        add1(src, "*");
+        add1(src, "* @param name Cache name.");
+        add1(src, "* @param storeFactory Cache store factory.");
         add1(src, "*/");
         add1(src, " public static CacheConfiguration cache(String name, Factory<CacheStore>
storeFactory) {");
         add2(src, "if (storeFactory == null)");
@@ -537,32 +570,100 @@ public class CodeGenerator {
 
             add2(src, "// " + tbl + ".");
             add2(src, (first ? "CacheTypeMetadata " : "") + "type = new CacheTypeMetadata();");
+            add0(src, "");
+            add2(src, "meta.add(type);");
+            add0(src, "");
+
+            // Database info.
             add2(src, "type.setDatabaseSchema(\"" + pojo.schema() + "\");");
             add2(src, "type.setDatabaseTable(\"" + tbl + "\");");
+
+            // Java info.
             add2(src, "type.setKeyType(" + pojo.keyClassName() + ".class.getName());");
             add2(src, "type.setValueType(" + pojo.valueClassName() + ".class.getName());");
             add0(src, "");
 
-            add2(src, "meta.add(type);");
-            add0(src, "");
-
+            // Key fields.
             add2(src, "// Key fields for " + tbl + ".");
             add2(src, (first ? "Collection<CacheTypeFieldMetadata> " : "") + "keys
= new ArrayList<>();");
             addFields(src, "keys", pojo.keyFields());
             add2(src, "type.setKeyFields(keys);");
             add0(src, "");
 
+            // Value fields.
             add2(src, "// Value fields for " + tbl + ".");
             add2(src, (first ? "Collection<CacheTypeFieldMetadata> " : "") + "vals
= new ArrayList<>();");
             addFields(src, "vals", pojo.valueFields(includeKeys));
             add2(src, "type.setValueFields(vals);");
             add0(src, "");
 
+            // Query fields.
+            addQueryFields(src, pojo.fields(), "qryFlds", "setQueryFields", "// Query fields
for " + tbl + ".", first);
+
+            // Ascending fields.
+            addQueryFields(src, pojo.ascendingFields(), "ascFlds", "setAscendingFields",
+                "// Ascending fields for " + tbl + ".", first);
+
+            // Descending fields.
+            addQueryFields(src, pojo.descendingFields(), "descFlds", "setDescendingFields",
+                "// Descending fields for " + tbl + ".", first);
+
+            // Groups.
+            Map<String, Map<String, IndexItem>> groups = pojo.groups();
+
+            if (!groups.isEmpty()) {
+                add2(src, "// Groups for " + tbl + ".");
+                add2(src, (first ? "Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>,
Boolean>>> " : "") +
+                    " grps = new LinkedHashMap<>();");
+                add0(src, "");
+
+                for (Map.Entry<String, Map<String, IndexItem>> group : groups.entrySet())
{
+                    add2(src, (first ? "LinkedHashMap<String, IgniteBiTuple<Class<?>,
Boolean>> " : "") +
+                            "grpItems = new LinkedHashMap<>();");
+                    add0(src, "");
+
+                    for (Map.Entry<String, IndexItem> grpItem : group.getValue().entrySet())
{
+                        IndexItem idxCol = grpItem.getValue();
+
+                        add2(src, "grpItems.put(\"" + grpItem.getKey() + "\", " +
+                            "new IgniteBiTuple<>(" + javaTypeName(idxCol.type()) +
".class, " +
+                            idxCol.descending() + "));");
+                    }
+
+                    add0(src, "");
+                    add2(src, "grps.put(\"" + group.getKey() + "\", grpItems);");
+                }
+
+                add2(src, "ccfg.setTypeMetadata(meta);");
+                add0(src, "");
+            }
+
             first = false;
         }
 
-        add2(src, "ccfg.setTypeMetadata(meta);");
+        add2(src, "type.setGroups(grps);");
         add0(src, "");
+
+        // Generate Indexed types.
+        StringBuilder indexedTypes = new StringBuilder(pojos.size() * 15);
+
+        first = true;
+
+        for (PojoDescriptor pojo : pojos) {
+            if (!first)
+                indexedTypes.append(", ");
+
+            indexedTypes
+                .append(pojo.keyClassName()).append(".class, ")
+                .append(pojo.valueClassName()).append(".class");
+
+            first = false;
+        }
+
+        add2(src, "// Indexed types.");
+        add2(src, "ccfg.setIndexedTypes(" + indexedTypes + ");");
+        add0(src, "");
+
         add2(src, "return ccfg;");
         add1(src, "}");
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fac29f0e/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
index 85b9275..6ab04dd 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
@@ -205,17 +205,17 @@ public class XmlGenerator {
 
                 Element val1 = addElement(doc, entry1, "map");
 
-                Map<String, IndexItem> fields = group.getValue();
+                Map<String, IndexItem> grpItems = group.getValue();
 
-                for (Map.Entry<String, IndexItem> field : fields.entrySet()) {
-                    Element entry2 = addElement(doc, val1, "entry", "key", field.getKey());
+                for (Map.Entry<String, IndexItem> grpItem : grpItems.entrySet()) {
+                    Element entry2 = addElement(doc, val1, "entry", "key", grpItem.getKey());
 
                     Element val2 = addBean(doc, entry2, IgniteBiTuple.class);
 
-                    IndexItem idx = field.getValue();
+                    IndexItem idxCol = grpItem.getValue();
 
-                    addElement(doc, val2, "constructor-arg", null, null, "value", idx.name());
-                    addElement(doc, val2, "constructor-arg", null, null, "value", String.valueOf(idx.descending()));
+                    addElement(doc, val2, "constructor-arg", null, null, "value", idxCol.type());
+                    addElement(doc, val2, "constructor-arg", null, null, "value", String.valueOf(idxCol.descending()));
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fac29f0e/modules/schema-import/src/main/java/org/apache/ignite/schema/model/IndexItem.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/IndexItem.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/model/IndexItem.java
index 1a0868d..4e00260 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/IndexItem.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/model/IndexItem.java
@@ -21,8 +21,8 @@ package org.apache.ignite.schema.model;
  * Index item descriptor.
  */
 public class IndexItem {
-    /** Column name. */
-    private final String name;
+    /** Column type. */
+    private final String type;
 
     /** Sort direction. */
     private final Boolean desc;
@@ -30,19 +30,19 @@ public class IndexItem {
     /**
      * Constructor.
      *
-     * @param name Column name.
+     * @param type Column type.
      * @param desc Sort direction.
      */
-    public IndexItem(String name, Boolean desc) {
-        this.name = name;
+    public IndexItem(String type, Boolean desc) {
+        this.type = type;
         this.desc = desc;
     }
 
     /**
-     * @return Column name.
+     * @return Column type.
      */
-    public String name() {
-        return name;
+    public String type() {
+        return type;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fac29f0e/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
index 3807f4f..4ef8b00 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
@@ -311,18 +311,20 @@ public class PojoDescriptor {
         Map<String, Map<String, IndexItem>> groups = new LinkedHashMap<>(idxs.size());
 
         for (Map.Entry<String, Map<String, Boolean>> idx : idxs.entrySet()) {
-            String idxName = idx.getKey();
-
             Map<String, Boolean> idxCols = idx.getValue();
 
-            Map<String, IndexItem> grp = new LinkedHashMap<>();
+            if (idxCols.size() > 1) {
+                String idxName = idx.getKey();
+
+                Map<String, IndexItem> grp = new LinkedHashMap<>();
 
-            groups.put(idxName, grp);
+                groups.put(idxName, grp);
 
-            for (Map.Entry<String, Boolean> idxCol : idxCols.entrySet()) {
-                PojoField fld = fieldsMap.get(idxCol.getKey());
+                for (Map.Entry<String, Boolean> idxCol : idxCols.entrySet()) {
+                    PojoField fld = fieldsMap.get(idxCol.getKey());
 
-                grp.put(fld.javaName(), new IndexItem(fld.javaTypeName(), idxCol.getValue()));
+                    grp.put(fld.javaName(), new IndexItem(fld.javaTypeName(), idxCol.getValue()));
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fac29f0e/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/ConfirmCallable.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/ConfirmCallable.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/ConfirmCallable.java
index 3990496..8321d96 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/ConfirmCallable.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/ConfirmCallable.java
@@ -51,7 +51,7 @@ public class ConfirmCallable implements Callable<MessageBox.Result>
{
 
     /** {@inheritDoc} */
     @Override public MessageBox.Result call() throws Exception {
-        choice = MessageBox.confirmRememberChoiceDialog(owner, String.format(template, msg));
+        choice = MessageBox.applyToAllChoiceDialog(owner, String.format(template, msg));
 
         return choice;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fac29f0e/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
index 378606c..7daf69f 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
@@ -72,9 +72,9 @@ public class MessageBox extends ModalDialog {
      * @param owner Owner window.
      * @param type Message box type.
      * @param msg Message to show.
-     * @param rememberChoice If {@code true} then add &quot;Remember choice&quot;
check box.
+     * @param applyToAll {@code true} if &quot;Apply to all&quot; check box should
be displayed.
      */
-    private MessageBox(Stage owner, MessageType type, String msg, final boolean rememberChoice)
{
+    private MessageBox(Stage owner, MessageType type, String msg, final boolean applyToAll)
{
         super(owner, 480, 180);
 
         String title;
@@ -136,11 +136,11 @@ public class MessageBox extends ModalDialog {
                 }
             });
 
-        final CheckBox rememberChoiceCh = checkBox("Remember choice", "", false);
+        final CheckBox applyToAllCh = checkBox("Apply to all", "", false);
 
-        if (rememberChoice) {
+        if (applyToAll) {
             contentPnl.skip(1);
-            contentPnl.add(rememberChoiceCh);
+            contentPnl.add(applyToAllCh);
         }
 
         HBox btns = hBox(10, true);
@@ -152,14 +152,14 @@ public class MessageBox extends ModalDialog {
             btns.getChildren().addAll(
                 button("Yes", "Approve the request", new EventHandler<ActionEvent>()
{
                     @Override public void handle(ActionEvent e) {
-                        res = rememberChoice && rememberChoiceCh.isSelected() ? Result.YES_TO_ALL
: Result.YES;
+                        res = applyToAll && applyToAllCh.isSelected() ? Result.YES_TO_ALL
: Result.YES;
 
                         close();
                     }
                 }),
                 button("No", "Reject the request", new EventHandler<ActionEvent>()
{
                     @Override public void handle(ActionEvent e) {
-                        res = rememberChoice && rememberChoiceCh.isSelected() ? Result.NO_TO_ALL
: Result.NO;
+                        res = applyToAll && applyToAllCh.isSelected() ? Result.NO_TO_ALL
: Result.NO;
 
                         close();
                     }
@@ -191,10 +191,11 @@ public class MessageBox extends ModalDialog {
      * @param owner Owner window.
      * @param type Message box type.
      * @param msg Message to show.
+     * @param applyToAll {@code true} if &quot;Apply to all&quot; check box should
be displayed.
      * @return Option selected by the user.
      */
-    private static Result showDialog(Stage owner, MessageType type, String msg, boolean rememberChoice)
{
-        MessageBox dlg = new MessageBox(owner, type, msg, rememberChoice);
+    private static Result showDialog(Stage owner, MessageType type, String msg, boolean applyToAll)
{
+        MessageBox dlg = new MessageBox(owner, type, msg, applyToAll);
 
         dlg.showModal();
 
@@ -219,7 +220,7 @@ public class MessageBox extends ModalDialog {
      * @param msg Message to show.
      * @return User confirmation result.
      */
-    public static Result confirmRememberChoiceDialog(Stage owner, String msg) {
+    public static Result applyToAllChoiceDialog(Stage owner, String msg) {
         return showDialog(owner, MessageType.CANCELLABLE_CONFIRM, msg, true);
     }
 


Mime
View raw message