TableInputParameterGeneration implements ParameterGenerationService { protected void convertCondition( Condition condition, StringBuilder builder, RowMeta paramsMeta, List<Object> params ) throws PushDownOptimizationException { if ( condition.isNegated() ) { builder.append( "NOT " ); } if ( condition.isComposite() ) { builder.append( "( " ); for ( Condition child : condition.getChildren() ) { if ( child.getOperator() == Condition.OPERATOR_AND ) { builder.append( " AND " ); } else if ( child.getOperator() == Condition.OPERATOR_OR ) { builder.append( " OR " ); } convertCondition( child, builder, paramsMeta, params ); } builder.append( " )" ); } else { builder.append( convertAtomicCondition( condition, paramsMeta, params ) ); } } TableInputParameterGeneration( ValueMetaResolver resolver ); @Override String getParameterDefault(); @Override OptimizationImpactInfo preview( Condition pushDownCondition, ParameterGeneration parameterGeneration, StepInterface stepInterface ); @Override void pushDown( Condition condition, ParameterGeneration parameterGeneration, StepInterface stepInterface );  }
@Test public void testConvertCondition() throws Exception { Condition condition = new Condition(); condition.addCondition( newCondition( "A", "valA" ) ); condition.getCondition( 0 ).addCondition( newCondition( OR, "B", 32 ) ); condition.addCondition( newCondition( AND, "C", "valC" ) ); condition.getCondition( 1 ).negate(); StringBuilder sqlBuilder = new StringBuilder(); RowMeta paramsMeta = mock( RowMeta.class ); List<Object> values = new LinkedList<Object>(); service.convertCondition( condition, sqlBuilder, paramsMeta, values ); assertThat( sqlBuilder.toString(), equalTo( "( ( A = ? OR B = ? ) AND NOT C = ? )" ) ); verify( paramsMeta, times( 3 ) ).addValueMeta( resolvedValueMeta ); verify( databaseMeta, times( 3 ) ).quoteField( anyString() ); assertThat( values, equalTo( Arrays.<Object>asList( "valA", 32, "valC" ) ) ); }