@Test public void testQueryData() throws ReportDataFactoryException, SQLException { DataRow parameters = mock( DataRow.class ); TableModel model = mock( TableModel.class ); String[] preparedParameterNames = new String[] {}; doReturn( model ).when( factory ).parametrizeAndQuery( parameters, QUERY, preparedParameterNames ); TableModel result = factory.queryData( QUERY, parameters ); assertThat( result, is( equalTo( model ) ) ); }
public synchronized TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { try { final ParametrizationProviderFactory factory = createParametrizationProviderFactory(); final Connection connection = getConnection( parameters ); final ParametrizationProvider parametrizationProvider = factory.create( connection ); final String translatedQuery = parametrizationProvider.rewriteQueryForParametrization( connection, query, parameters ); final String[] preparedParameterNames = parametrizationProvider.getPreparedParameterNames(); if ( logger.isDebugEnabled() ) { logger.debug( "Translated-Query: " + translatedQuery ); logger.debug( "Detected parameter:" + Arrays.asList( preparedParameterNames ) ); } return parametrizeAndQuery( parameters, translatedQuery, preparedParameterNames ); } catch ( SQLTimeoutException e ) { throw new ReportDataFactoryQueryTimeoutException(); } catch ( Exception e ) { throw new ReportDataFactoryException( "Failed at query: " + query, e ); } finally { currentRunningStatement = null; } }
SimpleSQLReportDataFactory extends AbstractDataFactory { public synchronized TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { try { final ParametrizationProviderFactory factory = createParametrizationProviderFactory(); final Connection connection = getConnection( parameters ); final ParametrizationProvider parametrizationProvider = factory.create( connection ); final String translatedQuery = parametrizationProvider.rewriteQueryForParametrization( connection, query, parameters ); final String[] preparedParameterNames = parametrizationProvider.getPreparedParameterNames(); if ( logger.isDebugEnabled() ) { logger.debug( "Translated-Query: " + translatedQuery ); logger.debug( "Detected parameter:" + Arrays.asList( preparedParameterNames ) ); } return parametrizeAndQuery( parameters, translatedQuery, preparedParameterNames ); } catch ( SQLTimeoutException e ) { throw new ReportDataFactoryQueryTimeoutException(); } catch ( Exception e ) { throw new ReportDataFactoryException( "Failed at query: " + query, e ); } finally { currentRunningStatement = null; } } }
SimpleSQLReportDataFactory extends AbstractDataFactory { public synchronized TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { try { final ParametrizationProviderFactory factory = createParametrizationProviderFactory(); final Connection connection = getConnection( parameters ); final ParametrizationProvider parametrizationProvider = factory.create( connection ); final String translatedQuery = parametrizationProvider.rewriteQueryForParametrization( connection, query, parameters ); final String[] preparedParameterNames = parametrizationProvider.getPreparedParameterNames(); if ( logger.isDebugEnabled() ) { logger.debug( "Translated-Query: " + translatedQuery ); logger.debug( "Detected parameter:" + Arrays.asList( preparedParameterNames ) ); } return parametrizeAndQuery( parameters, translatedQuery, preparedParameterNames ); } catch ( SQLTimeoutException e ) { throw new ReportDataFactoryQueryTimeoutException(); } catch ( Exception e ) { throw new ReportDataFactoryException( "Failed at query: " + query, e ); } finally { currentRunningStatement = null; } } SimpleSQLReportDataFactory();  SimpleSQLReportDataFactory( final Connection connection );  SimpleSQLReportDataFactory( final ConnectionProvider connectionProvider ); }
SimpleSQLReportDataFactory extends AbstractDataFactory { public synchronized TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { try { final ParametrizationProviderFactory factory = createParametrizationProviderFactory(); final Connection connection = getConnection( parameters ); final ParametrizationProvider parametrizationProvider = factory.create( connection ); final String translatedQuery = parametrizationProvider.rewriteQueryForParametrization( connection, query, parameters ); final String[] preparedParameterNames = parametrizationProvider.getPreparedParameterNames(); if ( logger.isDebugEnabled() ) { logger.debug( "Translated-Query: " + translatedQuery ); logger.debug( "Detected parameter:" + Arrays.asList( preparedParameterNames ) ); } return parametrizeAndQuery( parameters, translatedQuery, preparedParameterNames ); } catch ( SQLTimeoutException e ) { throw new ReportDataFactoryQueryTimeoutException(); } catch ( Exception e ) { throw new ReportDataFactoryException( "Failed at query: " + query, e ); } finally { currentRunningStatement = null; } } SimpleSQLReportDataFactory();  SimpleSQLReportDataFactory( final Connection connection );  SimpleSQLReportDataFactory( final ConnectionProvider connectionProvider ); String getUserField(); void setUserField( final String userField ); String getPasswordField(); void setPasswordField( final String passwordField ); int getBestResultSetType( final DataRow dataRow ); synchronized TableModel queryData( final String query, final DataRow parameters ); String[] getReferencedFields( final String query, final DataRow parameters ); static boolean isExpandArrayParameterNeeded( final String query ); ResultSet performQuery( Statement statement, final String translatedQuery, final String[] preparedParameterNames ); void cancelRunningQuery(); synchronized void close(); SimpleSQLReportDataFactory clone(); void setConnectionProvider( final ConnectionProvider connectionProvider ); ConnectionProvider getConnectionProvider(); boolean isQueryExecutable( final String query, final DataRow parameters ); String[] getQueryNames(); ArrayList<Object> getQueryHash( final String queryName, final DataRow parameter ); }
SimpleSQLReportDataFactory extends AbstractDataFactory { public synchronized TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { try { final ParametrizationProviderFactory factory = createParametrizationProviderFactory(); final Connection connection = getConnection( parameters ); final ParametrizationProvider parametrizationProvider = factory.create( connection ); final String translatedQuery = parametrizationProvider.rewriteQueryForParametrization( connection, query, parameters ); final String[] preparedParameterNames = parametrizationProvider.getPreparedParameterNames(); if ( logger.isDebugEnabled() ) { logger.debug( "Translated-Query: " + translatedQuery ); logger.debug( "Detected parameter:" + Arrays.asList( preparedParameterNames ) ); } return parametrizeAndQuery( parameters, translatedQuery, preparedParameterNames ); } catch ( SQLTimeoutException e ) { throw new ReportDataFactoryQueryTimeoutException(); } catch ( Exception e ) { throw new ReportDataFactoryException( "Failed at query: " + query, e ); } finally { currentRunningStatement = null; } } SimpleSQLReportDataFactory();  SimpleSQLReportDataFactory( final Connection connection );  SimpleSQLReportDataFactory( final ConnectionProvider connectionProvider ); String getUserField(); void setUserField( final String userField ); String getPasswordField(); void setPasswordField( final String passwordField ); int getBestResultSetType( final DataRow dataRow ); synchronized TableModel queryData( final String query, final DataRow parameters ); String[] getReferencedFields( final String query, final DataRow parameters ); static boolean isExpandArrayParameterNeeded( final String query ); ResultSet performQuery( Statement statement, final String translatedQuery, final String[] preparedParameterNames ); void cancelRunningQuery(); synchronized void close(); SimpleSQLReportDataFactory clone(); void setConnectionProvider( final ConnectionProvider connectionProvider ); ConnectionProvider getConnectionProvider(); boolean isQueryExecutable( final String query, final DataRow parameters ); String[] getQueryNames(); ArrayList<Object> getQueryHash( final String queryName, final DataRow parameter ); static Configuration globalConfig; }