// now add the methods for simplifying the individual field set methods
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("addCriterion"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addBodyLine("if (condition == null) {"); //$NON-NLS-1$
method.addBodyLine("throw new RuntimeException(\"Value for condition cannot be null\");"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("criteria.add(new Criterion(condition));"); //$NON-NLS-1$
if (criteriaLists.size() > 1) {
method.addBodyLine("allCriteria = null;"); //$NON-NLS-1$
}
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("addCriterion"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "property")); //$NON-NLS-1$
method.addBodyLine("if (value == null) {"); //$NON-NLS-1$
method.addBodyLine("throw new RuntimeException(\"Value for \" + property + \" cannot be null\");"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("criteria.add(new Criterion(condition, value));"); //$NON-NLS-1$
if (criteriaLists.size() > 1) {
method.addBodyLine("allCriteria = null;"); //$NON-NLS-1$
}
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("addCriterion"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value1")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value2")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "property")); //$NON-NLS-1$
method.addBodyLine("if (value1 == null || value2 == null) {"); //$NON-NLS-1$
method.addBodyLine("throw new RuntimeException(\"Between values for \" + property + \" cannot be null\");"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("criteria.add(new Criterion(condition, value1, value2));"); //$NON-NLS-1$
if (criteriaLists.size() > 1) {
method.addBodyLine("allCriteria = null;"); //$NON-NLS-1$
}
answer.addMethod(method);
FullyQualifiedJavaType listOfDates = new FullyQualifiedJavaType("java.util.List<java.util.Date>"); //$NON-NLS-1$
if (introspectedTable.hasJDBCDateColumns()) {
topLevelClass.addImportedType(FullyQualifiedJavaType.getDateInstance());
topLevelClass.addImportedType(FullyQualifiedJavaType.getNewIteratorInstance());
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("addCriterionForJDBCDate"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getDateInstance(), "value")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "property")); //$NON-NLS-1$
method.addBodyLine("if (value == null) {"); //$NON-NLS-1$
method.addBodyLine("throw new RuntimeException(\"Value for \" + property + \" cannot be null\");"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("addCriterion(condition, new java.sql.Date(value.getTime()), property);"); //$NON-NLS-1$
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("addCriterionForJDBCDate"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addParameter(new Parameter(listOfDates, "values")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "property")); //$NON-NLS-1$
method.addBodyLine("if (values == null || values.size() == 0) {"); //$NON-NLS-1$
method.addBodyLine("throw new RuntimeException(\"Value list for \" + property + \" cannot be null or empty\");"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("List<java.sql.Date> dateList = new ArrayList<java.sql.Date>();"); //$NON-NLS-1$
method.addBodyLine("Iterator<Date> iter = values.iterator();"); //$NON-NLS-1$
method.addBodyLine("while (iter.hasNext()) {"); //$NON-NLS-1$
method.addBodyLine("dateList.add(new java.sql.Date(iter.next().getTime()));"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("addCriterion(condition, dateList, property);"); //$NON-NLS-1$
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("addCriterionForJDBCDate"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getDateInstance(), "value1")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getDateInstance(), "value2")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "property")); //$NON-NLS-1$
method.addBodyLine("if (value1 == null || value2 == null) {"); //$NON-NLS-1$
method.addBodyLine("throw new RuntimeException(\"Between values for \" + property + \" cannot be null\");"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("addCriterion(condition, new java.sql.Date(value1.getTime()), new java.sql.Date(value2.getTime()), property);"); //$NON-NLS-1$
answer.addMethod(method);
}
if (introspectedTable.hasJDBCTimeColumns()) {
topLevelClass.addImportedType(FullyQualifiedJavaType.getDateInstance());
topLevelClass.addImportedType(FullyQualifiedJavaType.getNewIteratorInstance());
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("addCriterionForJDBCTime"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getDateInstance(), "value")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "property")); //$NON-NLS-1$
method.addBodyLine("if (value == null) {"); //$NON-NLS-1$
method.addBodyLine("throw new RuntimeException(\"Value for \" + property + \" cannot be null\");"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("addCriterion(condition, new java.sql.Time(value.getTime()), property);"); //$NON-NLS-1$
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("addCriterionForJDBCTime"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addParameter(new Parameter(listOfDates, "values")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "property")); //$NON-NLS-1$
method.addBodyLine("if (values == null || values.size() == 0) {"); //$NON-NLS-1$
method.addBodyLine("throw new RuntimeException(\"Value list for \" + property + \" cannot be null or empty\");"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("List<java.sql.Time> timeList = new ArrayList<java.sql.Time>();"); //$NON-NLS-1$
method.addBodyLine("Iterator<Date> iter = values.iterator();"); //$NON-NLS-1$
method.addBodyLine("while (iter.hasNext()) {"); //$NON-NLS-1$
method.addBodyLine("timeList.add(new java.sql.Time(iter.next().getTime()));"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("addCriterion(condition, timeList, property);"); //$NON-NLS-1$
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("addCriterionForJDBCTime"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getDateInstance(), "value1")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getDateInstance(), "value2")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "property")); //$NON-NLS-1$
method.addBodyLine("if (value1 == null || value2 == null) {"); //$NON-NLS-1$
method.addBodyLine("throw new RuntimeException(\"Between values for \" + property + \" cannot be null\");"); //$NON-NLS-1$
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("addCriterion(condition, new java.sql.Time(value1.getTime()), new java.sql.Time(value2.getTime()), property);"); //$NON-NLS-1$
answer.addMethod(method);