@Override public boolean acceptsURL(String url) throws SQLException { return driver.acceptsURL(url); }
@Override public boolean acceptsURL( String url ) throws SQLException { return driver.acceptsURL( url ); }
@Override public boolean acceptsURL(String u) throws SQLException { return this.driver.acceptsURL(u); }
@Override public boolean acceptsURL(String u) throws SQLException { return this.driver.acceptsURL(u); }
/** * Wraps the underlying driver's call to acceptsURL. Returns whether or not * the driver can open a connection to the given URL. * * @param url the URL of the database * @return true if the wrapped driver can connect to the specified URL * @throws SQLException thrown if there is an error connecting to the * database * @see java.sql.Driver#acceptsURL(java.lang.String) */ @Override public boolean acceptsURL(String url) throws SQLException { return this.driver.acceptsURL(url); }
public static Connection getConnection(String url) throws SQLException { for (Driver driver : registeredDrivers) { if (driver.acceptsURL(url)) { return driver.connect(url); } } throw new SQLException("No suitable driver"); }
private Driver findRegisteredDriver(String url) { for (Enumeration drivers = DriverManager.getDrivers(); drivers != null && drivers.hasMoreElements();) { Driver driver = (Driver) drivers.nextElement(); try { if (driver.acceptsURL(url)) { return driver; } } catch (Exception e) { } } return null; }
public Driver findLocalDriver(String url) throws Exception { if(drivers == null){ return null; } for (Driver d : drivers) { try { String clazzName = d.getClass().getName(); Driver driver = (Driver) Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader()).newInstance(); if (driver.acceptsURL(url) && isSupportedLocalDriver(driver)) { return driver; } } catch (SQLException e) { error(e); throw new Exception(e); } } return null; }
public Connection getConnectionFromLocalDriver(String url, Properties properties) { Collection<Driver> drivers = beeLine.getDrivers(); for (Driver d : drivers) { try { if (d.acceptsURL(url) && beeLine.isSupportedLocalDriver(d)) { String clazzName = d.getClass().getName(); beeLine.debug("Driver name is " + clazzName); Driver driver = (Driver) Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader()) .newInstance(); return driver.connect(url, properties); } } catch (Exception e) { beeLine.error("Fail to connect with a local driver due to the exception:" + e); beeLine.error(e); } } return null; }
/** * Tries to find a driver that can interpret the supplied URL. * * @param url * the URL of a database. * @return a {@code Driver} that matches the provided URL. {@code null} if * no {@code Driver} understands the URL * @throws SQLException * if there is any kind of problem accessing the database. */ public static Driver getDriver(String url) throws SQLException { ClassLoader callerClassLoader = VMStack.getCallingClassLoader(); synchronized (theDrivers) { /* * Loop over the drivers in the DriverSet checking to see if one * does understand the supplied URL - return the first driver which * does understand the URL */ for (Driver driver : theDrivers) { if (driver.acceptsURL(url) && DriverManager.isClassFromClassLoader(driver, callerClassLoader)) { return driver; } } } // If no drivers understand the URL, throw an SQLException // SQLState: 08 - connection exception // 001 - SQL-client unable to establish SQL-connection throw new SQLException("No suitable driver", "08001"); }
LOGGER.debug("Loaded driver with class name {} for jdbcUrl={}", driver.getClass().getName(), sanitizedUrl); else if (!driver.acceptsURL(jdbcUrl)) { throw new RuntimeException("Driver " + driverClassName + " claims to not accept jdbcUrl, " + sanitizedUrl);
public BasicDataSource getDataSource(String uri) throws DBConnectionException { synchronized (this) { try { BasicDataSource ds = dsMap.get(uri); if (ds == null) { Driver driver = null; for (Driver test : drivers) { if (test.acceptsURL(uri)) { driver = test; break; } } if (driver == null) { DriverManager.getDriver(uri); } ds = new BasicDataSource(); ds.setDriver(driver); ds.setUrl(uri); dsMap.put(uri, ds); } return ds; } catch (SQLException e) { //Logger.getLogger(JDBCClient.class.getName()).log(Level.SEVERE, null, e); throw new DBConnectionException(uri, e); } } }
@Override public boolean acceptsURL(String u) throws SQLException { return this.driver.acceptsURL(u); }
@Override public boolean acceptsURL(String u) throws SQLException { return this.driver.acceptsURL(u); }
"jdbc:proxy:org.apache.drill.jdbc.Driver:jdbc:drill:zk=local" ); assertThat( driver.acceptsURL( "jdbc:proxy::jdbc:drill:zk=local" ), equalTo( true ) ); assertThat( driver.acceptsURL( "jdbc:drill:zk=local" ), equalTo( false ) );
class DriverShim implements Driver { private Driver driver; DriverShim(Driver d) { this.driver = d; } public boolean acceptsURL(String u) throws SQLException { return this.driver.acceptsURL(u); } public Connection connect(String u, Properties p) throws SQLException { return this.driver.connect(u, p); } // and so on....
protected Driver findPassthru(String url) throws SQLException { // registers the passthru drivers, if configured s P6ModuleManager.getInstance(); String realUrl = extractRealUrl(url); Driver passthru = null; for (Driver driver: registeredDrivers() ) { try { if (driver.acceptsURL(extractRealUrl(url))) { passthru = driver; break; } } catch (SQLException e) { } } if( passthru == null ) { throw new SQLException("Unable to find a driver that accepts " + realUrl); } return passthru; }
@Test public void testNotAccept() throws Exception { Driver driver = new PhoenixDriver(); assertFalse(driver.acceptsURL("jdbc:phoenix://localhost")); assertFalse(driver.acceptsURL("jdbc:phoenix:localhost;test=true;bar=foo")); assertFalse(driver.acceptsURL("jdbc:phoenix:localhost;test=true")); assertTrue(driver.acceptsURL("jdbc:phoenix:localhost:123")); assertTrue(driver.acceptsURL("jdbc:phoenix:localhost:123;untest=true")); assertTrue(driver.acceptsURL("jdbc:phoenix:localhost:123;untest=true;foo=bar")); DriverManager.deregisterDriver(driver); }
@Test public void testNotAccept() throws Exception { Driver driver = new PhoenixDriver(); assertFalse(driver.acceptsURL("jdbc:phoenix://localhost")); assertFalse(driver.acceptsURL("jdbc:phoenix:localhost;test=true;bar=foo")); assertFalse(driver.acceptsURL("jdbc:phoenix:localhost;test=true")); assertTrue(driver.acceptsURL("jdbc:phoenix:localhost:123")); assertTrue(driver.acceptsURL("jdbc:phoenix:localhost:123;untest=true")); assertTrue(driver.acceptsURL("jdbc:phoenix:localhost:123;untest=true;foo=bar")); DriverManager.deregisterDriver(driver); } }
@Test public void testDriverCohabitation() throws SQLException { Driver thickDriver = null; Driver thinDriver = null; for (Driver d : Collections.list(DriverManager.getDrivers())) { if (d instanceof org.apache.phoenix.jdbc.PhoenixDriver) { thickDriver = d; } else if (d instanceof org.apache.phoenix.queryserver.client.Driver) { thinDriver = d; } } assertNotNull("Thick driver not registered with DriverManager.", thickDriver); assertNotNull("Thin driver not registered with DriverManager.", thinDriver); final String thickUrl = QueryUtil.getUrl("localhost"); final String thinUrl = ThinClientUtil.getConnectionUrl("localhost", 1234); assertTrue("Thick driver should accept connections like " + thickUrl, thickDriver.acceptsURL(thickUrl)); assertFalse("Thick driver should reject connections like " + thinUrl, thickDriver.acceptsURL(thinUrl)); assertTrue("Thin driver should accept connections like " + thinUrl, thinDriver.acceptsURL(thinUrl)); assertFalse("Thin driver should reject connections like " + thickUrl, thinDriver.acceptsURL(thickUrl)); } }