Java Code Examples for org.mybatis.generator.api.IntrospectedColumn#getFullyQualifiedJavaType()

The following examples show how to use org.mybatis.generator.api.IntrospectedColumn#getFullyQualifiedJavaType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaBeansUtil.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
private static Method getBasicJavaBeansGetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method(getGetterMethodName(property, fqjt));
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(fqjt);

    StringBuilder sb = new StringBuilder();
    sb.append("return ");
    sb.append(property);
    sb.append(';');
    method.addBodyLine(sb.toString());

    return method;
}
 
Example 2
Source File: AbstractJavaGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public Method getJavaBeansGetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(fqjt);
    method.setName(getGetterMethodName(property, fqjt));
    context.getCommentGenerator().addGetterComment(method,
            introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    sb.append("return "); //$NON-NLS-1$
    sb.append(property);
    sb.append(';');
    method.addBodyLine(sb.toString());

    return method;
}
 
Example 3
Source File: JavaBeansUtil.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the java beans field.
 *
 * @param introspectedColumn
 *            the introspected column
 * @param context
 *            the context
 * @param introspectedTable
 *            the introspected table
 * @return the java beans field
 */
public static Field getJavaBeansField(IntrospectedColumn introspectedColumn,
        Context context,
        IntrospectedTable introspectedTable) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(fqjt);
    field.setName(property);
    context.getCommentGenerator().addFieldComment(field,
            introspectedTable, introspectedColumn);

    return field;
}
 
Example 4
Source File: TableColumnBuilder.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 创建 ColumnField
 *
 * @param column
 * @return
 */
public static ColumnField build(IntrospectedColumn column) {
    ColumnField field = new ColumnField();
    field.setColumnName(column.getActualColumnName());
    field.setJdbcType(column.getJdbcTypeName());
    field.setFieldName(column.getJavaProperty());
    field.setRemarks(column.getRemarks());
    FullyQualifiedJavaType type = column.getFullyQualifiedJavaType();
    field.setType(type);
    field.setTypePackage(type.getPackageName());
    field.setShortTypeName(type.getShortName());
    field.setFullTypeName(type.getFullyQualifiedName());
    field.setIdentity(column.isIdentity());
    field.setNullable(column.isNullable());
    field.setSequenceColumn(column.isSequenceColumn());
    field.setBlobColumn(column.isBLOBColumn());
    field.setStringColumn(column.isStringColumn());
    field.setJdbcCharacterColumn(column.isJdbcCharacterColumn());
    field.setJdbcDateColumn(column.isJDBCDateColumn());
    field.setJdbcTimeColumn(column.isJDBCTimeColumn());
    field.setLength(column.getLength());
    field.setScale(column.getScale());
    return field;
}
 
Example 5
Source File: JavaBeansUtil.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private static Field getBasicJavaBeansField(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Field field = new Field(property, fqjt);
    field.setVisibility(JavaVisibility.PRIVATE);

    return field;
}
 
Example 6
Source File: AbstractJavaMapperMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
protected void addGeneratedKeyAnnotation(Interface interfaze, Method method,
        GeneratedKey gk) {
    StringBuilder sb = new StringBuilder();
    IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
    if (introspectedColumn != null) {
        if (gk.isJdbcStandard()) {
            interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Options")); //$NON-NLS-1$
            sb.append("@Options(useGeneratedKeys=true,keyProperty=\""); //$NON-NLS-1$
            sb.append(introspectedColumn.getJavaProperty());
            sb.append("\")"); //$NON-NLS-1$
            method.addAnnotation(sb.toString());
        } else {
            interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.SelectKey")); //$NON-NLS-1$
            FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
            interfaze.addImportedType(fqjt);
            sb.append("@SelectKey(statement=\""); //$NON-NLS-1$
            sb.append(gk.getRuntimeSqlStatement());
            sb.append("\", keyProperty=\""); //$NON-NLS-1$
            sb.append(introspectedColumn.getJavaProperty());
            sb.append("\", before="); //$NON-NLS-1$
            sb.append(gk.isIdentity() ? "false" : "true"); //$NON-NLS-1$ //$NON-NLS-2$
            sb.append(", resultType="); //$NON-NLS-1$
            sb.append(fqjt.getShortName());
            sb.append(".class)"); //$NON-NLS-1$
            method.addAnnotation(sb.toString());
        }
    }
}
 
