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

The following examples show how to use org.mybatis.generator.api.IntrospectedTable#hasBLOBColumns() . 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: UpsertPlugin.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * SQL Map Methods 生成
 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
 * @param document
 * @param introspectedTable
 * @return
 */
@Override
public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) {
    this.generateXmlElementWithSelective(document, introspectedTable);
    this.generateXmlElement(document, introspectedTable, false);
    if (introspectedTable.hasBLOBColumns()) {
        this.generateXmlElement(document, introspectedTable, true);
    }

    if (this.allowBatchUpsert) {
        this.generateBatchXmlElementSelective(document, introspectedTable);
        this.generateBatchXmlElement(document, introspectedTable, false);
        if (introspectedTable.hasBLOBColumns()) {
            this.generateBatchXmlElement(document, introspectedTable, true);
        }
    }

    return super.sqlMapDocumentGenerated(document, introspectedTable);
}
 
Example 2
Source File: SelectSelectivePlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientSelectByExampleWithoutBLOBsMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
    if (!introspectedTable.hasBLOBColumns()) {
        FormatTools.addMethodWithBestPosition(interfaze, this.replaceMethodWithSelective(
                method,
                METHOD_SELECT_BY_EXAMPLE_SELECTIVE,
                "@Param(\"example\")",
                introspectedTable
        ));
    }
    return super.clientSelectByExampleWithoutBLOBsMethodGenerated(method, interfaze, introspectedTable);
}
 
Example 3
Source File: SelectSelectivePlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
    if (!introspectedTable.hasBLOBColumns()) {
        this.selectByExampleSelectiveEle = this.generateSelectSelectiveElement(METHOD_SELECT_BY_EXAMPLE_SELECTIVE, introspectedTable, false, true);
    }
    return super.sqlMapSelectByExampleWithBLOBsElementGenerated(element, introspectedTable);
}
 
Example 4
Source File: SelectSelectivePlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clientSelectOneByExampleWithoutBLOBsMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
    if (!introspectedTable.hasBLOBColumns()) {
        FormatTools.addMethodWithBestPosition(interfaze, this.replaceMethodWithSelective(
                method,
                METHOD_SELECT_ONE_BY_EXAMPLE_SELECTIVE,
                "@Param(\"example\")",
                introspectedTable
        ));
    }
    return true;
}
 
Example 5
Source File: SelectSelectivePlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapSelectOneByExampleWithoutBLOBsElementGenerated(Document document, XmlElement element, IntrospectedTable introspectedTable) {
    if (!introspectedTable.hasBLOBColumns()) {
        FormatTools.addElementWithBestPosition(document.getRootElement(), this.generateSelectOneByExampleSelectiveElement(introspectedTable));
    }
    return true;
}
 
Example 6
Source File: SelectSelectivePlugin.java    From mybatis-generator-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * 生成selectOneByExampleSelective
 * @param introspectedTable
 * @return
 */
private XmlElement generateSelectSelectiveElement(String id, IntrospectedTable introspectedTable, boolean selectOne, boolean byExample) {
    XmlElement selectSelectiveEle = new XmlElement("select");
    commentGenerator.addComment(selectSelectiveEle);

    selectSelectiveEle.addAttribute(new Attribute("id", id));
    // issues#16
    if (introspectedTable.isConstructorBased()) {
        selectSelectiveEle.addAttribute(new Attribute("resultMap", ID_FOR_PROPERTY_BASED_RESULT_MAP));
    } else if (introspectedTable.hasBLOBColumns()) {
        selectSelectiveEle.addAttribute(new Attribute("resultMap", introspectedTable.getResultMapWithBLOBsId()));
    } else {
        selectSelectiveEle.addAttribute(new Attribute("resultMap", introspectedTable.getBaseResultMapId()));
    }
    selectSelectiveEle.addAttribute(new Attribute("parameterType", "map"));

    if (byExample) {
        selectSelectiveEle.addElement(new TextElement("select"));

        if (!selectOne) {
            // issues#20
            XmlElement ifDistinctElement = new XmlElement("if");
            ifDistinctElement.addAttribute(new Attribute("test", "example != null and example.distinct"));
            ifDistinctElement.addElement(new TextElement("distinct"));
            selectSelectiveEle.addElement(ifDistinctElement);
        }

        //issue#102
        if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
            selectSelectiveEle.addElement(new TextElement("'" + introspectedTable.getSelectByExampleQueryId() + "' as QUERYID,"));
        }
    } else {
        selectSelectiveEle.addElement(new TextElement("select"));
        if (stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())) {
            selectSelectiveEle.addElement(new TextElement("'" + introspectedTable.getSelectByPrimaryKeyQueryId() + "' as QUERYID,"));
        }
    }

    selectSelectiveEle.addElement(this.generateSelectiveElement(introspectedTable));
    selectSelectiveEle.addElement(new TextElement("from " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));

    if (byExample) {
        XmlElement ifElement = new XmlElement("if");
        ifElement.addAttribute(new Attribute("test", "example != null"));

        XmlElement includeElement = new XmlElement("include");
        includeElement.addAttribute(new Attribute("refid", introspectedTable.getMyBatis3UpdateByExampleWhereClauseId()));
        ifElement.addElement(includeElement);

        selectSelectiveEle.addElement(ifElement);

        XmlElement ifElement1 = new XmlElement("if");
        ifElement1.addAttribute(new Attribute("test", "example != null and example.orderByClause != null"));
        ifElement1.addElement(new TextElement("order by ${example.orderByClause}"));
        selectSelectiveEle.addElement(ifElement1);
    } else {
        boolean and = false;
        StringBuffer sb = new StringBuffer();
        for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
            sb.setLength(0);
            if (and) {
                sb.append("  and ");
            } else {
                sb.append("where ");
                and = true;
            }

            sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
            sb.append(" = ");
            sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, introspectedTable.getRules().generatePrimaryKeyClass() ? "record." : null));
            selectSelectiveEle.addElement(new TextElement(sb.toString()));
        }
    }

    if (selectOne) {
        // 只查询一条
        selectSelectiveEle.addElement(new TextElement("limit 1"));
    }

    return selectSelectiveEle;
}
 
Example 7
Source File: IntrospectedTableTools.java    From mybatis-generator-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * 是否有 blob 列
 * @param introspectedTable
 * @return
 */
public static boolean includeBLOBColumns(IntrospectedTable introspectedTable) {
    return !introspectedTable.getRules().generateRecordWithBLOBsClass()
            && introspectedTable.hasBLOBColumns();
}