## ============================================================================ ## Filename : FWJavaBeanAbstractSearchCriteriaDataTemplate.vm ## Note(s) : This template is used to generate the base class for all ## Java Bean Search Criteria Data classes. It is intended to be ## used along with the JavaBeanDAOTemplate.vm file. ## ## Copyright (c) 2007 ThinkUI Software Inc. All rights reserved. ## ============================================================================ ## ## **************************************************************************** ## The following variables are available in this template. For more ## information on any of the following variable, please refer to the user guide. ## **************************************************************************** ## $projectName ## $authorName ## $headerText ## $className ## $packageName ## $subPackageName ## $prjPkgName ## $prjClassPrefix ## $superClassName ## $date ## $codeGen ## #if ($packageName) package $packageName; #end #parse( "ClassHeaderInclude.vm" ) /** * Provides an abstract implemention of the SearchCriteriaData interface. * All search criteria classes should extend from this class and use * the appropriate appendSQLExpr() method to implement the getSQLExpr() method. */ public abstract class ${className} implements SearchCriteriaData { // The following fields are used to perform incremental search // (i.e. next/prev functions) private int startIndex = 0; private int maxObjectCount = -1; /** * ${className} constructor. */ public ${className}() { super(); } public final int getStartIndex() { return startIndex; } public final void setStartIndex(int startIndex) { this.startIndex = startIndex; } public final int getMaxObjectCount() { return maxObjectCount; } public final void setMaxObjectCount(int maxObjectCount) { this.maxObjectCount = maxObjectCount; } protected final StringBuffer appendSQLExpr(StringBuffer sb, String columnName, String value) { // Don't include nulls or empty strings. // Reason to exclude empty strings is it appears that you CANNOT insert an empty string // to a varchar2 column in ORACLE (tried on 9i). In which case to test for empty string // will always fail. Instead, must use the "is null" operator instead. if (value != null && !value.equals("")) { return appendSQLExpr(sb, columnName, SQLUtils.escapeSQL(value)); } return sb; } protected final StringBuffer appendSQLExpr(StringBuffer sb, String columnName, java.sql.Date value) { if (value != null) { return appendSQLExpr(sb, columnName, (Object) ("{ts '"+value+"'}")); } return sb; } protected final StringBuffer appendSQLExpr(StringBuffer sb, String columnName, Object value) { if (value != null) { if (sb == null) { sb = new StringBuffer(); } else { sb.append(" AND "); } sb.append(columnName); sb.append("="); sb.append(value); } return sb; } }