--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Mon Dec 16 20:42:45 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Mon Dec 16 23:17:34 2013 +0100
@@ -17,6 +17,7 @@
*/
package info.globalcode.sql.dk;
+import info.globalcode.sql.dk.CLIOptions.MODE;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -24,28 +25,73 @@
*
* @author Ing. František Kučera (frantovo.cz)
*/
-public class CLIStarter {
+public class CLIStarter implements ConfigurationProvider {
private static final Logger log = Logger.getLogger(CLIStarter.class.getName());
+ private CLIOptions options;
+ private Configuration configuration;
public static void main(String[] args) {
try {
- /** Parse options */
CLIParser parser = new CLIParser();
CLIOptions options = parser.parseOptions(args);
-
options.validate();
-
- /** Show info */
- if (!options.getShowInfo().isEmpty()) {
- InfoLister infoLister = new InfoLister(System.err);
- infoLister.showInfo(options);
- }
-
+ CLIStarter starter = new CLIStarter(options);
+ starter.process();
} catch (CLIParserException e) {
log.log(Level.SEVERE, "Unable to parse CLI options", e);
} catch (InvalidOptionsException e) {
log.log(Level.SEVERE, "Invalid CLI options", e);
}
}
+
+ public CLIStarter(CLIOptions options) {
+ this.options = options;
+ }
+
+ private void process() {
+ /** Show info */
+ if (!options.getShowInfo().isEmpty()) {
+ InfoLister infoLister = new InfoLister(System.err, this);
+ infoLister.showInfo(options);
+ }
+
+ MODE mode = options.getMode();
+ switch (mode) {
+ case QUERY_NOW:
+ break;
+ case PREPARE_BATCH:
+ break;
+ case EXECUTE_BATCH:
+ break;
+ case JUST_SHOW_INFO:
+ // already done above
+ break;
+ default:
+ log.log(Level.SEVERE, "Unsupported mode: {0}", mode);
+ break;
+ }
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ if (configuration == null) {
+ installDefaultConfiguration();
+ configuration = loadConfiguration();
+ }
+ return configuration;
+ }
+
+ private void installDefaultConfiguration() {
+ /**
+ * TODO: check config folder/file and create it if missing
+ */
+ }
+
+ private Configuration loadConfiguration() {
+ /**
+ * TODO: load configuration from XML
+ */
+ return null;
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/Configuration.java Mon Dec 16 23:17:34 2013 +0100
@@ -0,0 +1,27 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class Configuration {
+ /** TODO: Databases */
+ /** TODO: Formatters */
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/ConfigurationProvider.java Mon Dec 16 23:17:34 2013 +0100
@@ -0,0 +1,27 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public interface ConfigurationProvider {
+
+ public Configuration getConfiguration();
+}
--- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Mon Dec 16 20:42:45 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Mon Dec 16 23:17:34 2013 +0100
@@ -33,9 +33,11 @@
private static final Logger log = Logger.getLogger(InfoLister.class.getName());
private PrintStream out;
+ private ConfigurationProvider configurationProvider;
- public InfoLister(PrintStream out) {
+ public InfoLister(PrintStream out, ConfigurationProvider configurationProvider) {
this.out = out;
+ this.configurationProvider = configurationProvider;
}
public void showInfo(CLIOptions options) {