java/jdbc-loopback-driver/src/main/java/info/globalcode/jdbc/loopback/Driver.java
branchv_0
changeset 237 7e08730da258
parent 235 8ce612cca4d8
child 250 aae5009bd0af
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/jdbc-loopback-driver/src/main/java/info/globalcode/jdbc/loopback/Driver.java	Mon Mar 04 17:06:42 2019 +0100
@@ -0,0 +1,84 @@
+/**
+ * SQL-DK
+ * Copyright © 2014 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.jdbc.loopback;
+
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @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());
+
+	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, Properties info) throws SQLException {
+		if (acceptsURL(url)) {
+			return new Connection(url, info);
+		} else {
+			// The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL.
+			return null;
+		}
+	}
+
+	@Override
+	public boolean acceptsURL(String url) throws SQLException {
+		return url != null && url.startsWith("jdbc:loopback://");
+	}
+
+	@Override
+	public DriverPropertyInfo[] getPropertyInfo(String url, 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.");
+	}
+
+}