subFiltersList3.add(queryCompoundFilter1);
subFiltersList3.add(queryCompoundFilter2);
QueryFilter queryCompoundFilter3 =
new CompoundFilter(CompoundFilter.LogicalOperator.OR, subFiltersList3);
query.setFilter(queryCompoundFilter3);
StrBuilder queryStringBuilder = new StrBuilder();
SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
assertEquals(queryStringBuilder.toString(),
"WHERE (((`ID`=`Salary`) AND (`ID`>=1.0)) OR ((`Fname` LIKE \"Mi%\") "
+ "AND (`Lname` LIKE \"%SH%\") AND (`Lname` LIKE \"%tz\"))) ",
queryStringBuilder.toString());
// Check empty compound filters.
List<QueryFilter> subFiltersList4 = Lists.newArrayList();
QueryFilter queryCompoundFilter4 =
new CompoundFilter(CompoundFilter.LogicalOperator.OR, subFiltersList4);
query.setFilter(queryCompoundFilter4);
queryStringBuilder = new StrBuilder();
SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
assertEquals(queryStringBuilder.toString(), "WHERE false ");
QueryFilter queryCompoundFilter5 =
new CompoundFilter(CompoundFilter.LogicalOperator.AND, subFiltersList4);
query.setFilter(queryCompoundFilter5);
queryStringBuilder = new StrBuilder();
SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
assertEquals(queryStringBuilder.toString(), "WHERE true ");
// Check compound filter with one sub-filter.
List<QueryFilter> subFiltersList6 = Lists.newArrayList(
(QueryFilter) new ColumnColumnFilter(new SimpleColumn("ID"),
new SimpleColumn("Salary"), ComparisonFilter.Operator.EQ));
QueryFilter queryCompoundFilter6 =
new CompoundFilter(CompoundFilter.LogicalOperator.OR, subFiltersList6);
query.setFilter(queryCompoundFilter6);
queryStringBuilder = new StrBuilder();
SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
assertEquals(queryStringBuilder.toString(), "WHERE ((`ID`=`Salary`)) ",
queryStringBuilder.toString());
// Check "is null".
ColumnIsNullFilter isNullFilter = new ColumnIsNullFilter(new SimpleColumn("ID"));
query.setFilter(isNullFilter);
queryStringBuilder = new StrBuilder();
SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
assertEquals("WHERE (`ID` IS NULL) ", queryStringBuilder.toString());
// Check negation.
NegationFilter negationFilter =
new NegationFilter(new ColumnColumnFilter(new SimpleColumn("ID"),
new SimpleColumn("Salary"), ComparisonFilter.Operator.EQ));
query.setFilter(negationFilter);
queryStringBuilder = new StrBuilder();
SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
assertEquals("WHERE (NOT (`ID`=`Salary`)) ", queryStringBuilder.toString());
}