@Test public void testQueryData() throws Exception { ScriptableDataFactory dataFactory = spy( new ScriptableDataFactory() ); dataFactory.setQuery( QUERY_NAME, QUERY_VALUE ); dataFactory.setLanguage( LANGUAGE ); DataRow parameters = mock( DataRow.class ); BSFManager interpreter = mock( BSFManager.class ); TableModel tableModel = mock( TableModel.class ); when( dataFactory.createInterpreter() ).thenReturn( interpreter ); doReturn( tableModel ).when( interpreter ).eval( LANGUAGE, "expression", 1, 1, QUERY_VALUE ); TableModel result = dataFactory.queryData( QUERY_NAME, parameters ); assertThat( result, is( equalTo( tableModel ) ) ); }
public TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { final String queryScript = queries.get( query ); if ( queryScript == null ) { throw new ReportDataFactoryException( "No such query" ); } if ( interpreter == null ) { try { this.interpreter = createInterpreter(); } catch ( BSFException e ) { throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e ); } } try { dataRowWrapper.setParent( parameters ); final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, queryScript ); if ( o instanceof TableModel == false ) { throw new ReportDataFactoryException( "Resulting value is not a tablemodel" ); } return (TableModel) o; } catch ( ReportDataFactoryException rde ) { throw rde; } catch ( Exception e ) { throw new ReportDataFactoryException( "Evaluation error", e ); } }
ScriptableDataFactory extends AbstractDataFactory { public TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { final String queryScript = queries.get( query ); if ( queryScript == null ) { throw new ReportDataFactoryException( "No such query" ); } if ( interpreter == null ) { try { this.interpreter = createInterpreter(); } catch ( BSFException e ) { throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e ); } } try { dataRowWrapper.setParent( parameters ); final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, queryScript ); if ( o instanceof TableModel == false ) { throw new ReportDataFactoryException( "Resulting value is not a tablemodel" ); } return (TableModel) o; } catch ( ReportDataFactoryException rde ) { throw rde; } catch ( Exception e ) { throw new ReportDataFactoryException( "Evaluation error", e ); } } }
ScriptableDataFactory extends AbstractDataFactory { public TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { final String queryScript = queries.get( query ); if ( queryScript == null ) { throw new ReportDataFactoryException( "No such query" ); } if ( interpreter == null ) { try { this.interpreter = createInterpreter(); } catch ( BSFException e ) { throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e ); } } try { dataRowWrapper.setParent( parameters ); final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, queryScript ); if ( o instanceof TableModel == false ) { throw new ReportDataFactoryException( "Resulting value is not a tablemodel" ); } return (TableModel) o; } catch ( ReportDataFactoryException rde ) { throw rde; } catch ( Exception e ) { throw new ReportDataFactoryException( "Evaluation error", e ); } } ScriptableDataFactory(); }
ScriptableDataFactory extends AbstractDataFactory { public TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { final String queryScript = queries.get( query ); if ( queryScript == null ) { throw new ReportDataFactoryException( "No such query" ); } if ( interpreter == null ) { try { this.interpreter = createInterpreter(); } catch ( BSFException e ) { throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e ); } } try { dataRowWrapper.setParent( parameters ); final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, queryScript ); if ( o instanceof TableModel == false ) { throw new ReportDataFactoryException( "Resulting value is not a tablemodel" ); } return (TableModel) o; } catch ( ReportDataFactoryException rde ) { throw rde; } catch ( Exception e ) { throw new ReportDataFactoryException( "Evaluation error", e ); } } ScriptableDataFactory(); String getLanguage(); void setLanguage( final String language ); void setQuery( final String name, final String value ); String getScript(); void setScript( final String script ); String getShutdownScript(); void setShutdownScript( final String shutdownScript ); String getQuery( final String name ); String[] getQueryNames(); TableModel queryData( final String query, final DataRow parameters ); ScriptableDataFactory clone(); DataFactory derive(); void close(); boolean isQueryExecutable( final String query, final DataRow parameters ); void cancelRunningQuery(); }
ScriptableDataFactory extends AbstractDataFactory { public TableModel queryData( final String query, final DataRow parameters ) throws ReportDataFactoryException { final String queryScript = queries.get( query ); if ( queryScript == null ) { throw new ReportDataFactoryException( "No such query" ); } if ( interpreter == null ) { try { this.interpreter = createInterpreter(); } catch ( BSFException e ) { throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e ); } } try { dataRowWrapper.setParent( parameters ); final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, queryScript ); if ( o instanceof TableModel == false ) { throw new ReportDataFactoryException( "Resulting value is not a tablemodel" ); } return (TableModel) o; } catch ( ReportDataFactoryException rde ) { throw rde; } catch ( Exception e ) { throw new ReportDataFactoryException( "Evaluation error", e ); } } ScriptableDataFactory(); String getLanguage(); void setLanguage( final String language ); void setQuery( final String name, final String value ); String getScript(); void setScript( final String script ); String getShutdownScript(); void setShutdownScript( final String shutdownScript ); String getQuery( final String name ); String[] getQueryNames(); TableModel queryData( final String query, final DataRow parameters ); ScriptableDataFactory clone(); DataFactory derive(); void close(); boolean isQueryExecutable( final String query, final DataRow parameters ); void cancelRunningQuery();  }