ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [25/59] [abbrv] incubator-ignite git commit: # IGNITE-32: WIP GUI: added support and checks for "used" fields + fixed several typo.
Date Thu, 05 Feb 2015 13:12:31 GMT
# IGNITE-32: WIP GUI: added support and checks for "used" fields + fixed several typo.


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

Branch: refs/heads/ignite-54-55
Commit: 626700eb9203995c5ccb6114126be89aa6249345
Parents: 52a250d
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Tue Feb 3 17:58:56 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Tue Feb 3 17:58:56 2015 +0700

----------------------------------------------------------------------
 .../cache/query/GridCacheQueriesProxy.java      |   2 +-
 .../ignite/schema/model/PojoDescriptor.java     |  76 ++++++++---
 .../apache/ignite/schema/model/PojoField.java   |  11 +-
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 126 +++++++++++++------
 4 files changed, 155 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/626700eb/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueriesProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueriesProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueriesProxy.java
index 0266629..d9ad3cd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueriesProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueriesProxy.java
@@ -54,7 +54,7 @@ public class GridCacheQueriesProxy<K, V> implements GridCacheQueriesEx<K,
V>, Ex
     /**
      * Create cache queries implementation.
      *
-     * @param cctx Сontext.
+     * @param cctx Context.
      * @param prj Optional cache projection.
      * @param delegate Delegate object.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/626700eb/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 6bbed5e..2b030ce 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
@@ -83,7 +83,28 @@ public class PojoDescriptor {
         keyClsNamePrev = valClsNamePrev.isEmpty() ? "" : valClsNamePrev + "Key";
         keyClsNameProp = new SimpleStringProperty(keyClsNamePrev);
 
-        useProp = new SimpleBooleanProperty(true);
+        Collection<DbColumn> cols = tbl.columns();
+
+        List<PojoField> flds = new ArrayList<>(cols.size());
+
+        for (DbColumn col : cols) {
+            PojoField fld = new PojoField(col.name(), col.type(),
+                toJavaFieldName(col.name()), toJavaType(col.type(), col.nullable()).getName(),
+                col.key(), col.nullable());
+
+            fld.owner(this);
+
+            flds.add(fld);
+        }
+
+        fields = FXCollections.observableList(flds);
+
+        boolean hasKeys = !keyFields().isEmpty();
+
+        useProp = new SimpleBooleanProperty(hasKeys);
+
+        if (parent != null)
+            parent.indeterminate().set(true);
 
         useProp.addListener(new ChangeListener<Boolean>() {
             @Override public void changed(ObservableValue<? extends Boolean> val, Boolean
oldVal, Boolean newVal) {
@@ -111,22 +132,6 @@ public class PojoDescriptor {
                 }
             }
         });
-
-        Collection<DbColumn> cols = tbl.columns();
-
-        List<PojoField> flds = new ArrayList<>(cols.size());
-
-        for (DbColumn col : cols) {
-            PojoField fld = new PojoField(col.name(), col.type(),
-                toJavaFieldName(col.name()), toJavaType(col.type(), col.nullable()).getName(),
-                col.key(), col.nullable());
-
-            fld.owner(this);
-
-            flds.add(fld);
-        }
-
-        fields = FXCollections.observableList(flds);
     }
 
     /**
@@ -193,6 +198,43 @@ public class PojoDescriptor {
     }
 
     /**
+     * @return {@code true} if at least one field checked as &quot;used&quot;.
+     */
+    public boolean hasFields() {
+        for (PojoField field : fields)
+            if (field.use())
+                return true;
+
+        return false;
+    }
+
+    /**
+     * @return {@code true} if at least one field checked as &quot;used&quot; and
checked as &quot;key&quot;.
+     */
+    public boolean hasKeyFields() {
+        for (PojoField field : fields)
+            if (field.use() && field.key())
+                return true;
+
+        return false;
+    }
+
+    /**
+     * @param includeKeys {@code true} if key fields should be included into value class.
+     * @return {@code true} if at least one field checked as &quot;used&quot; and
not checked as &quot;key&quot;.
+     */
+    public boolean hasValueFields(boolean includeKeys) {
+        if (includeKeys)
+            return hasKeyFields();
+
+        for (PojoField field : fields)
+            if (field.use() && !field.key())
+                return true;
+
+        return false;
+    }
+
+    /**
      * @return Collection of key fields.
      */
     public Collection<PojoField> keyFields() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/626700eb/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 507d5db..66b3e67 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
