1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Mon Dec 16 20:42:45 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Mon Dec 16 23:17:34 2013 +0100
1.3 @@ -17,6 +17,7 @@
1.4 */
1.5 package info.globalcode.sql.dk;
1.6
1.7 +import info.globalcode.sql.dk.CLIOptions.MODE;
1.8 import java.util.logging.Level;
1.9 import java.util.logging.Logger;
1.10
1.11 @@ -24,28 +25,73 @@
1.12 *
1.13 * @author Ing. František Kučera (frantovo.cz)
1.14 */
1.15 -public class CLIStarter {
1.16 +public class CLIStarter implements ConfigurationProvider {
1.17
1.18 private static final Logger log = Logger.getLogger(CLIStarter.class.getName());
1.19 + private CLIOptions options;
1.20 + private Configuration configuration;
1.21
1.22 public static void main(String[] args) {
1.23 try {
1.24 - /** Parse options */
1.25 CLIParser parser = new CLIParser();
1.26 CLIOptions options = parser.parseOptions(args);
1.27 -
1.28 options.validate();
1.29 -
1.30 - /** Show info */
1.31 - if (!options.getShowInfo().isEmpty()) {
1.32 - InfoLister infoLister = new InfoLister(System.err);
1.33 - infoLister.showInfo(options);
1.34 - }
1.35 -
1.36 + CLIStarter starter = new CLIStarter(options);
1.37 + starter.process();
1.38 } catch (CLIParserException e) {
1.39 log.log(Level.SEVERE, "Unable to parse CLI options", e);
1.40 } catch (InvalidOptionsException e) {
1.41 log.log(Level.SEVERE, "Invalid CLI options", e);
1.42 }
1.43 }
1.44 +
1.45 + public CLIStarter(CLIOptions options) {
1.46 + this.options = options;
1.47 + }
1.48 +
1.49 + private void process() {
1.50 + /** Show info */
1.51 + if (!options.getShowInfo().isEmpty()) {
1.52 + InfoLister infoLister = new InfoLister(System.err, this);
1.53 + infoLister.showInfo(options);
1.54 + }
1.55 +
1.56 + MODE mode = options.getMode();
1.57 + switch (mode) {
1.58 + case QUERY_NOW:
1.59 + break;
1.60 + case PREPARE_BATCH:
1.61 + break;
1.62 + case EXECUTE_BATCH:
1.63 + break;
1.64 + case JUST_SHOW_INFO:
1.65 + // already done above
1.66 + break;
1.67 + default:
1.68 + log.log(Level.SEVERE, "Unsupported mode: {0}", mode);
1.69 + break;
1.70 + }
1.71 + }
1.72 +
1.73 + @Override
1.74 + public Configuration getConfiguration() {
1.75 + if (configuration == null) {
1.76 + installDefaultConfiguration();
1.77 + configuration = loadConfiguration();
1.78 + }
1.79 + return configuration;
1.80 + }
1.81 +
1.82 + private void installDefaultConfiguration() {
1.83 + /**
1.84 + * TODO: check config folder/file and create it if missing
1.85 + */
1.86 + }
1.87 +
1.88 + private Configuration loadConfiguration() {
1.89 + /**
1.90 + * TODO: load configuration from XML
1.91 + */
1.92 + return null;
1.93 + }
1.94 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/Configuration.java Mon Dec 16 23:17:34 2013 +0100
2.3 @@ -0,0 +1,27 @@
2.4 +/**
2.5 + * SQL-DK
2.6 + * Copyright © 2013 František Kučera (frantovo.cz)
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, either version 3 of the License, or
2.11 + * (at your option) any later version.
2.12 + *
2.13 + * This program is distributed in the hope that it will be useful,
2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.16 + * GNU General Public License for more details.
2.17 + *
2.18 + * You should have received a copy of the GNU General Public License
2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2.20 + */
2.21 +package info.globalcode.sql.dk;
2.22 +
2.23 +/**
2.24 + *
2.25 + * @author Ing. František Kučera (frantovo.cz)
2.26 + */
2.27 +public class Configuration {
2.28 + /** TODO: Databases */
2.29 + /** TODO: Formatters */
2.30 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/ConfigurationProvider.java Mon Dec 16 23:17:34 2013 +0100
3.3 @@ -0,0 +1,27 @@
3.4 +/**
3.5 + * SQL-DK
3.6 + * Copyright © 2013 František Kučera (frantovo.cz)
3.7 + *
3.8 + * This program is free software: you can redistribute it and/or modify
3.9 + * it under the terms of the GNU General Public License as published by
3.10 + * the Free Software Foundation, either version 3 of the License, or
3.11 + * (at your option) any later version.
3.12 + *
3.13 + * This program is distributed in the hope that it will be useful,
3.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.16 + * GNU General Public License for more details.
3.17 + *
3.18 + * You should have received a copy of the GNU General Public License
3.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3.20 + */
3.21 +package info.globalcode.sql.dk;
3.22 +
3.23 +/**
3.24 + *
3.25 + * @author Ing. František Kučera (frantovo.cz)
3.26 + */
3.27 +public interface ConfigurationProvider {
3.28 +
3.29 + public Configuration getConfiguration();
3.30 +}
4.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Mon Dec 16 20:42:45 2013 +0100
4.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Mon Dec 16 23:17:34 2013 +0100
4.3 @@ -33,9 +33,11 @@
4.4
4.5 private static final Logger log = Logger.getLogger(InfoLister.class.getName());
4.6 private PrintStream out;
4.7 + private ConfigurationProvider configurationProvider;
4.8
4.9 - public InfoLister(PrintStream out) {
4.10 + public InfoLister(PrintStream out, ConfigurationProvider configurationProvider) {
4.11 this.out = out;
4.12 + this.configurationProvider = configurationProvider;
4.13 }
4.14
4.15 public void showInfo(CLIOptions options) {