ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject incubator-ignite git commit: # IGNITE-32 WIP: UI and POJO generator: added support for affinity key.
Date Tue, 27 Jan 2015 16:43:34 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-32 6616ad450 -> 6a537baf8


# IGNITE-32 WIP: UI and POJO generator: added support for affinity key.


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

Branch: refs/heads/ignite-32
Commit: 6a537baf888187f3f85cf27b8bd78076512903a1
Parents: 6616ad4
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Tue Jan 27 23:42:19 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Tue Jan 27 23:42:19 2015 +0700

----------------------------------------------------------------------
 .../ignite/schema/generator/PojoGenerator.java  | 29 +++++++++++++------
 .../ignite/schema/model/PojoDescriptor.java     |  5 +++-
 .../apache/ignite/schema/model/PojoField.java   | 30 ++++++++++++++++++++
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 10 +++++++
 4 files changed, 64 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6a537baf/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/PojoGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/PojoGenerator.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/PojoGenerator.java
index 2d4bd4f..ac46a71 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/PojoGenerator.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/PojoGenerator.java
@@ -109,15 +109,19 @@ public class PojoGenerator {
     /**
      * Generate java class code.
      *
+     * @param pojo POJO descriptor.
+     * @param key {@code true} if key class should be generated.
      * @param pkg Package name.
-     * @param type Type name.
-     * @param fields POJO fields.
-     * @param constructor If {@code true} then generate empty and full constructors.
+     * @param pkgFolder Folder where to save generated class.
+     * @param constructor {@code true} if empty and full constructors should be generated.
+     * @param includeKeys {@code true} if key fields should be included into value class.
      * @param askOverwrite Callback to ask user to confirm file overwrite.
      * @throws IOException If failed to write generated code into file.
      */
-    private static void generateCode(String pkg, String type, Collection<PojoField>
fields,
-        File pkgFolder, boolean constructor, ConfirmCallable askOverwrite) throws IOException
{
+    private static void generateCode(PojoDescriptor pojo, boolean key, String pkg, File pkgFolder,
+        boolean constructor, boolean includeKeys, ConfirmCallable askOverwrite) throws IOException
{
+        String type = key ? pojo.keyClassName() : pojo.valueClassName();
+
         File out = new File(pkgFolder, type + ".java");
 
         if (out.exists()) {
@@ -171,11 +175,17 @@ public class PojoGenerator {
         add1(src, "private static final long serialVersionUID = 0L;");
         add0(src, "");
 
+        Collection<PojoField> fields = key ? pojo.keyFields() : pojo.valueFields(includeKeys);
+
         // Generate fields declaration.
         for (PojoField field : fields) {
             String fldName = field.javaName();
 
             add1(src, "/** Value for " + fldName + ". */");
+
+            if (key && field.affinityKey())
+                add1(src, "@CacheAffinityKeyMapped");
+
             add1(src, "private " + javaTypeName(field) + " " + fldName + ";");
             add0(src, "");
         }
@@ -382,10 +392,11 @@ public class PojoGenerator {
     /**
      * Generate source code for type by its metadata.
      *
-     * @param pojo Type metadata.
+     * @param pojo POJO descriptor.
      * @param outFolder Output folder.
      * @param pkg Types package.
-     * @param constructor If {@code true} then generate empty and full constructors.
+     * @param constructor {@code true} if empty and full constructors should be generated.
+     * @param includeKeys {@code true} if key fields should be included into value class.
      * @param askOverwrite Callback to ask user to confirm file overwrite.
      * @throws IOException If failed to write generated code into file.
      */
@@ -397,8 +408,8 @@ public class PojoGenerator {
         if (!pkgFolder.exists() && !pkgFolder.mkdirs())
             throw new IOException("Failed to create folders for package: " + pkg);
 
-        generateCode(pkg, pojo.keyClassName(), pojo.keyFields(), pkgFolder, constructor,
askOverwrite);
+        generateCode(pojo, true, pkg, pkgFolder, constructor, false, askOverwrite);
 
-        generateCode(pkg, pojo.valueClassName(), pojo.valueFields(includeKeys), pkgFolder,
constructor, askOverwrite);
+        generateCode(pojo, false, pkg, pkgFolder, constructor, includeKeys, askOverwrite);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6a537baf/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
index d7dec61..e215dcb 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java
@@ -127,6 +127,9 @@ public class PojoDescriptor {
 
         this.fields = FXCollections.observableList(fields);
 
+        for (PojoField field : fields)
+            field.owner(this);
+
         this.typeMeta = typeMeta;
     }
 
@@ -193,7 +196,7 @@ public class PojoDescriptor {
     }
 
     /**
-     * @param includeKeys If {@code true} include key fields into list of value fields.
+     * @param includeKeys {@code true} if key fields should be included into value class.
      * @return Collection of value fields.
      */
     public Collection<PojoField> valueFields(boolean includeKeys) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6a537baf/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoField.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoField.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoField.java
index 866954b..4768dfb 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoField.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoField.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.schema.model;
 
 import javafx.beans.property.*;
+import javafx.beans.value.*;
 import javafx.collections.*;
 import org.apache.ignite.cache.query.*;
 
@@ -72,6 +73,9 @@ public class PojoField {
     /** Field type descriptor. */
     private final CacheQueryTypeDescriptor desc;
 
+    /** Field owner. */
+    private PojoDescriptor owner;
+
     /**
      * @param clss List of classes to get class names.
      * @return List of classes names to show in UI for manual select.
@@ -180,6 +184,18 @@ public class PojoField {
         conversions = conversions(dbType, nullable, javaNamePrev);
 
         this.desc = desc;
+
+        ak.addListener(new ChangeListener<Boolean>() {
+            @Override public void changed(ObservableValue<? extends Boolean> val, Boolean
oldVal, Boolean newVal) {
+                if (newVal && owner != null) {
+                    keyProperty().set(true);
+
+                    for (PojoField field : owner.fields())
+                        if (field != PojoField.this && field.affinityKey())
+                            field.ak.set(false);
+                }
+            }
+        });
     }
 
     /**
@@ -272,6 +288,13 @@ public class PojoField {
     }
 
     /**
+     * @param owner New field owner.
+     */
+    public void owner(PojoDescriptor owner) {
+        this.owner = owner;
+    }
+
+    /**
      * @return {@code true} if this field belongs to primary key.
      */
     public boolean key() {
@@ -279,6 +302,13 @@ public class PojoField {
     }
 
     /**
+     * @return {@code true} if this field is an affinity key.
+     */
+    public boolean affinityKey() {
+        return ak.get();
+    }
+
+    /**
      * @param pk {@code true} if this field belongs to primary key.
      */
     public void key(boolean pk) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6a537baf/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
index b2bee1c..bbda32d 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
@@ -25,6 +25,7 @@ import javafx.event.*;
 import javafx.geometry.*;
 import javafx.scene.*;
 import javafx.scene.control.*;
+import javafx.scene.input.*;
 import javafx.scene.layout.*;
 import javafx.stage.*;
 import javafx.util.*;
@@ -1101,6 +1102,15 @@ public class SchemaLoadApp extends Application {
                         ch.indeterminateProperty().bindBidirectional(pojo.indeterminate());
                         ch.selectedProperty().bindBidirectional(pojo.useProperty());
 
+                        ch.setOnMouseClicked(new EventHandler<MouseEvent>() {
+                            @Override public void handle(MouseEvent evt) {
+                                TableView<PojoDescriptor> view = getTableView();
+
+                                view.getSelectionModel().select(getIndex());
+                                view.requestFocus();
+                            }
+                        });
+
                         Pane pnl = new HBox();
 
                         pnl.setPadding(new Insets(0, 0, 0, isTbl ? 25 : 5));


Mime
View raw message