@Test( expected = NullPointerException.class ) public void testCreateConnectionWithoutUrl() throws SQLException { provider.createConnection( "user", "password" ); }
public Connection createConnection( final String user, final String password ) throws SQLException { if ( url == null ) { throw new NullPointerException( "URL must not be null when connecting" ); } Driver driverImpl = null; try { if ( driver != null ) { driverImpl = ObjectUtilities.loadAndInstantiate( driver, getClass(), Driver.class ); if ( driverImpl == null ) { logger.warn( "Unable to load specified driver class: " + driver + ". See ObjectUtilities logger for error details." ); } } } catch ( Throwable e ) { throw new SQLException( "Unable to load the driver: " + driver, e.getMessage() ); } final Properties p = new Properties(); for ( final Map.Entry entry : properties.entrySet() ) { final String entryKey = (String) entry.getKey(); if ( isFilteredKey( entryKey ) ) { continue; } p.setProperty( entryKey, (String) entry.getValue() ); } if ( user != null ) { p.setProperty( "user", user ); } if ( password != null ) { p.setProperty( "password", password ); } final Connection connection; if ( driverImpl != null ) { connection = driverImpl.connect( url, p ); } else { connection = DriverManager.getConnection( url, p ); } if ( connection == null ) { throw new SQLException( "Driver Manager returned no connection. Your java-implementation is weird." ); } String sqlConnect = p.getProperty( "SQL_CONNECT" ); if ( !StringUtils.isEmpty( sqlConnect ) ) { SqlScriptUtils.execStatements( sqlConnect, connection, false ); } return connection; }
DriverConnectionProvider implements ConnectionProvider { public Connection createConnection( final String user, final String password ) throws SQLException { if ( url == null ) { throw new NullPointerException( "URL must not be null when connecting" ); } Driver driverImpl = null; try { if ( driver != null ) { driverImpl = ObjectUtilities.loadAndInstantiate( driver, getClass(), Driver.class ); if ( driverImpl == null ) { logger.warn( "Unable to load specified driver class: " + driver + ". See ObjectUtilities logger for error details." ); } } } catch ( Throwable e ) { throw new SQLException( "Unable to load the driver: " + driver, e.getMessage() ); } final Properties p = new Properties(); for ( final Map.Entry entry : properties.entrySet() ) { final String entryKey = (String) entry.getKey(); if ( isFilteredKey( entryKey ) ) { continue; } p.setProperty( entryKey, (String) entry.getValue() ); } if ( user != null ) { p.setProperty( "user", user ); } if ( password != null ) { p.setProperty( "password", password ); } final Connection connection; if ( driverImpl != null ) { connection = driverImpl.connect( url, p ); } else { connection = DriverManager.getConnection( url, p ); } if ( connection == null ) { throw new SQLException( "Driver Manager returned no connection. Your java-implementation is weird." ); } String sqlConnect = p.getProperty( "SQL_CONNECT" ); if ( !StringUtils.isEmpty( sqlConnect ) ) { SqlScriptUtils.execStatements( sqlConnect, connection, false ); } return connection; } }
DriverConnectionProvider implements ConnectionProvider { public Connection createConnection( final String user, final String password ) throws SQLException { if ( url == null ) { throw new NullPointerException( "URL must not be null when connecting" ); } Driver driverImpl = null; try { if ( driver != null ) { driverImpl = ObjectUtilities.loadAndInstantiate( driver, getClass(), Driver.class ); if ( driverImpl == null ) { logger.warn( "Unable to load specified driver class: " + driver + ". See ObjectUtilities logger for error details." ); } } } catch ( Throwable e ) { throw new SQLException( "Unable to load the driver: " + driver, e.getMessage() ); } final Properties p = new Properties(); for ( final Map.Entry entry : properties.entrySet() ) { final String entryKey = (String) entry.getKey(); if ( isFilteredKey( entryKey ) ) { continue; } p.setProperty( entryKey, (String) entry.getValue() ); } if ( user != null ) { p.setProperty( "user", user ); } if ( password != null ) { p.setProperty( "password", password ); } final Connection connection; if ( driverImpl != null ) { connection = driverImpl.connect( url, p ); } else { connection = DriverManager.getConnection( url, p ); } if ( connection == null ) { throw new SQLException( "Driver Manager returned no connection. Your java-implementation is weird." ); } String sqlConnect = p.getProperty( "SQL_CONNECT" ); if ( !StringUtils.isEmpty( sqlConnect ) ) { SqlScriptUtils.execStatements( sqlConnect, connection, false ); } return connection; } DriverConnectionProvider(); }
DriverConnectionProvider implements ConnectionProvider { public Connection createConnection( final String user, final String password ) throws SQLException { if ( url == null ) { throw new NullPointerException( "URL must not be null when connecting" ); } Driver driverImpl = null; try { if ( driver != null ) { driverImpl = ObjectUtilities.loadAndInstantiate( driver, getClass(), Driver.class ); if ( driverImpl == null ) { logger.warn( "Unable to load specified driver class: " + driver + ". See ObjectUtilities logger for error details." ); } } } catch ( Throwable e ) { throw new SQLException( "Unable to load the driver: " + driver, e.getMessage() ); } final Properties p = new Properties(); for ( final Map.Entry entry : properties.entrySet() ) { final String entryKey = (String) entry.getKey(); if ( isFilteredKey( entryKey ) ) { continue; } p.setProperty( entryKey, (String) entry.getValue() ); } if ( user != null ) { p.setProperty( "user", user ); } if ( password != null ) { p.setProperty( "password", password ); } final Connection connection; if ( driverImpl != null ) { connection = driverImpl.connect( url, p ); } else { connection = DriverManager.getConnection( url, p ); } if ( connection == null ) { throw new SQLException( "Driver Manager returned no connection. Your java-implementation is weird." ); } String sqlConnect = p.getProperty( "SQL_CONNECT" ); if ( !StringUtils.isEmpty( sqlConnect ) ) { SqlScriptUtils.execStatements( sqlConnect, connection, false ); } return connection; } DriverConnectionProvider(); String getProperty( final String key ); Object setProperty( final String key, final String value ); String getUrl(); void setUrl( final String url ); String getDriver(); void setDriver( final String driver ); Connection createConnection( final String user, final String password ); Object getConnectionHash(); String[] getPropertyNames(); boolean equals( final Object o ); int hashCode(); }
DriverConnectionProvider implements ConnectionProvider { public Connection createConnection( final String user, final String password ) throws SQLException { if ( url == null ) { throw new NullPointerException( "URL must not be null when connecting" ); } Driver driverImpl = null; try { if ( driver != null ) { driverImpl = ObjectUtilities.loadAndInstantiate( driver, getClass(), Driver.class ); if ( driverImpl == null ) { logger.warn( "Unable to load specified driver class: " + driver + ". See ObjectUtilities logger for error details." ); } } } catch ( Throwable e ) { throw new SQLException( "Unable to load the driver: " + driver, e.getMessage() ); } final Properties p = new Properties(); for ( final Map.Entry entry : properties.entrySet() ) { final String entryKey = (String) entry.getKey(); if ( isFilteredKey( entryKey ) ) { continue; } p.setProperty( entryKey, (String) entry.getValue() ); } if ( user != null ) { p.setProperty( "user", user ); } if ( password != null ) { p.setProperty( "password", password ); } final Connection connection; if ( driverImpl != null ) { connection = driverImpl.connect( url, p ); } else { connection = DriverManager.getConnection( url, p ); } if ( connection == null ) { throw new SQLException( "Driver Manager returned no connection. Your java-implementation is weird." ); } String sqlConnect = p.getProperty( "SQL_CONNECT" ); if ( !StringUtils.isEmpty( sqlConnect ) ) { SqlScriptUtils.execStatements( sqlConnect, connection, false ); } return connection; } DriverConnectionProvider(); String getProperty( final String key ); Object setProperty( final String key, final String value ); String getUrl(); void setUrl( final String url ); String getDriver(); void setDriver( final String driver ); Connection createConnection( final String user, final String password ); Object getConnectionHash(); String[] getPropertyNames(); boolean equals( final Object o ); int hashCode();  }