SQLConnection implements IPentahoLoggingConnection, ILimitableConnection { public boolean connect( final Properties props ) { close(); String jndiName = props.getProperty( IPentahoConnection.JNDI_NAME_KEY ); if ( ( jndiName != null ) && ( jndiName.length() > 0 ) ) { initWithJNDI( jndiName ); } else { String connectionName = props.getProperty( IPentahoConnection.CONNECTION_NAME ); if ( ( connectionName != null ) && ( connectionName.length() > 0 ) ) { IDatabaseConnection databaseConnection = (IDatabaseConnection) props.get( IPentahoConnection.CONNECTION ); initDataSource( databaseConnection ); } else { String driver = props.getProperty( IPentahoConnection.DRIVER_KEY ); String provider = props.getProperty( IPentahoConnection.LOCATION_KEY ); String userName = props.getProperty( IPentahoConnection.USERNAME_KEY ); String password = props.getProperty( IPentahoConnection.PASSWORD_KEY ); init( driver, provider, userName, password ); String query = props.getProperty( IPentahoConnection.QUERY_KEY ); if ( ( query != null ) && ( query.length() > 0 ) ) { try { executeQuery( query ); } catch ( Exception e ) { logger.error( "Can't execute query", e ); } } } } return ( ( nativeConnection != null ) && !isClosed() ); } SQLConnection();  SQLConnection( final String driverName, final String location, final String userName, final String password,
      final ILogger logger ); void setLogger( final ILogger logger ); void setProperties( Properties props ); void setQueryTimeout( final int timeInSec ); void setReadOnly( final boolean value ); int getQueryTimeout(); boolean initialized(); String getDatasourceType(); void close(); String getLastQuery(); IPentahoResultSet executeQuery( final String query ); IPentahoResultSet executeQuery( final String query, final int scrollType, final int concur ); IPentahoResultSet prepareAndExecuteQuery( final String query, final List parameters ); IPentahoResultSet prepareAndExecuteQuery( final String query, final List parameters, final int scrollType,
      final int concur ); boolean preparedQueriesSupported(); boolean isClosed(); boolean isReadOnly(); void clearWarnings(); IPentahoResultSet getResultSet(); boolean connect( final Properties props ); int execute( final String query ); int execute( final String query, final int scrollType, final int concur ); Connection getNativeConnection(); int getFetchSize(); void setFetchSize( final int fetchSize ); int getMaxRows(); void setMaxRows( final int maxRows ); boolean getReadOnly(); void setFallBackToNonscrollableOnError( boolean fallBackToNonscrollableOnError ); boolean isFallBackToNonscrollableOnError(); boolean isForcedForwardOnly(); void setForcedForwardOnly( boolean forcedForwardOnly ); static final int RESULTSET_SCROLLABLE; static final int RESULTSET_FORWARDONLY; static final int CONCUR_READONLY; static final int CONCUR_UPDATABLE; }
@Test public void testConnect() throws Exception { SQLConnection sqlc = spy( new SQLConnection() ); Properties props = new Properties(); props = new Properties(); props.put( IPentahoConnection.JNDI_NAME_KEY, "test" ); assertTrue( "JNDI Test", sqlc.connect( props ) ); props = new Properties(); doNothing().when( sqlc ).close(); doNothing().when( sqlc ).init( anyString(), anyString(), anyString(), anyString() ); assertTrue( "NonPool Test", sqlc.connect( props ) ); doNothing().when( sqlc ).initDataSource( any( IDatabaseConnection.class ) ); props.put( IPentahoConnection.CONNECTION_NAME, "test" ); assertTrue( "Pool Test", sqlc.connect( props ) ); }