public TemplateForReportTemplateSearchVoCollection listTemplates(String reportSearchText, String templateSearchText) { StringBuffer hql = new StringBuffer(); StringBuffer cond = new StringBuffer(); ArrayList<String> markers = new ArrayList<String>(); ArrayList<Object> values = new ArrayList<Object>(); if (reportSearchText == null || reportSearchText.length() == 0) { reportSearchText = "%"; } else { if(!reportSearchText.startsWith("%")) reportSearchText = "%" + reportSearchText; if(!reportSearchText.endsWith("%")) reportSearchText = reportSearchText + "%"; } if (templateSearchText == null || templateSearchText.length() == 0) { templateSearchText = "%"; } else { if(!templateSearchText.startsWith("%")) templateSearchText = "%" + templateSearchText; if(!templateSearchText.endsWith("%")) templateSearchText = templateSearchText + "%"; } String andStr = " "; hql.append("select template from TemplateBo as template left join template.report as report "); cond.append(andStr + "report.isActive = :isActive"); markers.add("isActive"); values.add(Boolean.TRUE); andStr = " and "; cond.append(andStr + "UPPER(report.reportName) like UPPER(:reportName)"); markers.add("reportName"); values.add(reportSearchText); andStr = " and "; cond.append(andStr + "template.isActive = :isActive"); markers.add("isActive"); values.add(Boolean.TRUE); andStr = " and "; cond.append(andStr + "UPPER(template.name) like UPPER(:templateName)"); markers.add("templateName"); values.add(templateSearchText); andStr = " and "; if (andStr.equals(" and ")) { hql.append(" where "); } hql.append(cond.toString()); DomainFactory factory = getDomainFactory(); List <?>list = factory.find(hql.toString(), markers, values); return TemplateForReportTemplateSearchVoAssembler.createTemplateForReportTemplateSearchVoCollectionFromTemplateBo(list).sort(); }