@Test public void testFormatCompositeCriteria() throws Exception { CompositeCriteria compositeCriteria = new CompositeCriteria(); List<Object> hostVariableValueList = new ArrayList<Object>(); Throwable exceptionThrown = null; try {generator.formatCompositeCriteria(null, hostVariableValueList);} catch (Exception e) { exceptionThrown = e; } Assert.assertTrue(exceptionThrown != null); Assert.assertTrue(exceptionThrown.getMessage().contains("compositeCriteria")); Assert.assertTrue(hostVariableValueList.size()==0); exceptionThrown = null; try {generator.formatCompositeCriteria(compositeCriteria, hostVariableValueList);} catch (Exception e) { exceptionThrown = e; } Assert.assertTrue(exceptionThrown != null); Assert.assertTrue(exceptionThrown.getMessage().contains("operator")); Assert.assertTrue(hostVariableValueList.size()==0); compositeCriteria.setOperator(CompositeCriteria.Operator.AND); Assert.assertTrue("".equals(generator.formatCompositeCriteria(compositeCriteria, hostVariableValueList))); Assert.assertTrue(hostVariableValueList.size()==0); compositeCriteria.setSearchCriteria(new CompositeCriteria[0]); Assert.assertTrue("".equals(generator.formatCompositeCriteria(compositeCriteria, hostVariableValueList))); Assert.assertTrue(hostVariableValueList.size()==0); 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); compositeCriteria.setSearchCriteria(new Criteria[]{fCrit1,fCrit2,cCrit2}); Assert.assertTrue("(myCol1 =? and myCol2 =? and (myCol1 =? or myCol2 =?))".equals(generator.formatCompositeCriteria(compositeCriteria, hostVariableValueList))); Assert.assertTrue(hostVariableValueList.size()==4); Assert.assertTrue("fu".equals(hostVariableValueList.get(0))); Assert.assertTrue("bar".equals(hostVariableValueList.get(1))); Assert.assertTrue("fu".equals(hostVariableValueList.get(2))); Assert.assertTrue("bar".equals(hostVariableValueList.get(3))); }
protected String formatCompositeCriteria(CompositeCriteria compositeCriteria, List<Object> hostVariableValueList) { Validate.notNull(compositeCriteria, "Null compositeCriteria not allowed. criteria="+compositeCriteria); Validate.notNull(compositeCriteria.getOperator(), "Null compositeCriteria operator not allowed. criteria="+compositeCriteria); if (compositeCriteria.getSearchCriteria() == null) { return ""; } if (compositeCriteria.getSearchCriteria().length == 0) { return ""; } StringBuilder builder = new StringBuilder("("); for (Criteria criteria: compositeCriteria.getSearchCriteria()) { if (builder.length() > 1) { builder.append(" "); builder.append(compositeCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, hostVariableValueList); } builder.append(")"); return builder.toString(); }
DefaultSqlGenerator implements SqlGenerator { protected String formatCompositeCriteria(CompositeCriteria compositeCriteria, List<Object> hostVariableValueList) { Validate.notNull(compositeCriteria, "Null compositeCriteria not allowed. criteria="+compositeCriteria); Validate.notNull(compositeCriteria.getOperator(), "Null compositeCriteria operator not allowed. criteria="+compositeCriteria); if (compositeCriteria.getSearchCriteria() == null) { return ""; } if (compositeCriteria.getSearchCriteria().length == 0) { return ""; } StringBuilder builder = new StringBuilder("("); for (Criteria criteria: compositeCriteria.getSearchCriteria()) { if (builder.length() > 1) { builder.append(" "); builder.append(compositeCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, hostVariableValueList); } builder.append(")"); return builder.toString(); } }
DefaultSqlGenerator implements SqlGenerator { protected String formatCompositeCriteria(CompositeCriteria compositeCriteria, List<Object> hostVariableValueList) { Validate.notNull(compositeCriteria, "Null compositeCriteria not allowed. criteria="+compositeCriteria); Validate.notNull(compositeCriteria.getOperator(), "Null compositeCriteria operator not allowed. criteria="+compositeCriteria); if (compositeCriteria.getSearchCriteria() == null) { return ""; } if (compositeCriteria.getSearchCriteria().length == 0) { return ""; } StringBuilder builder = new StringBuilder("("); for (Criteria criteria: compositeCriteria.getSearchCriteria()) { if (builder.length() > 1) { builder.append(" "); builder.append(compositeCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, hostVariableValueList); } builder.append(")"); return builder.toString(); } DefaultSqlGenerator(); }
DefaultSqlGenerator implements SqlGenerator { protected String formatCompositeCriteria(CompositeCriteria compositeCriteria, List<Object> hostVariableValueList) { Validate.notNull(compositeCriteria, "Null compositeCriteria not allowed. criteria="+compositeCriteria); Validate.notNull(compositeCriteria.getOperator(), "Null compositeCriteria operator not allowed. criteria="+compositeCriteria); if (compositeCriteria.getSearchCriteria() == null) { return ""; } if (compositeCriteria.getSearchCriteria().length == 0) { return ""; } StringBuilder builder = new StringBuilder("("); for (Criteria criteria: compositeCriteria.getSearchCriteria()) { if (builder.length() > 1) { builder.append(" "); builder.append(compositeCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, hostVariableValueList); } builder.append(")"); return builder.toString(); } DefaultSqlGenerator(); SqlStatement generateSelect(Topic topic, CompositeCriteria searchCriteria,
			String[] fieldNames); }
DefaultSqlGenerator implements SqlGenerator { protected String formatCompositeCriteria(CompositeCriteria compositeCriteria, List<Object> hostVariableValueList) { Validate.notNull(compositeCriteria, "Null compositeCriteria not allowed. criteria="+compositeCriteria); Validate.notNull(compositeCriteria.getOperator(), "Null compositeCriteria operator not allowed. criteria="+compositeCriteria); if (compositeCriteria.getSearchCriteria() == null) { return ""; } if (compositeCriteria.getSearchCriteria().length == 0) { return ""; } StringBuilder builder = new StringBuilder("("); for (Criteria criteria: compositeCriteria.getSearchCriteria()) { if (builder.length() > 1) { builder.append(" "); builder.append(compositeCriteria.getOperator().toString().toLowerCase()); builder.append(" "); } appendCriteria(builder, criteria, hostVariableValueList); } builder.append(")"); return builder.toString(); } DefaultSqlGenerator(); SqlStatement generateSelect(Topic topic, CompositeCriteria searchCriteria,
			String[] fieldNames);  }