return answer;
}
private InnerClass getGeneratedCriteriaInnerClass(
TopLevelClass topLevelClass) {
Field field;
Method method;
InnerClass answer = new InnerClass(FullyQualifiedJavaType
.getGeneratedCriteriaInstance());
answer.setVisibility(JavaVisibility.PROTECTED);
answer.setStatic(true);
answer.setAbstract(true);
context.getCommentGenerator().addClassComment(answer,
introspectedTable);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setName("GeneratedCriteria"); //$NON-NLS-1$
method.setConstructor(true);
method.addBodyLine("super();"); //$NON-NLS-1$
method.addBodyLine("criteria = new ArrayList<Criterion>();"); //$NON-NLS-1$
answer.addMethod(method);
List<String> criteriaLists = new ArrayList<String>();
criteriaLists.add("criteria"); //$NON-NLS-1$
for (IntrospectedColumn introspectedColumn : introspectedTable
.getNonBLOBColumns()) {
if (stringHasValue(introspectedColumn
.getTypeHandler())) {
String name = addtypeHandledObjectsAndMethods(
introspectedColumn, method, answer);
criteriaLists.add(name);
}
}
// now generate the isValid method
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setName("isValid"); //$NON-NLS-1$
method.setReturnType(FullyQualifiedJavaType
.getBooleanPrimitiveInstance());
StringBuilder sb = new StringBuilder();
Iterator<String> strIter = criteriaLists.iterator();
sb.append("return "); //$NON-NLS-1$
sb.append(strIter.next());
sb.append(".size() > 0"); //$NON-NLS-1$
if (!strIter.hasNext()) {
sb.append(';');
}
method.addBodyLine(sb.toString());
while (strIter.hasNext()) {
sb.setLength(0);
OutputUtilities.javaIndent(sb, 1);
sb.append("|| "); //$NON-NLS-1$
sb.append(strIter.next());
sb.append(".size() > 0"); //$NON-NLS-1$
if (!strIter.hasNext()) {
sb.append(';');
}
method.addBodyLine(sb.toString());
}
answer.addMethod(method);
// now generate the getAllCriteria method
if (criteriaLists.size() > 1) {
field = new Field();
field.setName("allCriteria"); //$NON-NLS-1$
field.setType(new FullyQualifiedJavaType("List<Criterion>")); //$NON-NLS-1$
field.setVisibility(JavaVisibility.PROTECTED);
answer.addField(field);
}
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setName("getAllCriteria"); //$NON-NLS-1$
method.setReturnType(new FullyQualifiedJavaType("List<Criterion>")); //$NON-NLS-1$
if (criteriaLists.size() < 2) {
method.addBodyLine("return criteria;"); //$NON-NLS-1$
} else {
method.addBodyLine("if (allCriteria == null) {"); //$NON-NLS-1$
method.addBodyLine("allCriteria = new ArrayList<Criterion>();"); //$NON-NLS-1$
strIter = criteriaLists.iterator();
while (strIter.hasNext()) {
method.addBodyLine(String.format("allCriteria.addAll(%s);", strIter.next())); //$NON-NLS-1$
}
method.addBodyLine("}"); //$NON-NLS-1$
method.addBodyLine("return allCriteria;"); //$NON-NLS-1$
}
answer.addMethod(method);
// now we need to generate the methods that will be used in the SqlMap
// to generate the dynamic where clause
topLevelClass.addImportedType(FullyQualifiedJavaType
.getNewListInstance());
topLevelClass.addImportedType(FullyQualifiedJavaType
.getNewArrayListInstance());
field = new Field();
field.setVisibility(JavaVisibility.PROTECTED);
FullyQualifiedJavaType listOfCriterion = new FullyQualifiedJavaType(
"java.util.List<Criterion>"); //$NON-NLS-1$
field.setType(listOfCriterion);
field.setName("criteria"); //$NON-NLS-1$
answer.addField(field);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(field.getType());
method.setName(getGetterMethodName(field.getName(), field
.getType()));
method.addBodyLine("return criteria;"); //$NON-NLS-1$
answer.addMethod(method);
// now add the methods for simplifying the individual field set methods