Search in sources :

Example 6 with InnerClass

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;
}
Also used : Field(org.mybatis.generator.api.dom.java.Field) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) InnerClass(org.mybatis.generator.api.dom.java.InnerClass) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 7 with InnerClass

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;
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) InnerClass(org.mybatis.generator.api.dom.java.InnerClass) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Aggregations

InnerClass (org.mybatis.generator.api.dom.java.InnerClass)7 Method (org.mybatis.generator.api.dom.java.Method)7 Parameter (org.mybatis.generator.api.dom.java.Parameter)5 Field (org.mybatis.generator.api.dom.java.Field)4 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)4 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)3 ArrayList (java.util.ArrayList)2 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)2