use of org.mybatis.generator.api.dom.java.InnerClass in project generator by mybatis.
the class ExampleGenerator method getCriterionInnerClass.
private InnerClass getCriterionInnerClass() {
Field field;
Method method;
InnerClass answer = new InnerClass(new FullyQualifiedJavaType(//$NON-NLS-1$
"Criterion"));
answer.setVisibility(JavaVisibility.PUBLIC);
answer.setStatic(true);
context.getCommentGenerator().addClassComment(answer, introspectedTable);
field = new Field();
//$NON-NLS-1$
field.setName("condition");
field.setType(FullyQualifiedJavaType.getStringInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("value");
field.setType(FullyQualifiedJavaType.getObjectInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("secondValue");
field.setType(FullyQualifiedJavaType.getObjectInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("noValue");
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("singleValue");
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("betweenValue");
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("listValue");
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("typeHandler");
field.setType(FullyQualifiedJavaType.getStringInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
//$NON-NLS-1$
method.addBodyLine("super();");
//$NON-NLS-1$
method.addBodyLine("this.condition = condition;");
//$NON-NLS-1$
method.addBodyLine("this.typeHandler = null;");
//$NON-NLS-1$
method.addBodyLine("this.noValue = true;");
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"value"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"typeHandler"));
//$NON-NLS-1$
method.addBodyLine("super();");
//$NON-NLS-1$
method.addBodyLine("this.condition = condition;");
//$NON-NLS-1$
method.addBodyLine("this.value = value;");
//$NON-NLS-1$
method.addBodyLine("this.typeHandler = typeHandler;");
//$NON-NLS-1$
method.addBodyLine("if (value instanceof List<?>) {");
//$NON-NLS-1$
method.addBodyLine("this.listValue = true;");
//$NON-NLS-1$
method.addBodyLine("} else {");
//$NON-NLS-1$
method.addBodyLine("this.singleValue = true;");
//$NON-NLS-1$
method.addBodyLine("}");
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"value"));
//$NON-NLS-1$
method.addBodyLine("this(condition, value, null);");
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"value"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"secondValue"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"typeHandler"));
//$NON-NLS-1$
method.addBodyLine("super();");
//$NON-NLS-1$
method.addBodyLine("this.condition = condition;");
//$NON-NLS-1$
method.addBodyLine("this.value = value;");
//$NON-NLS-1$
method.addBodyLine("this.secondValue = secondValue;");
//$NON-NLS-1$
method.addBodyLine("this.typeHandler = typeHandler;");
//$NON-NLS-1$
method.addBodyLine("this.betweenValue = true;");
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"value"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"secondValue"));
//$NON-NLS-1$
method.addBodyLine("this(condition, value, secondValue, null);");
answer.addMethod(method);
return answer;
}
use of org.mybatis.generator.api.dom.java.InnerClass in project generator by mybatis.
the class CaseInsensitiveLikePlugin method modelExampleClassGenerated.
@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
InnerClass criteria = null;
// first, find the Criteria inner class
for (InnerClass innerClass : topLevelClass.getInnerClasses()) {
if ("GeneratedCriteria".equals(innerClass.getType().getShortName())) {
//$NON-NLS-1$
criteria = innerClass;
break;
}
}
if (criteria == null) {
// can't find the inner class for some reason, bail out.
return true;
}
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
if (!introspectedColumn.isJdbcCharacterColumn() || !introspectedColumn.isStringColumn()) {
continue;
}
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), //$NON-NLS-1$
"value"));
StringBuilder sb = new StringBuilder();
sb.append(introspectedColumn.getJavaProperty());
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
//$NON-NLS-1$
sb.insert(0, "and");
//$NON-NLS-1$
sb.append("LikeInsensitive");
method.setName(sb.toString());
method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
sb.setLength(0);
//$NON-NLS-1$
sb.append("addCriterion(\"upper(");
sb.append(Ibatis2FormattingUtilities.getAliasedActualColumnName(introspectedColumn));
//$NON-NLS-1$
sb.append(") like\", value.toUpperCase(), \"");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append("\");");
method.addBodyLine(sb.toString());
//$NON-NLS-1$
method.addBodyLine("return (Criteria) this;");
criteria.addMethod(method);
}
return true;
}
Aggregations