@Test public void testGenerateWhereClause() throws Exception { CompositeCriteria compositeCriteria = new CompositeCriteria(); compositeCriteria.setOperator(CompositeCriteria.Operator.AND); FilterCriteria fCrit1 = createFilterCriteria("myCol1", FilterCriteria.Operation.EQUAL, "fu"); FilterCriteria fCrit2 = createFilterCriteria("myCol2", FilterCriteria.Operation.EQUAL, "bar"); CompositeCriteria cCrit2 = createCompositCriteria(new Criteria[]{fCrit1,fCrit2}, CompositeCriteria.Operator.OR); SqlStatement stmt = generator.generateWhereClause(compositeCriteria); Assert.assertTrue("".equals(stmt.getSqlText())); Assert.assertTrue(stmt.getHostVariableValueList().size()==0); compositeCriteria.setSearchCriteria(new CompositeCriteria[0]); stmt = generator.generateWhereClause(compositeCriteria); Assert.assertTrue("".equals(stmt.getSqlText())); Assert.assertTrue(stmt.getHostVariableValueList().size()==0); compositeCriteria.setSearchCriteria(new Criteria[]{fCrit1,fCrit2,cCrit2}); System.out.println(generator.generateWhereClause(compositeCriteria)); stmt = generator.generateWhereClause(compositeCriteria); Assert.assertTrue("where myCol1 =? and myCol2 =? and (myCol1 =? or myCol2 =?)".equals(stmt.getSqlText())); Assert.assertTrue(stmt.getHostVariableValueList().size()==4); Assert.assertTrue("fu".equals(stmt.getHostVariableValueList().get(0))); Assert.assertTrue("bar".equals(stmt.getHostVariableValueList().get(1))); Assert.assertTrue("fu".equals(stmt.getHostVariableValueList().get(2))); Assert.assertTrue("bar".equals(stmt.getHostVariableValueList().get(3))); }
protected SqlStatement generateWhereClause(CompositeCriteria searchCriteria) { if (searchCriteria.getSearchCriteria() == null) { return new SqlStatement(""); } if (searchCriteria.getSearchCriteria().length == 0) { return new SqlStatement(""); } SqlStatement sqlStatement = new SqlStatement(); StringBuilder builder = new StringBuilder(); for (Criteria criteria : searchCriteria.getSearchCriteria()) { if (builder.length() == 0) { builder.append("where "); } else { builder.append(" "); builder.append(searchCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, sqlStatement.getHostVariableValueList()); } sqlStatement.setSqlText(builder.toString()); return sqlStatement; }
DefaultSqlGenerator implements SqlGenerator { protected SqlStatement generateWhereClause(CompositeCriteria searchCriteria) { if (searchCriteria.getSearchCriteria() == null) { return new SqlStatement(""); } if (searchCriteria.getSearchCriteria().length == 0) { return new SqlStatement(""); } SqlStatement sqlStatement = new SqlStatement(); StringBuilder builder = new StringBuilder(); for (Criteria criteria : searchCriteria.getSearchCriteria()) { if (builder.length() == 0) { builder.append("where "); } else { builder.append(" "); builder.append(searchCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, sqlStatement.getHostVariableValueList()); } sqlStatement.setSqlText(builder.toString()); return sqlStatement; } }
DefaultSqlGenerator implements SqlGenerator { protected SqlStatement generateWhereClause(CompositeCriteria searchCriteria) { if (searchCriteria.getSearchCriteria() == null) { return new SqlStatement(""); } if (searchCriteria.getSearchCriteria().length == 0) { return new SqlStatement(""); } SqlStatement sqlStatement = new SqlStatement(); StringBuilder builder = new StringBuilder(); for (Criteria criteria : searchCriteria.getSearchCriteria()) { if (builder.length() == 0) { builder.append("where "); } else { builder.append(" "); builder.append(searchCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, sqlStatement.getHostVariableValueList()); } sqlStatement.setSqlText(builder.toString()); return sqlStatement; } DefaultSqlGenerator(); }
DefaultSqlGenerator implements SqlGenerator { protected SqlStatement generateWhereClause(CompositeCriteria searchCriteria) { if (searchCriteria.getSearchCriteria() == null) { return new SqlStatement(""); } if (searchCriteria.getSearchCriteria().length == 0) { return new SqlStatement(""); } SqlStatement sqlStatement = new SqlStatement(); StringBuilder builder = new StringBuilder(); for (Criteria criteria : searchCriteria.getSearchCriteria()) { if (builder.length() == 0) { builder.append("where "); } else { builder.append(" "); builder.append(searchCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, sqlStatement.getHostVariableValueList()); } sqlStatement.setSqlText(builder.toString()); return sqlStatement; } DefaultSqlGenerator(); SqlStatement generateSelect(Topic topic, CompositeCriteria searchCriteria,
			String[] fieldNames); }
DefaultSqlGenerator implements SqlGenerator { protected SqlStatement generateWhereClause(CompositeCriteria searchCriteria) { if (searchCriteria.getSearchCriteria() == null) { return new SqlStatement(""); } if (searchCriteria.getSearchCriteria().length == 0) { return new SqlStatement(""); } SqlStatement sqlStatement = new SqlStatement(); StringBuilder builder = new StringBuilder(); for (Criteria criteria : searchCriteria.getSearchCriteria()) { if (builder.length() == 0) { builder.append("where "); } else { builder.append(" "); builder.append(searchCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, sqlStatement.getHostVariableValueList()); } sqlStatement.setSqlText(builder.toString()); return sqlStatement; } DefaultSqlGenerator(); SqlStatement generateSelect(Topic topic, CompositeCriteria searchCriteria,
			String[] fieldNames);  }