1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Fri Dec 20 23:50:21 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sat Dec 21 20:38:50 2013 +0100
1.3 @@ -17,7 +17,9 @@
1.4 */
1.5 package info.globalcode.sql.dk;
1.6
1.7 +import info.globalcode.sql.dk.configuration.ConfigurationProvider;
1.8 import info.globalcode.sql.dk.CLIOptions.MODE;
1.9 +import info.globalcode.sql.dk.configuration.Configuration;
1.10 import java.util.logging.Level;
1.11 import java.util.logging.Logger;
1.12
2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/Configuration.java Fri Dec 20 23:50:21 2013 +0100
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,27 +0,0 @@
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 --- a/java/sql-dk/src/info/globalcode/sql/dk/ConfigurationProvider.java Fri Dec 20 23:50:21 2013 +0100
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,27 +0,0 @@
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 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DKException.java Sat Dec 21 20:38:50 2013 +0100
4.3 @@ -0,0 +1,41 @@
4.4 +/**
4.5 + * SQL-DK
4.6 + * Copyright © 2013 František Kučera (frantovo.cz)
4.7 + *
4.8 + * This program is free software: you can redistribute it and/or modify
4.9 + * it under the terms of the GNU General Public License as published by
4.10 + * the Free Software Foundation, either version 3 of the License, or
4.11 + * (at your option) any later version.
4.12 + *
4.13 + * This program is distributed in the hope that it will be useful,
4.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.16 + * GNU General Public License for more details.
4.17 + *
4.18 + * You should have received a copy of the GNU General Public License
4.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4.20 + */
4.21 +package info.globalcode.sql.dk;
4.22 +
4.23 +/**
4.24 + * TODO: GEC
4.25 + *
4.26 + * @author Ing. František Kučera (frantovo.cz)
4.27 + */
4.28 +public class DKException extends Exception {
4.29 +
4.30 + public DKException() {
4.31 + }
4.32 +
4.33 + public DKException(String message) {
4.34 + super(message);
4.35 + }
4.36 +
4.37 + public DKException(Throwable cause) {
4.38 + super(cause);
4.39 + }
4.40 +
4.41 + public DKException(String message, Throwable cause) {
4.42 + super(message, cause);
4.43 + }
4.44 +}
5.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Fri Dec 20 23:50:21 2013 +0100
5.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sat Dec 21 20:38:50 2013 +0100
5.3 @@ -17,6 +17,7 @@
5.4 */
5.5 package info.globalcode.sql.dk;
5.6
5.7 +import info.globalcode.sql.dk.configuration.ConfigurationProvider;
5.8 import java.io.BufferedReader;
5.9 import java.io.InputStreamReader;
5.10 import java.io.PrintStream;
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java Sat Dec 21 20:38:50 2013 +0100
6.3 @@ -0,0 +1,49 @@
6.4 +/**
6.5 + * SQL-DK
6.6 + * Copyright © 2013 František Kučera (frantovo.cz)
6.7 + *
6.8 + * This program is free software: you can redistribute it and/or modify
6.9 + * it under the terms of the GNU General Public License as published by
6.10 + * the Free Software Foundation, either version 3 of the License, or
6.11 + * (at your option) any later version.
6.12 + *
6.13 + * This program is distributed in the hope that it will be useful,
6.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.16 + * GNU General Public License for more details.
6.17 + *
6.18 + * You should have received a copy of the GNU General Public License
6.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6.20 + */
6.21 +package info.globalcode.sql.dk.configuration;
6.22 +
6.23 +import java.util.ArrayList;
6.24 +import java.util.List;
6.25 +import javax.xml.bind.annotation.XmlRootElement;
6.26 +
6.27 +/**
6.28 + *
6.29 + * @author Ing. František Kučera (frantovo.cz)
6.30 + */
6.31 +@XmlRootElement
6.32 +public class Configuration {
6.33 +
6.34 + private List<DatabaseDefinition> databases = new ArrayList<>();
6.35 + private List<FormatterDefinition> formatters = new ArrayList<>();
6.36 +
6.37 + public List<DatabaseDefinition> getDatabases() {
6.38 + return databases;
6.39 + }
6.40 +
6.41 + public void setDatabases(List<DatabaseDefinition> databases) {
6.42 + this.databases = databases;
6.43 + }
6.44 +
6.45 + public List<FormatterDefinition> getFormatters() {
6.46 + return formatters;
6.47 + }
6.48 +
6.49 + public void setFormatters(List<FormatterDefinition> formatters) {
6.50 + this.formatters = formatters;
6.51 + }
6.52 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/ConfigurationProvider.java Sat Dec 21 20:38:50 2013 +0100
7.3 @@ -0,0 +1,27 @@
7.4 +/**
7.5 + * SQL-DK
7.6 + * Copyright © 2013 František Kučera (frantovo.cz)
7.7 + *
7.8 + * This program is free software: you can redistribute it and/or modify
7.9 + * it under the terms of the GNU General Public License as published by
7.10 + * the Free Software Foundation, either version 3 of the License, or
7.11 + * (at your option) any later version.
7.12 + *
7.13 + * This program is distributed in the hope that it will be useful,
7.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.16 + * GNU General Public License for more details.
7.17 + *
7.18 + * You should have received a copy of the GNU General Public License
7.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7.20 + */
7.21 +package info.globalcode.sql.dk.configuration;
7.22 +
7.23 +/**
7.24 + *
7.25 + * @author Ing. František Kučera (frantovo.cz)
7.26 + */
7.27 +public interface ConfigurationProvider {
7.28 +
7.29 + public Configuration getConfiguration();
7.30 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseConnection.java Sat Dec 21 20:38:50 2013 +0100
8.3 @@ -0,0 +1,31 @@
8.4 +/**
8.5 + * SQL-DK
8.6 + * Copyright © 2013 František Kučera (frantovo.cz)
8.7 + *
8.8 + * This program is free software: you can redistribute it and/or modify
8.9 + * it under the terms of the GNU General Public License as published by
8.10 + * the Free Software Foundation, either version 3 of the License, or
8.11 + * (at your option) any later version.
8.12 + *
8.13 + * This program is distributed in the hope that it will be useful,
8.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.16 + * GNU General Public License for more details.
8.17 + *
8.18 + * You should have received a copy of the GNU General Public License
8.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8.20 + */
8.21 +package info.globalcode.sql.dk.configuration;
8.22 +
8.23 +/**
8.24 + *
8.25 + * @author Ing. František Kučera (frantovo.cz)
8.26 + */
8.27 +public class DatabaseConnection {
8.28 +
8.29 + private DatabaseDefinition databaseDefinition;
8.30 +
8.31 + public DatabaseConnection(DatabaseDefinition databaseDefinition) {
8.32 + this.databaseDefinition = databaseDefinition;
8.33 + }
8.34 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/DatabaseDefinition.java Sat Dec 21 20:38:50 2013 +0100
9.3 @@ -0,0 +1,75 @@
9.4 +/**
9.5 + * SQL-DK
9.6 + * Copyright © 2013 František Kučera (frantovo.cz)
9.7 + *
9.8 + * This program is free software: you can redistribute it and/or modify
9.9 + * it under the terms of the GNU General Public License as published by
9.10 + * the Free Software Foundation, either version 3 of the License, or
9.11 + * (at your option) any later version.
9.12 + *
9.13 + * This program is distributed in the hope that it will be useful,
9.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9.16 + * GNU General Public License for more details.
9.17 + *
9.18 + * You should have received a copy of the GNU General Public License
9.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9.20 + */
9.21 +package info.globalcode.sql.dk.configuration;
9.22 +
9.23 +import javax.xml.bind.annotation.XmlElement;
9.24 +import javax.xml.bind.annotation.XmlTransient;
9.25 +
9.26 +/**
9.27 + *
9.28 + * @author Ing. František Kučera (frantovo.cz)
9.29 + */
9.30 +public class DatabaseDefinition implements NameIdentified {
9.31 +
9.32 + private String name;
9.33 + private String url;
9.34 + private String userName;
9.35 + private String password;
9.36 +
9.37 + @XmlElement(name = "name")
9.38 + @Override
9.39 + public String getName() {
9.40 + return name;
9.41 + }
9.42 +
9.43 + public void setName(String name) {
9.44 + this.name = name;
9.45 + }
9.46 +
9.47 + @XmlElement(name = "url")
9.48 + public String getUrl() {
9.49 + return url;
9.50 + }
9.51 +
9.52 + public void setUrl(String url) {
9.53 + this.url = url;
9.54 + }
9.55 +
9.56 + @XmlElement(name = "userName")
9.57 + public String getUserName() {
9.58 + return userName;
9.59 + }
9.60 +
9.61 + public void setUserName(String userName) {
9.62 + this.userName = userName;
9.63 + }
9.64 +
9.65 + @XmlElement(name = "password")
9.66 + public String getPassword() {
9.67 + return password;
9.68 + }
9.69 +
9.70 + public void setPassword(String password) {
9.71 + this.password = password;
9.72 + }
9.73 +
9.74 + @XmlTransient
9.75 + public DatabaseConnection connect() {
9.76 + return new DatabaseConnection(this);
9.77 + }
9.78 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/FormatterDefinition.java Sat Dec 21 20:38:50 2013 +0100
10.3 @@ -0,0 +1,90 @@
10.4 +/**
10.5 + * SQL-DK
10.6 + * Copyright © 2013 František Kučera (frantovo.cz)
10.7 + *
10.8 + * This program is free software: you can redistribute it and/or modify
10.9 + * it under the terms of the GNU General Public License as published by
10.10 + * the Free Software Foundation, either version 3 of the License, or
10.11 + * (at your option) any later version.
10.12 + *
10.13 + * This program is distributed in the hope that it will be useful,
10.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.16 + * GNU General Public License for more details.
10.17 + *
10.18 + * You should have received a copy of the GNU General Public License
10.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10.20 + */
10.21 +package info.globalcode.sql.dk.configuration;
10.22 +
10.23 +import info.globalcode.sql.dk.DKException;
10.24 +import info.globalcode.sql.dk.formatting.Formatter;
10.25 +import info.globalcode.sql.dk.formatting.FormatterContext;
10.26 +import java.lang.reflect.Constructor;
10.27 +import java.lang.reflect.InvocationTargetException;
10.28 +import javax.xml.bind.annotation.XmlElement;
10.29 +import javax.xml.bind.annotation.XmlTransient;
10.30 +
10.31 +/**
10.32 + *
10.33 + * @author Ing. František Kučera (frantovo.cz)
10.34 + */
10.35 +public class FormatterDefinition implements NameIdentified {
10.36 +
10.37 + private String name;
10.38 + private String className;
10.39 +
10.40 + @XmlElement(name = "name")
10.41 + @Override
10.42 + public String getName() {
10.43 + return name;
10.44 + }
10.45 +
10.46 + public void setName(String name) {
10.47 + this.name = name;
10.48 + }
10.49 +
10.50 + /**
10.51 + * Filter's class. Must implement the
10.52 + * <code>info.globalcode.sql.dk.formatting.Formatter</code> interface.
10.53 + * Subclassing the
10.54 + * <code>info.globalcode.sql.dk.formatting.AbstractFormatter</code> is strongly recommended.
10.55 + * The constructor must accept one parameter:
10.56 + * <code>info.globalcode.sql.dk.formatting.FormatterContext</code>
10.57 + *
10.58 + * @return fully qualified class name
10.59 + */
10.60 + @XmlElement(name = "class")
10.61 + public String getClassName() {
10.62 + return className;
10.63 + }
10.64 +
10.65 + public void setClassName(String className) {
10.66 + this.className = className;
10.67 + }
10.68 +
10.69 + /**
10.70 + * @param context
10.71 + * @return
10.72 + * @throws DKException
10.73 + */
10.74 + @XmlTransient
10.75 + public Formatter getInstance(FormatterContext context) throws DKException {
10.76 + try {
10.77 + Constructor constructor = Class.forName(className).getConstructor(context.getClass());
10.78 +
10.79 + Object instance = constructor.newInstance(context);
10.80 + if (instance instanceof Formatter) {
10.81 + return (Formatter) instance;
10.82 + } else {
10.83 + throw new DKException("Formatter " + instance + " does not implement the " + Formatter.class.getName() + " interface");
10.84 + }
10.85 + } catch (ClassNotFoundException e) {
10.86 + throw new DKException("No formatter class with name: " + className, e);
10.87 + } catch (NoSuchMethodException e) {
10.88 + throw new DKException("Formatter class with no valid constructor: " + className, e);
10.89 + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
10.90 + throw new DKException("Formatter's constructor caused an error: " + className, e);
10.91 + }
10.92 + }
10.93 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/NameIdentified.java Sat Dec 21 20:38:50 2013 +0100
11.3 @@ -0,0 +1,27 @@
11.4 +/**
11.5 + * SQL-DK
11.6 + * Copyright © 2013 František Kučera (frantovo.cz)
11.7 + *
11.8 + * This program is free software: you can redistribute it and/or modify
11.9 + * it under the terms of the GNU General Public License as published by
11.10 + * the Free Software Foundation, either version 3 of the License, or
11.11 + * (at your option) any later version.
11.12 + *
11.13 + * This program is distributed in the hope that it will be useful,
11.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.16 + * GNU General Public License for more details.
11.17 + *
11.18 + * You should have received a copy of the GNU General Public License
11.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11.20 + */
11.21 +package info.globalcode.sql.dk.configuration;
11.22 +
11.23 +/**
11.24 + *
11.25 + * @author Ing. František Kučera (frantovo.cz)
11.26 + */
11.27 +public interface NameIdentified {
11.28 +
11.29 + public String getName();
11.30 +}