Search in sources :

Example 26 with XmlElement

use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.

the class UpdateByExampleWithoutBLOBsElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("update");
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "id", introspectedTable.getUpdateByExampleStatementId()));
    //$NON-NLS-1$ //$NON-NLS-2$
    answer.addAttribute(new Attribute("parameterType", "map"));
    context.getCommentGenerator().addComment(answer);
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("update ");
    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));
    // set up for first column
    sb.setLength(0);
    //$NON-NLS-1$
    sb.append("set ");
    Iterator<IntrospectedColumn> iter = ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonBLOBColumns()).iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();
        sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, //$NON-NLS-1$
        "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);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) TextElement(org.mybatis.generator.api.dom.xml.TextElement) Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 27 with XmlElement

use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.

the class UpdateByPrimaryKeyWithBLOBsElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("update");
    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
    introspectedTable.getUpdateByPrimaryKeyWithBLOBsStatementId()));
    String parameterType;
    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
        parameterType = introspectedTable.getRecordWithBLOBsType();
    } else {
        parameterType = introspectedTable.getBaseRecordType();
    }
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "parameterType", parameterType));
    context.getCommentGenerator().addComment(answer);
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("update ");
    sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));
    // set up for first column
    sb.setLength(0);
    //$NON-NLS-1$
    sb.append("set ");
    Iterator<IntrospectedColumn> iter = ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonPrimaryKeyColumns()).iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();
        sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
        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);
        }
    }
    boolean and = false;
    for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
        sb.setLength(0);
        if (and) {
            //$NON-NLS-1$
            sb.append("  and ");
        } else {
            //$NON-NLS-1$
            sb.append("where ");
            and = true;
        }
        sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
        answer.addElement(new TextElement(sb.toString()));
    }
    if (context.getPlugins().sqlMapUpdateByPrimaryKeyWithBLOBsElementGenerated(answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) TextElement(org.mybatis.generator.api.dom.xml.TextElement) Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 28 with XmlElement

use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.

the class ColumnOverride method toXmlElement.

/**
     * To xml element.
     *
     * @return the xml element
     */
public XmlElement toXmlElement() {
    //$NON-NLS-1$
    XmlElement xmlElement = new XmlElement("columnOverride");
    //$NON-NLS-1$
    xmlElement.addAttribute(new Attribute("column", columnName));
    if (stringHasValue(javaProperty)) {
        //$NON-NLS-1$
        xmlElement.addAttribute(new Attribute("property", javaProperty));
    }
    if (stringHasValue(javaType)) {
        //$NON-NLS-1$
        xmlElement.addAttribute(new Attribute("javaType", javaType));
    }
    if (stringHasValue(jdbcType)) {
        //$NON-NLS-1$
        xmlElement.addAttribute(new Attribute("jdbcType", jdbcType));
    }
    if (stringHasValue(typeHandler)) {
        //$NON-NLS-1$
        xmlElement.addAttribute(new Attribute("typeHandler", typeHandler));
    }
    if (stringHasValue(configuredDelimitedColumnName)) {
        xmlElement.addAttribute(new Attribute("delimitedColumnName", //$NON-NLS-1$
        configuredDelimitedColumnName));
    }
    addPropertyXmlElements(xmlElement);
    return xmlElement;
}
Also used : Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 29 with XmlElement

use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.

the class ColumnRenamingRule method toXmlElement.

public XmlElement toXmlElement() {
    //$NON-NLS-1$
    XmlElement xmlElement = new XmlElement("columnRenamingRule");
    //$NON-NLS-1$
    xmlElement.addAttribute(new Attribute("searchString", searchString));
    if (replaceString != null) {
        xmlElement.addAttribute(new Attribute("replaceString", //$NON-NLS-1$
        replaceString));
    }
    return xmlElement;
}
Also used : Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 30 with XmlElement

use of org.mybatis.generator.api.dom.xml.XmlElement in project generator by mybatis.

the class ConnectionFactoryConfiguration method toXmlElement.

public XmlElement toXmlElement() {
    //$NON-NLS-1$
    XmlElement xmlElement = new XmlElement("connectionFactory");
    if (stringHasValue(getConfigurationType())) {
        //$NON-NLS-1$
        xmlElement.addAttribute(new Attribute("type", getConfigurationType()));
    }
    addPropertyXmlElements(xmlElement);
    return xmlElement;
}
Also used : Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Aggregations

XmlElement (org.mybatis.generator.api.dom.xml.XmlElement)87 Attribute (org.mybatis.generator.api.dom.xml.Attribute)73 TextElement (org.mybatis.generator.api.dom.xml.TextElement)43 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)34 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)5 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)5 ArrayList (java.util.ArrayList)4 Document (org.mybatis.generator.api.dom.xml.Document)4 GeneratedKey (org.mybatis.generator.config.GeneratedKey)4 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)3 Date (java.util.Date)2 GeneratedXmlFile (org.mybatis.generator.api.GeneratedXmlFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1