# IGNITE-330 WIP on demo.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2a917135 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2a917135 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2a917135 Branch: refs/heads/ignite-330 Commit: 2a9171351cc70d4a5a393b3b8377e0c4a00ebafa Parents: 9265672 Author: AKuznetsov <akuznet...@gridgain.com> Authored: Thu Mar 19 18:17:17 2015 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Thu Mar 19 18:17:17 2015 +0700 ---------------------------------------------------------------------- examples/schema-import/db-demo.bat | 2 + examples/schema-import/db-demo.sh | 3 + .../schema-import/ignite-schema-import-demo.bat | 97 +++++++++++++ .../schema-import/ignite-schema-import-demo.sh | 78 +++++++++++ .../ignite/schema/ui/SchemaImportApp.java | 136 ++++++++++++++----- 5 files changed, 283 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a917135/examples/schema-import/db-demo.bat ---------------------------------------------------------------------- diff --git a/examples/schema-import/db-demo.bat b/examples/schema-import/db-demo.bat new file mode 100644 index 0000000..d5c450d --- /dev/null +++ b/examples/schema-import/db-demo.bat @@ -0,0 +1,2 @@ +@java -cp "h2-1.3.175.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Console %* +@if errorlevel 1 pause http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a917135/examples/schema-import/db-demo.sh ---------------------------------------------------------------------- diff --git a/examples/schema-import/db-demo.sh b/examples/schema-import/db-demo.sh new file mode 100644 index 0000000..97f35e0 --- /dev/null +++ b/examples/schema-import/db-demo.sh @@ -0,0 +1,3 @@ +#!/bin/sh +dir=$(dirname "$0") +java -cp "$dir/h2-1.3.175.jar:$H2DRIVERS:$CLASSPATH" org.h2.tools.Console "$@" http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a917135/examples/schema-import/ignite-schema-import-demo.bat ---------------------------------------------------------------------- diff --git a/examples/schema-import/ignite-schema-import-demo.bat b/examples/schema-import/ignite-schema-import-demo.bat new file mode 100644 index 0000000..fc01306 --- /dev/null +++ b/examples/schema-import/ignite-schema-import-demo.bat @@ -0,0 +1,97 @@ +:: +:: Licensed to the Apache Software Foundation (ASF) under one or more +:: contributor license agreements. See the NOTICE file distributed with +:: this work for additional information regarding copyright ownership. +:: The ASF licenses this file to You under the Apache License, Version 2.0 +:: (the "License"); you may not use this file except in compliance with +:: the License. You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, +:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +:: See the License for the specific language governing permissions and +:: limitations under the License. +:: + +:: +:: Ignite Schema Import Utility. +:: + +@echo off + +if "%OS%" == "Windows_NT" setlocal + +:: Check JAVA_HOME. +if defined JAVA_HOME goto checkJdk + echo %0, ERROR: + echo JAVA_HOME environment variable is not found. + echo Please point JAVA_HOME variable to location of JDK 1.7 or JDK 1.8. + echo You can also download latest JDK at http://java.com/download. +goto error_finish + +:checkJdk +:: Check that JDK is where it should be. +if exist "%JAVA_HOME%\bin\java.exe" goto checkJdkVersion + echo %0, ERROR: + echo JAVA is not found in JAVA_HOME=%JAVA_HOME%. + echo Please point JAVA_HOME variable to installation of JDK 1.7 or JDK 1.8. + echo You can also download latest JDK at http://java.com/download. +goto error_finish + +:checkJdkVersion +"%JAVA_HOME%\bin\java.exe" -version 2>&1 | findstr "1\.[78]\." > nul +if %ERRORLEVEL% equ 0 goto checkIgniteHome1 + echo %0, ERROR: + echo The version of JAVA installed in %JAVA_HOME% is incorrect. + echo Please point JAVA_HOME variable to installation of JDK 1.7 or JDK 1.8. + echo You can also download latest JDK at http://java.com/download. +goto error_finish + +:: Check IGNITE_HOME. +:checkIgniteHome1 +if defined IGNITE_HOME goto checkIgniteHome2 + pushd "%~dp0"/.. + set IGNITE_HOME=%CD% + popd + +:checkIgniteHome2 +:: Strip double quotes from IGNITE_HOME +set IGNITE_HOME=%IGNITE_HOME:"=% + +:: remove all trailing slashes from IGNITE_HOME. +if %IGNITE_HOME:~-1,1% == \ goto removeTrailingSlash +if %IGNITE_HOME:~-1,1% == / goto removeTrailingSlash +goto checkIgniteHome3 + +:removeTrailingSlash +set IGNITE_HOME=%IGNITE_HOME:~0,-1% +goto checkIgniteHome2 + +:checkIgniteHome3 +if exist "%IGNITE_HOME%\config" goto run + echo %0, ERROR: Ignite installation folder is not found or IGNITE_HOME environment variable is not valid. + echo Please create IGNITE_HOME environment variable pointing to location of + echo Ignite installation folder. + goto error_finish + +:run + +:: +:: Set CLASS PATH. +:: +set CP=%JAVA_HOME%\jre\lib\jfxrt.jar;%IGNITE_HOME%\bin\include\schema-import\* + +:: +:: JVM options. See http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp for more details. +:: +:: ADD YOUR/CHANGE ADDITIONAL OPTIONS HERE +:: +if "%JVM_OPTS%" == "" set JVM_OPTS=-Xms256m -Xmx1g + +"%JAVA_HOME%\bin\java.exe" %JVM_OPTS% -cp "%CP%" org.apache.ignite.schema.ui.SchemaImportApp + +:error_finish + +goto :eof http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a917135/examples/schema-import/ignite-schema-import-demo.sh ---------------------------------------------------------------------- diff --git a/examples/schema-import/ignite-schema-import-demo.sh b/examples/schema-import/ignite-schema-import-demo.sh new file mode 100644 index 0000000..2ef887c --- /dev/null +++ b/examples/schema-import/ignite-schema-import-demo.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Ignite Schema Import Utility. +# + +# +# Import common functions. +# +if [ "${IGNITE_HOME}" = "" ]; + then IGNITE_HOME_TMP="$(dirname "$(cd "$(dirname "$0")"; "pwd")")"; + else IGNITE_HOME_TMP=${IGNITE_HOME}; +fi + +# +# Set SCRIPTS_HOME - base path to scripts. +# +SCRIPTS_HOME="${IGNITE_HOME_TMP}/bin" + +source "${SCRIPTS_HOME}"/include/functions.sh + +# +# Discover path to Java executable and check it's version. +# +checkJava + +# +# Discover IGNITE_HOME environment variable. +# +setIgniteHome + +# +# Set CLASS PATH. +# +. "${SCRIPTS_HOME}"/include/setenv.sh +. "${SCRIPTS_HOME}"/include/target-classpath.sh # Will be removed in release. +CP="${JAVA_HOME}/jre/lib/jfxrt.jar${SEP}${IGNITE_HOME}/bin/include/schema-import/*" + +# Mac OS specific support to display correct name in the dock. +osname=`uname` + +if [ "${DOCK_OPTS}" == "" ]; then + DOCK_OPTS="-Xdock:name=Ignite Schema Import Utility" +fi + +# +# JVM options. See http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp for more details. +# +# ADD YOUR/CHANGE ADDITIONAL OPTIONS HERE +# +if [ -z "$JVM_OPTS" ] ; then + JVM_OPTS="-Xms256m -Xmx1g" +fi + +case $osname in + Darwin*) + "$JAVA" ${JVM_OPTS} "${DOCK_OPTS}" -cp "${CP}" org.apache.ignite.schema.ui.SchemaImportApp + ;; + *) + "$JAVA" ${JVM_OPTS} -cp "${CP}" org.apache.ignite.schema.ui.SchemaImportApp + ;; +esac http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a917135/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java ---------------------------------------------------------------------- diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java index bbd5f3f..4752c88 100644 --- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java +++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java @@ -108,6 +108,55 @@ public class SchemaImportApp extends Application { }; /** */ + private static final String PREF_WINDOW_X = "window.x"; + /** */ + private static final String PREF_WINDOW_Y = "window.y"; + /** */ + private static final String PREF_WINDOW_WIDTH = "window.width"; + /** */ + private static final String PREF_WINDOW_HEIGHT = "window.height"; + + /** */ + private static final String PREF_JDBC_DB_PRESET = "jdbc.db.preset"; + /** */ + private static final String PREF_JDBC_DRIVER_JAR = "jdbc.driver.jar"; + /** */ + private static final String PREF_JDBC_DRIVER_CLASS = "jdbc.driver.class"; + /** */ + private static final String PREF_JDBC_URL = "jdbc.url"; + /** */ + private static final String PREF_JDBC_USER = "jdbc.user"; + + /** */ + private static final String PREF_OUT_FOLDER = "out.folder"; + + /** */ + private static final String PREF_POJO_PACKAGE = "pojo.package"; + /** */ + private static final String PREF_POJO_INCLUDE = "pojo.include"; + /** */ + private static final String PREF_POJO_CONSTRUCTOR = "pojo.constructor"; + + /** */ + private static final String PREF_XML_SINGLE = "xml.single"; + + /** */ + private static final String PREF_NAMING_PATTERN = "naming.pattern"; + /** */ + private static final String PREF_NAMING_REPLACE = "naming.replace"; + + /** */ + private static final String[] PREFS = { + PREF_WINDOW_X, PREF_WINDOW_Y, PREF_WINDOW_WIDTH, PREF_WINDOW_HEIGHT, + PREF_JDBC_DB_PRESET, PREF_JDBC_DRIVER_JAR, PREF_JDBC_DRIVER_CLASS, PREF_JDBC_URL, PREF_JDBC_USER, + PREF_OUT_FOLDER, + PREF_POJO_PACKAGE, PREF_POJO_INCLUDE, PREF_POJO_CONSTRUCTOR, + PREF_XML_SINGLE, + PREF_NAMING_PATTERN, PREF_NAMING_REPLACE + }; + + + /** */ private Stage owner; /** */ @@ -1247,6 +1296,22 @@ public class SchemaImportApp extends Application { prefs.put(key, String.valueOf(val)); } + /** + * Override parameter in preferences. + * + * @param key Parameter name in preferences. + * @param val Value specified in application parameters. + */ + private void overrideParam(String key, String val) { + String param = key + "="; + + if (val.startsWith(param)) { + System.out.println(key + " = " + val); + + prefs.setProperty(key, val.substring(param.length())); + } + } + /** {@inheritDoc} */ @Override public void start(Stage primaryStage) { owner = primaryStage; @@ -1259,6 +1324,11 @@ public class SchemaImportApp extends Application { // No-op. } + // Override params. + for (String arg : getParameters().getRaw()) + for (String pref : PREFS) + overrideParam(pref, arg); + // Restore presets. for (Preset preset : presets) { String key = "presets." + preset.pref + "."; @@ -1297,11 +1367,11 @@ public class SchemaImportApp extends Application { prev(); // Restore window pos and size. - if (prefs.getProperty("window.x") != null) { - int x = getIntProp("window.x", 100); - int y = getIntProp("window.y", 100); - int w = getIntProp("window.width", 650); - int h = getIntProp("window.height", 650); + if (prefs.getProperty(PREF_WINDOW_X) != null) { + int x = getIntProp(PREF_WINDOW_X, 100); + int y = getIntProp(PREF_WINDOW_Y, 100); + int w = getIntProp(PREF_WINDOW_WIDTH, 650); + int h = getIntProp(PREF_WINDOW_HEIGHT, 650); // Ensure that window fit any available screen. if (!Screen.getScreensForRectangle(x, y, w, h).isEmpty()) { @@ -1321,23 +1391,23 @@ public class SchemaImportApp extends Application { String userHome = System.getProperty("user.home").replace('\\', '/'); // Restore connection pane settings. - rdbmsCb.getSelectionModel().select(getIntProp("jdbc.db.preset", 0)); - jdbcDrvJarTf.setText(getStringProp("jdbc.driver.jar", "h2.jar")); - jdbcDrvClsTf.setText(getStringProp("jdbc.driver.class", "org.h2.Driver")); - jdbcUrlTf.setText(getStringProp("jdbc.url", "jdbc:h2:" + userHome + "/ignite-schema-import/db")); - userTf.setText(getStringProp("jdbc.user", "sa")); + rdbmsCb.getSelectionModel().select(getIntProp(PREF_JDBC_DB_PRESET, 0)); + jdbcDrvJarTf.setText(getStringProp(PREF_JDBC_DRIVER_JAR, "h2.jar")); + jdbcDrvClsTf.setText(getStringProp(PREF_JDBC_DRIVER_CLASS, "org.h2.Driver")); + jdbcUrlTf.setText(getStringProp(PREF_JDBC_URL, "jdbc:h2:" + userHome + "/ignite-schema-import/db")); + userTf.setText(getStringProp(PREF_JDBC_USER, "sa")); // Restore generation pane settings. - outFolderTf.setText(getStringProp("out.folder", userHome + "/ignite-schema-import/out")); + outFolderTf.setText(getStringProp(PREF_OUT_FOLDER, userHome + "/ignite-schema-import/out")); - pkgTf.setText(getStringProp("pojo.package", "org.apache.ignite")); - pojoIncludeKeysCh.setSelected(getBoolProp("pojo.include", true)); - pojoConstructorCh.setSelected(getBoolProp("pojo.constructor", false)); + pkgTf.setText(getStringProp(PREF_POJO_PACKAGE, "org.apache.ignite")); + pojoIncludeKeysCh.setSelected(getBoolProp(PREF_POJO_INCLUDE, true)); + pojoConstructorCh.setSelected(getBoolProp(PREF_POJO_CONSTRUCTOR, false)); - xmlSingleFileCh.setSelected(getBoolProp("xml.single", true)); + xmlSingleFileCh.setSelected(getBoolProp(PREF_XML_SINGLE, true)); - regexTf.setText(getStringProp("naming.pattern", "(\\w+)")); - replaceTf.setText(getStringProp("naming.replace", "$1_SomeText")); + regexTf.setText(getStringProp(PREF_NAMING_PATTERN, "(\\w+)")); + replaceTf.setText(getStringProp(PREF_NAMING_REPLACE, "$1_SomeText")); primaryStage.show(); } @@ -1380,29 +1450,29 @@ public class SchemaImportApp extends Application { /** {@inheritDoc} */ @Override public void stop() throws Exception { // Save window pos and size. - setIntProp("window.x", (int)owner.getX()); - setIntProp("window.y", (int)owner.getY()); - setIntProp("window.width", (int)owner.getWidth()); - setIntProp("window.height", (int)owner.getHeight()); + setIntProp(PREF_WINDOW_X, (int)owner.getX()); + setIntProp(PREF_WINDOW_Y, (int)owner.getY()); + setIntProp(PREF_WINDOW_WIDTH, (int)owner.getWidth()); + setIntProp(PREF_WINDOW_HEIGHT, (int)owner.getHeight()); // Save connection pane settings. - setIntProp("jdbc.db.preset", rdbmsCb.getSelectionModel().getSelectedIndex()); - setStringProp("jdbc.driver.jar", jdbcDrvJarTf.getText()); - setStringProp("jdbc.driver.class", jdbcDrvClsTf.getText()); - setStringProp("jdbc.url", jdbcUrlTf.getText()); - setStringProp("jdbc.user", userTf.getText()); + setIntProp(PREF_JDBC_DB_PRESET, rdbmsCb.getSelectionModel().getSelectedIndex()); + setStringProp(PREF_JDBC_DRIVER_JAR, jdbcDrvJarTf.getText()); + setStringProp(PREF_JDBC_DRIVER_CLASS, jdbcDrvClsTf.getText()); + setStringProp(PREF_JDBC_URL, jdbcUrlTf.getText()); + setStringProp(PREF_JDBC_USER, userTf.getText()); // Save generation pane settings. - setStringProp("out.folder", outFolderTf.getText()); + setStringProp(PREF_OUT_FOLDER, outFolderTf.getText()); - setStringProp("pojo.package", pkgTf.getText()); - setBoolProp("pojo.include", pojoIncludeKeysCh.isSelected()); - setBoolProp("pojo.constructor", pojoConstructorCh.isSelected()); + setStringProp(PREF_POJO_PACKAGE, pkgTf.getText()); + setBoolProp(PREF_POJO_INCLUDE, pojoIncludeKeysCh.isSelected()); + setBoolProp(PREF_POJO_CONSTRUCTOR, pojoConstructorCh.isSelected()); - setBoolProp("xml.single", xmlSingleFileCh.isSelected()); + setBoolProp(PREF_XML_SINGLE, xmlSingleFileCh.isSelected()); - setStringProp("naming.pattern", regexTf.getText()); - setStringProp("naming.replace", replaceTf.getText()); + setStringProp(PREF_NAMING_PATTERN, regexTf.getText()); + setStringProp(PREF_NAMING_REPLACE, replaceTf.getText()); savePreferences(); }