java/jdbc-loopback-driver/src/main/java/info/globalcode/jdbc/loopback/Driver.java
author František Kučera <franta-hg@frantovo.cz>
Sun, 04 Feb 2024 16:10:37 +0100
branchv_0
changeset 255 099bb96f8d8d
parent 250 aae5009bd0af
permissions -rw-r--r--
tabular formatter: new option 'separateBy' to print horizontal separator on each change of given column
     1 /**
     2  * SQL-DK
     3  * Copyright © 2014 František Kučera (frantovo.cz)
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 3 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  */
    17 package info.globalcode.jdbc.loopback;
    18 
    19 import java.sql.DriverManager;
    20 import java.sql.DriverPropertyInfo;
    21 import java.sql.SQLException;
    22 import java.sql.SQLFeatureNotSupportedException;
    23 import java.util.Properties;
    24 import java.util.logging.Level;
    25 import java.util.logging.Logger;
    26 
    27 /**
    28  *
    29  * @author Ing. František Kučera (frantovo.cz)
    30  */
    31 public class Driver implements java.sql.Driver {
    32 
    33 	private static final Logger log = Logger.getLogger(Driver.class.getName());
    34 
    35 	static {
    36 		try {
    37 			DriverManager.registerDriver(new Driver());
    38 		} catch (SQLException e) {
    39 			log.log(Level.SEVERE, "Unable to register JDBC driver", e);
    40 		}
    41 	}
    42 
    43 	@Override
    44 	public Connection connect(String url, Properties info) throws SQLException {
    45 		if (acceptsURL(url)) {
    46 			return new Connection(url, info);
    47 		} else {
    48 			// The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL.
    49 			return null;
    50 		}
    51 	}
    52 
    53 	@Override
    54 	public boolean acceptsURL(String url) throws SQLException {
    55 		return url != null && url.startsWith("jdbc:loopback://");
    56 	}
    57 
    58 	@Override
    59 	public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
    60 		return new DriverPropertyInfo[0];
    61 	}
    62 
    63 	@Override
    64 	public int getMajorVersion() {
    65 		return 0;
    66 	}
    67 
    68 	@Override
    69 	public int getMinorVersion() {
    70 		return 1;
    71 	}
    72 
    73 	@Override
    74 	public boolean jdbcCompliant() {
    75 		return false;
    76 	}
    77 
    78 	@Override
    79 	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
    80 		throw new SQLFeatureNotSupportedException("Not supported yet.");
    81 	}
    82 
    83 }