java/jdbc-loopback-driver/src/main/java/info/globalcode/jdbc/loopback/Driver.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/jdbc-loopback-driver/src/main/java/info/globalcode/jdbc/loopback/Driver.java Mon Mar 04 17:06:42 2019 +0100
1.3 @@ -0,0 +1,84 @@
1.4 +/**
1.5 + * SQL-DK
1.6 + * Copyright © 2014 František Kučera (frantovo.cz)
1.7 + *
1.8 + * This program is free software: you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License as published by
1.10 + * the Free Software Foundation, either version 3 of the License, or
1.11 + * (at your option) any later version.
1.12 + *
1.13 + * This program is distributed in the hope that it will be useful,
1.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.16 + * GNU General Public License for more details.
1.17 + *
1.18 + * You should have received a copy of the GNU General Public License
1.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.20 + */
1.21 +package info.globalcode.jdbc.loopback;
1.22 +
1.23 +import java.sql.DriverManager;
1.24 +import java.sql.DriverPropertyInfo;
1.25 +import java.sql.SQLException;
1.26 +import java.sql.SQLFeatureNotSupportedException;
1.27 +import java.util.Properties;
1.28 +import java.util.logging.Level;
1.29 +import java.util.logging.Logger;
1.30 +
1.31 +/**
1.32 + *
1.33 + * @author Ing. František Kučera (frantovo.cz)
1.34 + */
1.35 +public class Driver implements java.sql.Driver {
1.36 +
1.37 + private static final Logger log = Logger.getLogger(Driver.class.getName());
1.38 +
1.39 + static {
1.40 + try {
1.41 + DriverManager.registerDriver(new Driver());
1.42 + } catch (SQLException e) {
1.43 + log.log(Level.SEVERE, "Unable to register JDBC driver", e);
1.44 + }
1.45 + }
1.46 +
1.47 + @Override
1.48 + public Connection connect(String url, Properties info) throws SQLException {
1.49 + if (acceptsURL(url)) {
1.50 + return new Connection(url, info);
1.51 + } else {
1.52 + // The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL.
1.53 + return null;
1.54 + }
1.55 + }
1.56 +
1.57 + @Override
1.58 + public boolean acceptsURL(String url) throws SQLException {
1.59 + return url != null && url.startsWith("jdbc:loopback://");
1.60 + }
1.61 +
1.62 + @Override
1.63 + public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
1.64 + return new DriverPropertyInfo[0];
1.65 + }
1.66 +
1.67 + @Override
1.68 + public int getMajorVersion() {
1.69 + return 0;
1.70 + }
1.71 +
1.72 + @Override
1.73 + public int getMinorVersion() {
1.74 + return 1;
1.75 + }
1.76 +
1.77 + @Override
1.78 + public boolean jdbcCompliant() {
1.79 + return false;
1.80 + }
1.81 +
1.82 + @Override
1.83 + public Logger getParentLogger() throws SQLFeatureNotSupportedException {
1.84 + throw new SQLFeatureNotSupportedException("Not supported yet.");
1.85 + }
1.86 +
1.87 +}