@Test public void testConnect() throws Exception { final AlternativeDriver orange = new AlternativeDriver(new jdbcDriver(), "jdbc:hsqldb:mem:orange"); final Driver general = DriverManager.getDriver(orange.getUrl()); assertNotSame(general, orange); orange.register(); assertSame(orange, DriverManager.getDriver(orange.getUrl())); assertSame(general, DriverManager.getDriver(orange.getUrl() + "foo")); final AlternativeDriver green = new AlternativeDriver(new jdbcDriver(), "jdbc:hsqldb:mem:green"); green.register(); assertSame(orange, DriverManager.getDriver(orange.getUrl())); assertSame(green, DriverManager.getDriver(green.getUrl())); assertSame(general, DriverManager.getDriver(orange.getUrl() + "foo")); assertSame(general, DriverManager.getDriver(green.getUrl() + "bar")); final AlternativeDriver green2 = new AlternativeDriver(new jdbcDriver(), "jdbc:hsqldb:mem:green"); green2.register(); assertSame(orange, DriverManager.getDriver(orange.getUrl())); assertSame(green2, DriverManager.getDriver(green.getUrl())); assertSame(general, DriverManager.getDriver(orange.getUrl() + "foo")); assertSame(general, DriverManager.getDriver(green.getUrl() + "bar")); green2.deregister(); assertSame(orange, DriverManager.getDriver(orange.getUrl())); assertSame(green, DriverManager.getDriver(green.getUrl())); assertSame(general, DriverManager.getDriver(orange.getUrl() + "foo")); assertSame(general, DriverManager.getDriver(green.getUrl() + "bar")); }
@Override public Connection connect(final String url, final Properties info) throws SQLException { if (acceptsURL(url)) { return getDelegate().connect(url, info); } return null; }
AlternativeDriver implements Driver { @Override public Connection connect(final String url, final Properties info) throws SQLException { if (acceptsURL(url)) { return getDelegate().connect(url, info); } return null; } }
AlternativeDriver implements Driver { @Override public Connection connect(final String url, final Properties info) throws SQLException { if (acceptsURL(url)) { return getDelegate().connect(url, info); } return null; } AlternativeDriver(final Driver driver, final String url); }
AlternativeDriver implements Driver { @Override public Connection connect(final String url, final Properties info) throws SQLException { if (acceptsURL(url)) { return getDelegate().connect(url, info); } return null; } AlternativeDriver(final Driver driver, final String url); Driver getDelegate(); String getUrl(); void register(); void deregister(); @Override Connection connect(final String url, final Properties info); @Override boolean acceptsURL(final String url); @Override DriverPropertyInfo[] getPropertyInfo(final String url, final Properties info); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); Logger getParentLogger(); }
AlternativeDriver implements Driver { @Override public Connection connect(final String url, final Properties info) throws SQLException { if (acceptsURL(url)) { return getDelegate().connect(url, info); } return null; } AlternativeDriver(final Driver driver, final String url); Driver getDelegate(); String getUrl(); void register(); void deregister(); @Override Connection connect(final String url, final Properties info); @Override boolean acceptsURL(final String url); @Override DriverPropertyInfo[] getPropertyInfo(final String url, final Properties info); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); Logger getParentLogger();  }