Example 7
Source File: AbstractJavaGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public Method getJavaBeansSetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getSetterMethodName(property));
    method.addParameter(new Parameter(fqjt, property));
    context.getCommentGenerator().addSetterComment(method,
            introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    if (isTrimStringsEnabled() && introspectedColumn.isStringColumn()) {
        sb.append("this."); //$NON-NLS-1$
        sb.append(property);
        sb.append(" = "); //$NON-NLS-1$
        sb.append(property);
        sb.append(" == null ? null : "); //$NON-NLS-1$
        sb.append(property);
        sb.append(".trim();"); //$NON-NLS-1$
        method.addBodyLine(sb.toString());
    } else {
        sb.append("this."); //$NON-NLS-1$
        sb.append(property);
        sb.append(" = "); //$NON-NLS-1$
        sb.append(property);
        sb.append(';');
        method.addBodyLine(sb.toString());
    }

    return method;
}
 
Example 8
Source File: AbstractJavaGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public Field getJavaBeansField(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(fqjt);
    field.setName(property);
    field.setComments(introspectedColumn.getRemarks());
    context.getCommentGenerator().addFieldComment(field,
            introspectedTable, introspectedColumn);

    return field;
}
 
Example 9
Source File: InsertSelectiveMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable
                .getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getDAOMethodNameCalculator()
            .getInsertSelectiveMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 10
Source File: TemplateFilePlugin.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * 列转换为字段
 *
 * @param introspectedColumn
 * @return
 */
public static Field convertToJavaBeansField(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();
    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(fqjt);
    field.setName(property);
    return field;
}
 
Example 11
Source File: InsertSelectiveMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable
                .getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getDAOMethodNameCalculator()
            .getInsertSelectiveMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 12
Source File: DynamicSqlSupportClassGenerator.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
private FullyQualifiedJavaType calculateFieldType(IntrospectedColumn column) {
	FullyQualifiedJavaType typeParameter;
	if (column.getFullyQualifiedJavaType().isPrimitive()) {
		typeParameter = column.getFullyQualifiedJavaType().getPrimitiveTypeWrapper();
	} else {
		typeParameter = column.getFullyQualifiedJavaType();
	}
	return new FullyQualifiedJavaType(String.format("SqlColumn<%s>", typeParameter.getShortName())); //$NON-NLS-1$
}
 
Example 13
Source File: DynamicSqlSupportClassGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private FullyQualifiedJavaType calculateFieldType(IntrospectedColumn column) {
    FullyQualifiedJavaType typeParameter;
    if (column.getFullyQualifiedJavaType().isPrimitive()) {
        typeParameter = column.getFullyQualifiedJavaType().getPrimitiveTypeWrapper();
    } else {
        typeParameter = column.getFullyQualifiedJavaType();
    }
    return new FullyQualifiedJavaType(String.format("SqlColumn<%s>", typeParameter.getShortName()));
}
 
Example 14
Source File: JavaBeansUtil.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private static Method getBasicJavaBeansSetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn
            .getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method(getSetterMethodName(property));
    method.setVisibility(JavaVisibility.PUBLIC);
    method.addParameter(new Parameter(fqjt, property));

    StringBuilder sb = new StringBuilder();
    if (introspectedColumn.isStringColumn() && isTrimStringsEnabled(introspectedColumn)) {
        sb.append("this.");
        sb.append(property);
        sb.append(" = ");
        sb.append(property);
        sb.append(" == null ? null : ");
        sb.append(property);
        sb.append(".trim();");
        method.addBodyLine(sb.toString());
    } else {
        sb.append("this.");
        sb.append(property);
        sb.append(" = ");
        sb.append(property);
        sb.append(';');
        method.addBodyLine(sb.toString());
    }

    return method;
}
 
Example 15
Source File: ExampleGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
/**
 * Generates methods that set between and not between conditions
 * 
 * @param introspectedColumn
 * @param betweenMethod
 * @return a generated method for the between or not between method
 */
