Java Code Examples for org.mybatis.generator.api.IntrospectedTable#getNonBLOBColumns()

The following examples show how to use org.mybatis.generator.api.IntrospectedTable#getNonBLOBColumns() . 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: ExampleEnhancedPlugin.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 添加列操作方法
 * @param topLevelClass
 * @param innerClass
 * @param introspectedTable
 */
private void addColumnMethodToCriteria(TopLevelClass topLevelClass, InnerClass innerClass, IntrospectedTable introspectedTable) {
    // !!!!! Column import比较特殊引入的是外部类
    topLevelClass.addImportedType(introspectedTable.getRules().calculateAllFieldsClass());
    for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
        topLevelClass.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
        // EqualTo
        FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "EqualTo", "="));
        // NotEqualTo
        FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "NotEqualTo", "<>"));
        // GreaterThan
        FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "GreaterThan", ">"));
        // GreaterThanOrEqualTo
        FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "GreaterThanOrEqualTo", ">="));
        // LessThan
        FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "LessThan", "<"));
        // LessThanOrEqualTo
        FormatTools.addMethodWithBestPosition(innerClass, this.generateSingleValueMethod(introspectedTable, introspectedColumn, "LessThanOrEqualTo", "<="));
    }
}
 
Example 2
Source File: IntrospectedTableTools.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 获取生成model baseRecord的列
 * @param introspectedTable
 * @return
 */
public static List<IntrospectedColumn> getModelBaseRecordClomns(IntrospectedTable introspectedTable) {
    List<IntrospectedColumn> introspectedColumns;
    if (includePrimaryKeyColumns(introspectedTable)) {
        if (includeBLOBColumns(introspectedTable)) {
            introspectedColumns = introspectedTable.getAllColumns();
        } else {
            introspectedColumns = introspectedTable.getNonBLOBColumns();
        }
    } else {
        if (includeBLOBColumns(introspectedTable)) {
            introspectedColumns = introspectedTable
                    .getNonPrimaryKeyColumns();
        } else {
            introspectedColumns = introspectedTable.getBaseColumns();
        }
    }

    return introspectedColumns;
}
 
Example 3
Source File: EqualsHashCodePlugin.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    List<IntrospectedColumn> columns;
    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
        columns = introspectedTable.getNonBLOBColumns();
    } else {
        columns = introspectedTable.getAllColumns();
    }

    generateEquals(topLevelClass, columns, introspectedTable);
    generateHashCode(topLevelClass, columns, introspectedTable);

    return true;
}
 
Example 4
Source File: ModelBuilderPlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Model Methods 生成
 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
@Override
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    // 判断是否有生成Model的WithBLOBs类
    List<IntrospectedColumn> columns = introspectedTable.getRules().generateRecordWithBLOBsClass() ? introspectedTable.getNonBLOBColumns() : introspectedTable.getAllColumns();
    InnerClass innerClass = this.generateModelBuilder(topLevelClass, introspectedTable, columns);
    topLevelClass.addInnerClass(innerClass);
    return super.modelBaseRecordClassGenerated(topLevelClass, introspectedTable);
}
 
Example 5
Source File: ModelBuilderPlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean modelBaseRecordBuilderClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    // 判断是否有生成Model的WithBLOBs类
    List<IntrospectedColumn> columns = introspectedTable.getRules().generateRecordWithBLOBsClass() ? introspectedTable.getNonBLOBColumns() : introspectedTable.getAllColumns();
    InnerClass innerClass = this.generateModelBuilder(topLevelClass, introspectedTable, columns);
    topLevelClass.addInnerClass(innerClass);
    return true;
}
 
Example 6
Source File: EqualsHashCodePlugin.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    List<IntrospectedColumn> columns;
    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
        columns = introspectedTable.getNonBLOBColumns();
    } else {
        columns = introspectedTable.getAllColumns();
    }

    generateEquals(topLevelClass, columns, introspectedTable);
    generateHashCode(topLevelClass, columns, introspectedTable);

    return true;
}
 
Example 7
Source File: EqualsHashCodePlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    List<IntrospectedColumn> columns;
    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
        columns = introspectedTable.getNonBLOBColumns();
    } else {
        columns = introspectedTable.getAllColumns();
    }

    generateEquals(topLevelClass, columns, introspectedTable);
    generateHashCode(topLevelClass, columns, introspectedTable);

    return true;
}
 
