# HG changeset patch # User František Kučera # Date 1551733372 -3600 # Node ID 39e6c2ad3571eae20cfc22996256342f8020422a # Parent 4a1864c3e8677599dbaeddf0c3fbf8b298243d6f mavenized: jdbc-dk-driver diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/build.xml --- a/java/jdbc-dk-driver/build.xml Mon Mar 04 20:15:24 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project jdbc-dk-driver. - - - diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/conf/META-INF/services/java.sql.Driver --- a/java/jdbc-dk-driver/conf/META-INF/services/java.sql.Driver Mon Mar 04 20:15:24 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -info.globalcode.sql.dk.jdbc.Driver diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/libs/sql-dk --- a/java/jdbc-dk-driver/libs/sql-dk Mon Mar 04 20:15:24 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -../../sql-dk/src \ No newline at end of file diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/nbproject/build-impl.xml --- a/java/jdbc-dk-driver/nbproject/build-impl.xml Mon Mar 04 20:15:24 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1438 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.conf.dir - Must set src.dir - Must set src.sql-dk.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No tests executed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - Must select one file in the IDE or set profile.class - This target only works when run from inside the NetBeans IDE. - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - - - Must select some files in the IDE or set test.includes - - - - - Must select one file in the IDE or set run.class - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - Must select some files in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - Must select one file in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/nbproject/genfiles.properties --- a/java/jdbc-dk-driver/nbproject/genfiles.properties Mon Mar 04 20:15:24 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -build.xml.data.CRC32=50d83c90 -build.xml.script.CRC32=3b53b17c -build.xml.stylesheet.CRC32=8064a381@1.75.2.48 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=50d83c90 -nbproject/build-impl.xml.script.CRC32=71784fcc -nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/nbproject/project.properties --- a/java/jdbc-dk-driver/nbproject/project.properties Mon Mar 04 20:15:24 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=jdbc-dk-driver -application.vendor=fiki -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/jdbc-dk-driver.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.8 -javac.target=1.8 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=true -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.conf.dir=conf -src.dir=src -src.sql-dk.dir=libs/sql-dk -test.src.dir=test diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/nbproject/project.xml --- a/java/jdbc-dk-driver/nbproject/project.xml Mon Mar 04 20:15:24 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - jdbc-dk-driver - - - - - - - - - - - diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/jdbc-dk-driver/pom.xml Mon Mar 04 22:02:52 2019 +0100 @@ -0,0 +1,21 @@ + + + 4.0.0 + info.globalcode.sql.dk + jdbc-dk-driver + 0.10-SNAPSHOT + jar + + + info.globalcode.sql.dk + sql-dk + ${project.version} + jar + + + + UTF-8 + 1.8 + 1.8 + + diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/src/info/globalcode/sql/dk/jdbc/Driver.java --- a/java/jdbc-dk-driver/src/info/globalcode/sql/dk/jdbc/Driver.java Mon Mar 04 20:15:24 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,157 +0,0 @@ -/** - * SQL-DK - * Copyright © 2015 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 . - */ -package info.globalcode.sql.dk.jdbc; - -import info.globalcode.sql.dk.Constants; -import info.globalcode.sql.dk.configuration.Configuration; -import info.globalcode.sql.dk.configuration.ConfigurationException; -import info.globalcode.sql.dk.configuration.DatabaseDefinition; -import info.globalcode.sql.dk.configuration.Loader; -import info.globalcode.sql.dk.configuration.Properties; -import info.globalcode.sql.dk.configuration.Property; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.DriverPropertyInfo; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - *

- * Meta JDBC driver that works as redirector/router. It loads SQL-DK's configuration file and - * instantiates a real JDBC connection (PostgreSQL, MariDB etc.) of given name. - *

- * - *

- * Raison d'être: user can define his/her database connections just once (in SQL-DK's configuration) - * and use them in many other programs – there is no need to define the connection (hostname, - * username, password, properties…) in each application again and again. User will simply connect to - * e.g. jdbc:sql-dk://my-connection and this driver reads parameters of - * my-connection from SQL-DK's configuration and returns real driver implementation. - *

