Search in sources :

Example 51 with Attribute

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

the class UpdateByPrimaryKeySelectiveElementGenerator 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.getUpdateByPrimaryKeySelectiveStatementId()));
    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()));
    //$NON-NLS-1$
    XmlElement dynamicElement = new XmlElement("set");
    answer.addElement(dynamicElement);
    for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonPrimaryKeyColumns())) {
        //$NON-NLS-1$
        XmlElement isNotNullElement = new XmlElement("if");
        sb.setLength(0);
        sb.append(introspectedColumn.getJavaProperty());
        //$NON-NLS-1$
        sb.append(" != null");
        //$NON-NLS-1$
        isNotNullElement.addAttribute(new Attribute("test", sb.toString()));
        dynamicElement.addElement(isNotNullElement);
        sb.setLength(0);
        sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
        sb.append(',');
        isNotNullElement.addElement(new TextElement(sb.toString()));
    }
    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().sqlMapUpdateByPrimaryKeySelectiveElementGenerated(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 52 with Attribute

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

the class UpdateByPrimaryKeyWithoutBLOBsElementGenerator 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.getUpdateByPrimaryKeyStatementId()));
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "parameterType", introspectedTable.getBaseRecordType()));
    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;
    if (isSimple) {
        iter = ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonPrimaryKeyColumns()).iterator();
    } else {
        iter = ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getBaseColumns()).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().sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(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 53 with Attribute

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

the class CommentGeneratorConfiguration method toXmlElement.

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

Example 54 with Attribute

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

the class Configuration method toDocument.

/**
     * Builds an XML representation of this configuration. This can be used to
     * persist a programmatically generated configuration.
     * 
     * @return the XML representation of this configuration
     */
public Document toDocument() {
    // note that this method will not reconstruct a properties
    // element - that element is only used in XML parsing
    Document document = new Document(XmlConstants.MYBATIS_GENERATOR_CONFIG_PUBLIC_ID, XmlConstants.MYBATIS_GENERATOR_CONFIG_SYSTEM_ID);
    //$NON-NLS-1$
    XmlElement rootElement = new XmlElement("generatorConfiguration");
    document.setRootElement(rootElement);
    for (String classPathEntry : classPathEntries) {
        //$NON-NLS-1$
        XmlElement cpeElement = new XmlElement("classPathEntry");
        //$NON-NLS-1$
        cpeElement.addAttribute(new Attribute("location", classPathEntry));
        rootElement.addElement(cpeElement);
    }
    for (Context context : contexts) {
        rootElement.addElement(context.toXmlElement());
    }
    return document;
}
Also used : Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) Document(org.mybatis.generator.api.dom.xml.Document)

Example 55 with Attribute

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

the class JavaClientGeneratorConfiguration method toXmlElement.

public XmlElement toXmlElement() {
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("javaClientGenerator");
    if (getConfigurationType() != null) {
        //$NON-NLS-1$
        answer.addAttribute(new Attribute("type", getConfigurationType()));
    }
    if (targetPackage != null) {
        //$NON-NLS-1$
        answer.addAttribute(new Attribute("targetPackage", targetPackage));
    }
    if (targetProject != null) {
        //$NON-NLS-1$
        answer.addAttribute(new Attribute("targetProject", targetProject));
    }
    if (implementationPackage != null) {
        answer.addAttribute(new Attribute("implementationPackage", //$NON-NLS-1$
        targetProject));
    }
    addPropertyXmlElements(answer);
    return answer;
}
Also used : Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Aggregations

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