Java Code Examples for org.mybatis.generator.api.dom.OutputUtilities#xmlIndent()

The following examples show how to use org.mybatis.generator.api.dom.OutputUtilities#xmlIndent() . 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: MybatisGeneratorPlugin.java    From java-master with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) {
    Element element = new Element() {
        @Override
        public String getFormattedContent(int indentLevel) {
            StringBuilder sb = new StringBuilder();
            OutputUtilities.xmlIndent(sb, indentLevel);
            sb.append("<!-- 此文件由 mybatis generator 生成,注意: 请勿手工改动此文件, 请使用 mybatis generator -->");
            return sb.toString();
        }
    };
    document.getRootElement().addElement(0, element);
    return super.sqlMapDocumentGenerated(document, introspectedTable);
}
 
Example 2
Source File: TextElement.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();
    OutputUtilities.xmlIndent(sb, indentLevel);
    sb.append(content);
    return sb.toString();
}
 
Example 3
Source File: XmlElement.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();

    OutputUtilities.xmlIndent(sb, indentLevel);
    sb.append('<');
    sb.append(name);

    Collections.sort(attributes);
    for (Attribute att : attributes) {
        sb.append(' ');
        sb.append(att.getFormattedContent());
    }

    if (elements.size() > 0) {
        sb.append(">"); //$NON-NLS-1$
        for (Element element : elements) {
            OutputUtilities.newLine(sb);
            sb.append(element.getFormattedContent(indentLevel + 1));
        }
        OutputUtilities.newLine(sb);
        OutputUtilities.xmlIndent(sb, indentLevel);
        sb.append("</"); //$NON-NLS-1$
        sb.append(name);
        sb.append('>');

    } else {
        sb.append(" />"); //$NON-NLS-1$
    }

    return sb.toString();
}
 
Example 4
Source File: TextElement.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();
    OutputUtilities.xmlIndent(sb, indentLevel);
    sb.append(content);
    return sb.toString();
}
 
Example 5
Source File: XmlElement.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();

    OutputUtilities.xmlIndent(sb, indentLevel);
    sb.append('<');
    sb.append(name);

    for (Attribute att : attributes) {
        sb.append(' ');
        sb.append(att.getFormattedContent());
    }

    if (elements.size() > 0) {
        sb.append(" >"); //$NON-NLS-1$
        for (Element element : elements) {
            OutputUtilities.newLine(sb);
            sb.append(element.getFormattedContent(indentLevel + 1));
        }
        OutputUtilities.newLine(sb);
        OutputUtilities.xmlIndent(sb, indentLevel);
        sb.append("</"); //$NON-NLS-1$
        sb.append(name);
        sb.append('>');

    } else {
        sb.append(" />"); //$NON-NLS-1$
    }

    return sb.toString();
}
 