private Method getSetBetweenOrNotBetweenMethod(
        IntrospectedColumn introspectedColumn, boolean betweenMethod) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = introspectedColumn
            .getFullyQualifiedJavaType();

    method.addParameter(new Parameter(type, "value1")); //$NON-NLS-1$
    method.addParameter(new Parameter(type, "value2")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    if (betweenMethod) {
        sb.append("Between"); //$NON-NLS-1$
    } else {
        sb.append("NotBetween"); //$NON-NLS-1$
    }
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(Ibatis2FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (betweenMethod) {
        sb.append(" between"); //$NON-NLS-1$
    } else {
        sb.append(" not between"); //$NON-NLS-1$
    }
    sb.append("\", "); //$NON-NLS-1$
    if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedTable.isJava5Targeted()) {
        sb.append("new "); //$NON-NLS-1$
        sb.append(introspectedColumn.getFullyQualifiedJavaType()
                .getPrimitiveTypeWrapper().getShortName());
        sb.append("(value1), "); //$NON-NLS-1$
        sb.append("new "); //$NON-NLS-1$
        sb.append(introspectedColumn.getFullyQualifiedJavaType()
                .getPrimitiveTypeWrapper().getShortName());
        sb.append("(value2)"); //$NON-NLS-1$
    } else {
        sb.append("value1, value2"); //$NON-NLS-1$
    }

    sb.append(", \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 16
Source File: InsertMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable
                .getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }

    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    DAOMethodNameCalculator methodNameCalculator = getDAOMethodNameCalculator();
    method.setName(methodNameCalculator
            .getInsertMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 17
Source File: InsertMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable
                .getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }

    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    DAOMethodNameCalculator methodNameCalculator = getDAOMethodNameCalculator();
    method.setName(methodNameCalculator
            .getInsertMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 18
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
/**
 * Generates methods that set between and not between conditions
 * 
 * @param introspectedColumn
 * @param betweenMethod
 * @return a generated method for the between or not between method
 */
private Method getSetBetweenOrNotBetweenMethod(
        IntrospectedColumn introspectedColumn, boolean betweenMethod) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = introspectedColumn
            .getFullyQualifiedJavaType();

    method.addParameter(new Parameter(type, "value1")); //$NON-NLS-1$
    method.addParameter(new Parameter(type, "value2")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    if (betweenMethod) {
        sb.append("Between"); //$NON-NLS-1$
    } else {
        sb.append("NotBetween"); //$NON-NLS-1$
    }
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (betweenMethod) {
        sb.append(" between"); //$NON-NLS-1$
    } else {
        sb.append(" not between"); //$NON-NLS-1$
    }
    sb.append("\", "); //$NON-NLS-1$
    sb.append("value1, value2"); //$NON-NLS-1$
    sb.append(", \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 19
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
/**
 * Generates methods that set between and not between conditions
 * 
 * @param introspectedColumn
 * @param betweenMethod
 * @return a generated method for the between or not between method
 */
private Method getSetBetweenOrNotBetweenMethod(
        IntrospectedColumn introspectedColumn, boolean betweenMethod) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = introspectedColumn
            .getFullyQualifiedJavaType();

    method.addParameter(new Parameter(type, "value1")); //$NON-NLS-1$
    method.addParameter(new Parameter(type, "value2")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    if (betweenMethod) {
        sb.append("Between"); //$NON-NLS-1$
    } else {
        sb.append("NotBetween"); //$NON-NLS-1$
    }
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(Ibatis2FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (betweenMethod) {
        sb.append(" between"); //$NON-NLS-1$
    } else {
        sb.append(" not between"); //$NON-NLS-1$
    }
    sb.append("\", "); //$NON-NLS-1$
    if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedTable.isJava5Targeted()) {
        sb.append("new "); //$NON-NLS-1$
        sb.append(introspectedColumn.getFullyQualifiedJavaType()
                .getPrimitiveTypeWrapper().getShortName());
        sb.append("(value1), "); //$NON-NLS-1$
        sb.append("new "); //$NON-NLS-1$
        sb.append(introspectedColumn.getFullyQualifiedJavaType()
                .getPrimitiveTypeWrapper().getShortName());
        sb.append("(value2)"); //$NON-NLS-1$
    } else {
        sb.append("value1, value2"); //$NON-NLS-1$
    }

    sb.append(", \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 20
Source File: ExampleGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
/**
 * Generates methods that set between and not between conditions.
 *
 * @param introspectedColumn the introspected column
 * @param betweenMethod true if between, else not between
 * @return a generated method for the between or not between method
 */
private Method getSetBetweenOrNotBetweenMethod(
        IntrospectedColumn introspectedColumn, boolean betweenMethod) {

    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and");
    if (betweenMethod) {
        sb.append("Between");
    } else {
        sb.append("NotBetween");
    }
    Method method = new Method(sb.toString());
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();

    method.addParameter(new Parameter(type, "value1"));
    method.addParameter(new Parameter(type, "value2"));
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());

    sb.setLength(0);
    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\"");
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\"");
    } else if (stringHasValue(introspectedColumn.getTypeHandler())) {
        sb.append("add");
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\"");
    } else {
        sb.append("addCriterion(\"");
    }

    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (betweenMethod) {
        sb.append(" between");
    } else {
        sb.append(" not between");
    }
    sb.append("\", ");
    sb.append("value1, value2");
    sb.append(", \"");
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");");
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;");

    return method;
}