- * - *

- * Of course, the real JDBC driver for given database is still needed on the class path. - *

- * - *

- * TODO: current version is quite heavy-weight, because it includes whole SQL-DK source tree. Some - * refactoring and separation is desired to provide more light-weight JDBC driver. However the - * public interface and behavior of this driver should remain unchanged. - *

- * - * @author Ing. František Kučera (frantovo.cz) - */ -public class Driver implements java.sql.Driver { - - private static final Logger log = Logger.getLogger(Driver.class.getName()); - - private final Loader loader = new Loader(); - - static { - try { - DriverManager.registerDriver(new Driver()); - } catch (SQLException e) { - log.log(Level.SEVERE, "Unable to register JDBC driver", e); - } - } - - @Override - public Connection connect(String url, java.util.Properties info) throws SQLException { - if (acceptsURL(url)) { - log.log(Level.FINER, "Loading SQL-DK configuration for URL: {0}", url); - String name = extractDatabaseName(url); - log.log(Level.FINE, "Loading SQL-DK configuration for name: {0}", name); - - try { - return getConnection(name, info); - } catch (ConfigurationException e) { - log.log(Level.SEVERE, "Unable to load SQL-DK configuration for name: {0}. Is it defined in {1}?", new Object[]{name, Constants.CONFIG_FILE}); - throw new SQLException("Unable to load SQL-DK configuration for name: " + name, e); - } - } else { - // The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. - return null; - } - } - - private Connection getConnection(String connectionName, java.util.Properties info) throws SQLException, ConfigurationException { - Configuration c = loader.loadConfiguration(); - DatabaseDefinition dd = c.getDatabase(connectionName); - - if (acceptsURL(dd.getUrl())) { - log.log(Level.SEVERE, "SQL-DK meta JDBC driver loops to itself: {0} → {1} Please check {2}", new Object[]{connectionName, dd.getUrl(), Constants.CONFIG_FILE}); - throw new ConfigurationException("SQL-DK meta JDBC driver loops to itself."); - } else { - return Loader.jdbcConnect(dd, translate(info)); - } - } - - private String extractDatabaseName(String url) { - return url.split("//", 2)[1]; - } - - /** - * TODO: refactor/move, reuse - * - * @param info - * @return - */ - private Properties translate(java.util.Properties info) { - Properties properties = new Properties(); - - for (String name : info.stringPropertyNames()) { - String value = info.getProperty(name); - properties.add(new Property(name, value)); - } - - return properties; - } - - @Override - public boolean acceptsURL(String url) throws SQLException { - return url != null && url.startsWith("jdbc:sql-dk://"); - } - - @Override - public DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info) throws SQLException { - return new DriverPropertyInfo[0]; - } - - @Override - public int getMajorVersion() { - return 0; - } - - @Override - public int getMinorVersion() { - return 1; - } - - @Override - public boolean jdbcCompliant() { - return false; - } - - @Override - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new SQLFeatureNotSupportedException("Not supported yet."); - } - -} diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/src/main/java/info/globalcode/sql/dk/jdbc/Driver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/jdbc-dk-driver/src/main/java/info/globalcode/sql/dk/jdbc/Driver.java Mon Mar 04 22:02:52 2019 +0100 @@ -0,0 +1,157 @@ +/** + * SQL-DK + * Copyright © 2015 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 . + */ +package info.globalcode.sql.dk.jdbc; + +import info.globalcode.sql.dk.Constants; +import info.globalcode.sql.dk.configuration.Configuration; +import info.globalcode.sql.dk.configuration.ConfigurationException; +import info.globalcode.sql.dk.configuration.DatabaseDefinition; +import info.globalcode.sql.dk.configuration.Loader; +import info.globalcode.sql.dk.configuration.Properties; +import info.globalcode.sql.dk.configuration.Property; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.DriverPropertyInfo; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + *

+ * Meta JDBC driver that works as redirector/router. It loads SQL-DK's configuration file and + * instantiates a real JDBC connection (PostgreSQL, MariDB etc.) of given name. + *

+ * + *

+ * Raison d'être: user can define his/her database connections just once (in SQL-DK's configuration) + * and use them in many other programs – there is no need to define the connection (hostname, + * username, password, properties…) in each application again and again. User will simply connect to + * e.g. jdbc:sql-dk://my-connection and this driver reads parameters of + * my-connection from SQL-DK's configuration and returns real driver implementation. + *

+ * + *

+ * Of course, the real JDBC driver for given database is still needed on the class path. + *

+ * + *

+ * TODO: current version is quite heavy-weight, because it includes whole SQL-DK source tree. Some + * refactoring and separation is desired to provide more light-weight JDBC driver. However the + * public interface and behavior of this driver should remain unchanged. + *

+ * + * @author Ing. František Kučera (frantovo.cz) + */ +public class Driver implements java.sql.Driver { + + private static final Logger log = Logger.getLogger(Driver.class.getName()); + + private final Loader loader = new Loader(); + + static { + try { + DriverManager.registerDriver(new Driver()); + } catch (SQLException e) { + log.log(Level.SEVERE, "Unable to register JDBC driver", e); + } + } + + @Override + public Connection connect(String url, java.util.Properties info) throws SQLException { + if (acceptsURL(url)) { + log.log(Level.FINER, "Loading SQL-DK configuration for URL: {0}", url); + String name = extractDatabaseName(url); + log.log(Level.FINE, "Loading SQL-DK configuration for name: {0}", name); + + try { + return getConnection(name, info); + } catch (ConfigurationException e) { + log.log(Level.SEVERE, "Unable to load SQL-DK configuration for name: {0}. Is it defined in {1}?", new Object[]{name, Constants.CONFIG_FILE}); + throw new SQLException("Unable to load SQL-DK configuration for name: " + name, e); + } + } else { + // The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. + return null; + } + } + + private Connection getConnection(String connectionName, java.util.Properties info) throws SQLException, ConfigurationException { + Configuration c = loader.loadConfiguration(); + DatabaseDefinition dd = c.getDatabase(connectionName); + + if (acceptsURL(dd.getUrl())) { + log.log(Level.SEVERE, "SQL-DK meta JDBC driver loops to itself: {0} → {1} Please check {2}", new Object[]{connectionName, dd.getUrl(), Constants.CONFIG_FILE}); + throw new ConfigurationException("SQL-DK meta JDBC driver loops to itself."); + } else { + return Loader.jdbcConnect(dd, translate(info)); + } + } + + private String extractDatabaseName(String url) { + return url.split("//", 2)[1]; + } + + /** + * TODO: refactor/move, reuse + * + * @param info + * @return + */ + private Properties translate(java.util.Properties info) { + Properties properties = new Properties(); + + for (String name : info.stringPropertyNames()) { + String value = info.getProperty(name); + properties.add(new Property(name, value)); + } + + return properties; + } + + @Override + public boolean acceptsURL(String url) throws SQLException { + return url != null && url.startsWith("jdbc:sql-dk://"); + } + + @Override + public DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info) throws SQLException { + return new DriverPropertyInfo[0]; + } + + @Override + public int getMajorVersion() { + return 0; + } + + @Override + public int getMinorVersion() { + return 1; + } + + @Override + public boolean jdbcCompliant() { + return false; + } + + @Override + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + throw new SQLFeatureNotSupportedException("Not supported yet."); + } + +} diff -r 4a1864c3e867 -r 39e6c2ad3571 java/jdbc-dk-driver/src/main/resources/META-INF/services/java.sql.Driver --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/jdbc-dk-driver/src/main/resources/META-INF/services/java.sql.Driver Mon Mar 04 22:02:52 2019 +0100 @@ -0,0 +1,1 @@ +info.globalcode.sql.dk.jdbc.Driver