Example 8
Source File: CaseInsensitiveLikePlugin.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
@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(), "value")); //$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$
        sb.append("LikeInsensitive"); //$NON-NLS-1$
        method.setName(sb.toString());
        method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());

        sb.setLength(0);
        sb.append("addCriterion(\"upper("); //$NON-NLS-1$
        sb.append(Ibatis2FormattingUtilities
                .getAliasedActualColumnName(introspectedColumn));
        sb.append(") like\", value.toUpperCase(), \""); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.append("\");"); //$NON-NLS-1$
        method.addBodyLine(sb.toString());
        method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

        criteria.addMethod(method);
    }

    return true;
}
 
Example 9
Source File: CaseInsensitiveLikePlugin.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@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(), "value")); //$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$
        sb.append("LikeInsensitive"); //$NON-NLS-1$
        method.setName(sb.toString());
        method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());

        sb.setLength(0);
        sb.append("addCriterion(\"upper("); //$NON-NLS-1$
        sb.append(Ibatis2FormattingUtilities
                .getAliasedActualColumnName(introspectedColumn));
        sb.append(") like\", value.toUpperCase(), \""); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.append("\");"); //$NON-NLS-1$
        method.addBodyLine(sb.toString());
        method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

        criteria.addMethod(method);
    }

    return true;
}
 
Example 10
Source File: AliasExampleWhereClauseGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void addElements(XmlElement parentElement,IntrospectedTable introspectedTable) {
	XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$

	if (isForUpdateByExample) {
		answer.addAttribute(new Attribute(
				"id", ALIAS_UPDATE_BY_EXAMPLE_WHERE_CLAUSE_ID)); //$NON-NLS-1$
	} else {
		answer.addAttribute(new Attribute(
				"id", ALIAS_EXAMPLE_WHERE_CLAUSE_ID)); //$NON-NLS-1$
	}

	introspectedTable.getContext().getCommentGenerator().addComment(answer);

	XmlElement whereElement = new XmlElement("where"); //$NON-NLS-1$
	answer.addElement(whereElement);

	XmlElement outerForEachElement = new XmlElement("foreach"); //$NON-NLS-1$
	if (isForUpdateByExample) {
		outerForEachElement.addAttribute(new Attribute(
				"collection", "example.oredCriteria")); //$NON-NLS-1$ //$NON-NLS-2$
	} else {
		outerForEachElement.addAttribute(new Attribute(
				"collection", "oredCriteria")); //$NON-NLS-1$ //$NON-NLS-2$
	}
	outerForEachElement.addAttribute(new Attribute("item", "criteria")); //$NON-NLS-1$ //$NON-NLS-2$
	outerForEachElement.addAttribute(new Attribute("separator", "or")); //$NON-NLS-1$ //$NON-NLS-2$
	whereElement.addElement(outerForEachElement);

	XmlElement ifElement = new XmlElement("if"); //$NON-NLS-1$
	ifElement.addAttribute(new Attribute("test", "criteria.valid")); //$NON-NLS-1$ //$NON-NLS-2$
	outerForEachElement.addElement(ifElement);

	XmlElement trimElement = new XmlElement("trim"); //$NON-NLS-1$
	trimElement.addAttribute(new Attribute("prefix", "(")); //$NON-NLS-1$ //$NON-NLS-2$
	trimElement.addAttribute(new Attribute("suffix", ")")); //$NON-NLS-1$ //$NON-NLS-2$
	trimElement.addAttribute(new Attribute("prefixOverrides", "and")); //$NON-NLS-1$ //$NON-NLS-2$

	ifElement.addElement(trimElement);

	trimElement.addElement(getMiddleForEachElement(null,introspectedTable));

	for (IntrospectedColumn introspectedColumn : introspectedTable
			.getNonBLOBColumns()) {
		if (stringHasValue(introspectedColumn.getTypeHandler())) {
			trimElement
					.addElement(getMiddleForEachElement(introspectedColumn,introspectedTable));
		}
	}

	parentElement.addElement(answer);
}