Example 6
Source File: InsertBatchElementGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("insert");

    answer.addAttribute(new Attribute(
            "id", introspectedTable.getInsertBatchStatementId()));

    answer.addAttribute(new Attribute("parameterType",
            FullyQualifiedJavaType.getNewListInstance().getFullyQualifiedName()));

    context.getCommentGenerator().addComment(answer);

    this.generateKey(introspectedTable, answer);

    answer.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
    answer.addElement(new TextElement(" ("));

    StringBuilder insertClause = new StringBuilder();
    StringBuilder valuesClause = new StringBuilder();
    List<String> valuesClauses = new ArrayList<String>();
    List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns());
    for (int i = 0; i < columns.size(); i++) {
        IntrospectedColumn introspectedColumn = columns.get(i);

        insertClause.setLength(0);
        valuesClause.setLength(0);
        insertClause.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
        valuesClause.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item."));
        if (i + 1 < columns.size()) {
            insertClause.append(", ");
            valuesClause.append(", ");
        }

        answer.addElement(new TextElement(insertClause.toString()));
        OutputUtilities.xmlIndent(insertClause, 1);
        valuesClauses.add(valuesClause.toString());
        OutputUtilities.xmlIndent(valuesClause, 3);
    }

    answer.addElement(new TextElement(")"));
    OutputUtilities.xmlIndent(valuesClause, 1);
    answer.addElement(new TextElement("values"));
    OutputUtilities.xmlIndent(valuesClause, 1);
    answer.addElement(new TextElement("<foreach collection=\"list\" item=\"item\" separator=\",\">"));
    answer.addElement(new TextElement("("));

    for (String clause : valuesClauses) {
        answer.addElement(new TextElement(clause));
    }

    answer.addElement(new TextElement(")"));
    answer.addElement(new TextElement("</foreach>"));

    if (context.getPlugins().sqlMapInsertElementGenerated(answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 7
Source File: UpdateByExampleWithBLOBsElementGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update");

    answer.addAttribute(new Attribute("id",
            introspectedTable.getUpdateByExampleWithBLOBsStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-2$
    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update ");
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set ");

    Iterator<IntrospectedColumn> iter =
            ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getAllColumns()).iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();
        
        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record."));

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 8
Source File: UpdateByExampleWithoutBLOBsElementGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update");

    answer.addAttribute(new Attribute("id",
            introspectedTable.getUpdateByExampleStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-2$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update ");
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set ");

    Iterator<IntrospectedColumn> iter =
            ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonBLOBColumns()).iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record."));

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 9
Source File: UpdateByExampleWithBLOBsElementGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer
            .addAttribute(new Attribute(
                    "id", introspectedTable.getUpdateByExampleWithBLOBsStatementId())); //$NON-NLS-1$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns()
            .iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(Ibatis2FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(Ibatis2FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

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

    XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$
    includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$
            introspectedTable.getIbatis2SqlMapNamespace()
                    + "." + introspectedTable.getExampleWhereClauseId())); //$NON-NLS-1$
    isParameterPresentElement.addElement(includeElement);

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 10
Source File: UpdateByExampleWithoutBLOBsElementGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute(
            "id", introspectedTable.getUpdateByExampleStatementId())); //$NON-NLS-1$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable
            .getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(Ibatis2FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(Ibatis2FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

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

    XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$
    includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$
            introspectedTable.getIbatis2SqlMapNamespace()
                    + "." + introspectedTable.getExampleWhereClauseId())); //$NON-NLS-1$
    isParameterPresentElement.addElement(includeElement);

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 11
Source File: UpdateByExampleWithBLOBsElementGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
            introspectedTable.getUpdateByExampleWithBLOBsStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$
    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns()
            .iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 12
Source File: UpdateByExampleWithoutBLOBsElementGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
            introspectedTable.getUpdateByExampleStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable
            .getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 13
Source File: UpdateByExampleWithBLOBsElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer
            .addAttribute(new Attribute(
                    "id", introspectedTable.getUpdateByExampleWithBLOBsStatementId())); //$NON-NLS-1$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns()
            .iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(Ibatis2FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(Ibatis2FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

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

    XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$
    includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$
            introspectedTable.getIbatis2SqlMapNamespace()
                    + "." + introspectedTable.getExampleWhereClauseId())); //$NON-NLS-1$
    isParameterPresentElement.addElement(includeElement);

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 14
Source File: UpdateByExampleWithoutBLOBsElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute(
            "id", introspectedTable.getUpdateByExampleStatementId())); //$NON-NLS-1$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable
            .getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(Ibatis2FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(Ibatis2FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

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

    XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$
    includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$
            introspectedTable.getIbatis2SqlMapNamespace()
                    + "." + introspectedTable.getExampleWhereClauseId())); //$NON-NLS-1$
    isParameterPresentElement.addElement(includeElement);

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 15
Source File: UpdateByExampleWithBLOBsElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
            introspectedTable.getUpdateByExampleWithBLOBsStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$
    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns()
            .iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example 16
Source File: UpdateByExampleWithoutBLOBsElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
            introspectedTable.getUpdateByExampleStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable
            .getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}