@@ -151,14 +151,14 @@ public class PojoField {
 
         javaTypeNameProp = new SimpleStringProperty(javaTypeNamePrev);
 
+        useProp = new SimpleBooleanProperty(true);
+
         keyPrev = key;
 
         keyProp = new SimpleBooleanProperty(keyPrev);
 
         this.nullable = nullable;
 
-        useProp = new SimpleBooleanProperty(true);
-
         akProp = new SimpleBooleanProperty(false);
 
         conversions = conversions(dbType, nullable, javaNamePrev);
@@ -280,6 +280,13 @@ public class PojoField {
     }
 
     /**
+     * @return {@code true} if filed should be used for code generation.
+     */
+    public boolean use() {
+        return useProp.get();
+    }
+
+    /**
      * @return {@code true} if this field belongs to primary key.
      */
     public boolean key() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/626700eb/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 6acbf39..cd08f4d 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,7 +25,6 @@ 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.*;
@@ -53,8 +52,9 @@ public class SchemaLoadApp extends Application {
         "H2 Database",
         "DB2",
         "Oracle",
-        "Microsoft SQL Server",
         "MySQL",
+        "Microsoft SQL Server",
+        "PostgreSQL",
         "Custom server..."};
 
     /** Jdbc drivers. */
@@ -62,8 +62,9 @@ public class SchemaLoadApp extends Application {
         "h2.jar",
         "db2jcc4.jar",
         "ojdbc6.jar",
-        "sqljdbc41.jar",
         "mysql-connector-java-5-bin.jar",
+        "sqljdbc41.jar",
+        "postgresql-9.3.jdbc4.jar",
         "jdbc.jar"};
 
     /** Jdbc drivers. */
@@ -71,17 +72,19 @@ public class SchemaLoadApp extends Application {
         "org.h2.Driver",
         "com.ibm.db2.jcc.DB2Driver",
         "oracle.jdbc.OracleDriver",
-        "com.microsoft.sqlserver.jdbc.SQLServerDriver",
         "com.mysql.jdbc.Driver",
+        "com.microsoft.sqlserver.jdbc.SQLServerDriver",
+        "org.postgresql.Driver",
         "org.custom.Driver"};
 
     /** Jdbc urls. */
     private static final String[] JDBC_URLS = {
-        "jdbc:h2:_path_to_db_",
+        "jdbc:h2:[database]",
         "jdbc:db2://[host]:[port]/[database]",
         "jdbc:oracle:thin:@[host]:[port]:[database]",
-        "jdbc:sqlserver://[host]:[port];databaseName=[database]",
-        "jdbc:mysql://[host][,failoverhost...]:[port]/[database]",
+        "jdbc:mysql://[host]:[port]/[database]",
+        "jdbc:sqlserver://[host]:[port][;databaseName=database]",
+        "jdbc:postgresql://[host]:[port]/[database]",
         "jdbc:custom"};
 
     /** */
@@ -324,7 +327,7 @@ public class SchemaLoadApp extends Application {
      * Generate XML and POJOs.
      */
     private void generate() {
-        final Collection<PojoDescriptor> selPojos = chekedPojos();
+        final Collection<PojoDescriptor> selPojos = checkedPojos();
 
         if (selPojos.isEmpty()) {
             MessageBox.warningDialog(owner, "Please select tables to generate XML and POJOs
files!");
@@ -340,13 +343,22 @@ public class SchemaLoadApp extends Application {
 
         final File destFolder = new File(outFolder);
 
+        final boolean constructor = pojoConstructorCh.isSelected();
+
+        final boolean includeKeys = pojoIncludeKeysCh.isSelected();
+
+        final boolean singleXml = xmlSingleFileCh.isSelected();
+
         Runnable task = new Task<Void>() {
-            private void checkEmpty(final PojoDescriptor pojo, Collection<PojoField>
fields, String msg) {
-                if (fields.isEmpty()) {
+            private void checkEmpty(final PojoDescriptor pojo, boolean selected, String msg)
{
+                if (!selected) {
                     Platform.runLater(new Runnable() {
                         @Override public void run() {
-                            pojosTbl.getSelectionModel().select(pojo);
-                            pojosTbl.scrollTo(pojosTbl.getSelectionModel().getSelectedIndex());
+                            TableView.TableViewSelectionModel<PojoDescriptor> selMdl
= pojosTbl.getSelectionModel();
+
+                            selMdl.clearSelection();
+                            selMdl.select(pojo);
+                            pojosTbl.scrollTo(selMdl.getSelectedIndex());
                         }
                     });
 
@@ -363,27 +375,25 @@ public class SchemaLoadApp extends Application {
 
                 Collection<PojoDescriptor> all = new ArrayList<>();
 
-                boolean constructor = pojoConstructorCh.isSelected();
-                boolean includeKeys = pojoIncludeKeysCh.isSelected();
-                boolean singleXml = xmlSingleFileCh.isSelected();
-
                 ConfirmCallable askOverwrite = new ConfirmCallable(owner, "File already exists:
%s\nOverwrite?");
 
                 // Generate XML and POJO.
                 for (PojoDescriptor pojo : selPojos) {
                     if (pojo.checked()) {
-                        checkEmpty(pojo, pojo.keyFields(), "No key fields specified for type:
");
-
-                        checkEmpty(pojo, pojo.valueFields(includeKeys), "No value fields
specified for type: ");
+                        checkEmpty(pojo, pojo.hasFields(), "No fields selected for type:
");
+                        checkEmpty(pojo, pojo.hasKeyFields(), "No key fields selected for
type: ");
+                        checkEmpty(pojo, pojo.hasValueFields(includeKeys), "No value fields
selected for type: ");
 
                         all.add(pojo);
+                    }
+                }
 
-                        if (!singleXml)
-                            XmlGenerator.generate(pkg, pojo, includeKeys, new File(destFolder,
pojo.table() + ".xml"),
-                                askOverwrite);
+                for (PojoDescriptor pojo : all) {
+                    if (!singleXml)
+                        XmlGenerator.generate(pkg, pojo, includeKeys, new File(destFolder,
pojo.table() + ".xml"),
+                            askOverwrite);
 
-                        PojoGenerator.generate(pojo, outFolder, pkg, constructor, includeKeys,
askOverwrite);
-                    }
+                    PojoGenerator.generate(pojo, outFolder, pkg, constructor, includeKeys,
askOverwrite);
                 }
 
                 if (singleXml)
@@ -634,7 +644,7 @@ public class SchemaLoadApp extends Application {
             }
         }));
 
-        jdbcDrvClsTf = connPnl.addLabeled("JDBC Driver:", textField("Enter сlass name for
JDBC driver"), 2);
+        jdbcDrvClsTf = connPnl.addLabeled("JDBC Driver:", textField("Enter class name for
JDBC driver"), 2);
 
         jdbcUrlTf = connPnl.addLabeled("JDBC URL:", textField("JDBC URL of the database connection
string"), 2);
 
@@ -740,15 +750,16 @@ public class SchemaLoadApp extends Application {
 
         pojosTbl = tableView("Tables not found in database", useCol, keyClsCol, valClsCol);
 
-        TableColumn<PojoField, Boolean> useFldCol = booleanColumn("Use", "use",
-            "Check to use this field for XML and POJO generation");
+        TableColumn<PojoField, Boolean> useFldCol = customColumn("Use", "use",
+            "Check to use this field for XML and POJO generation\n" +
+            "Note that NOT NULL columns cannot be unchecked", PojoFieldUseCell.cellFactory());
 
         TableColumn<PojoField, Boolean> keyCol = booleanColumn("Key", "key",
-            "Сheck to include this field into key object");
+            "Check to include this field into key object");
 
         TableColumn<PojoField, Boolean> akCol = booleanColumn("AK", "affinityKey",
             "Check to annotate key filed with @CacheAffinityKeyMapped annotation in generated
POJO class\n" +
-            "Note that a class can have only one key field annotated with @CacheAffinityKeyMapped
annotation");
+            "Note that a class can have only ONE key field annotated with @CacheAffinityKeyMapped
annotation");
 
         TableColumn<PojoField, String> dbNameCol = tableColumn("DB Name", "dbName",
"Field name in database");
 
@@ -1014,7 +1025,7 @@ public class SchemaLoadApp extends Application {
     /**
      * @return POJOs checked in table-tree-view.
      */
-    private Collection<PojoDescriptor> chekedPojos() {
+    private Collection<PojoDescriptor> checkedPojos() {
         Collection<PojoDescriptor> res = new ArrayList<>();
 
         for (PojoDescriptor pojo : pojos)
@@ -1275,7 +1286,6 @@ public class SchemaLoadApp extends Application {
                         boolean isTbl = pojo.parent() != null;
 
                         CheckBox ch = new CheckBox();
-                        Label lb = new Label(isTbl ? pojo.table() : pojo.schema());
 
                         ch.setAllowIndeterminate(false);
 
@@ -1283,17 +1293,9 @@ public class SchemaLoadApp extends Application {
 
                         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();
-                            }
-                        });
+                        Label lb = new Label(isTbl ? pojo.table() : pojo.schema());
 
                         Pane pnl = new HBox(5);
-
                         pnl.setPadding(new Insets(0, 0, 0, isTbl ? 25 : 5));
                         pnl.getChildren().addAll(ch, lb);
 
@@ -1303,4 +1305,48 @@ public class SchemaLoadApp extends Application {
             }
         }
     }
+
+    /**
+     * Special table cell to select &quot;used&quot; fields for code generation.
+     */
+    private static class PojoFieldUseCell extends TableCell<PojoField, Boolean> {
+        /** Creates a ComboBox cell factory for use in TableColumn controls. */
+        public static Callback<TableColumn<PojoField, Boolean>, TableCell<PojoField,
Boolean>> cellFactory() {
+            return new Callback<TableColumn<PojoField, Boolean>, TableCell<PojoField,
Boolean>>() {
+                @Override public TableCell<PojoField, Boolean> call(TableColumn<PojoField,
Boolean> col) {
+                    return new PojoFieldUseCell();
+                }
+            };
+        }
+
+        /** Previous POJO field bound to cell. */
+        private PojoField prevField;
+
+        /** {@inheritDoc} */
+        @Override public void updateItem(Boolean item, boolean empty) {
+            super.updateItem(item, empty);
+
+            if (!empty) {
+                TableRow row = getTableRow();
+
+                if (row != null) {
+                    final PojoField field = (PojoField)row.getItem();
+
+                    if (field != prevField) {
+                        prevField = field;
+
+                        setAlignment(Pos.CENTER);
+
+                        CheckBox ch = new CheckBox();
+
+                        ch.setDisable(!field.nullable());
+
+                        ch.selectedProperty().bindBidirectional(field.useProperty());
+
+                        setGraphic(ch);
+                    }
+                }
+            }
+        }
+    }
 }


Mime
View raw message