Search in sources :

Example 46 with XmlElement

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

the class SelectByPrimaryKeyElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("select");
    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
    introspectedTable.getSelectByPrimaryKeyStatementId()));
    if (introspectedTable.getRules().generateResultMapWithBLOBs()) {
        answer.addAttribute(new //$NON-NLS-1$
        Attribute(//$NON-NLS-1$
        "resultMap", introspectedTable.getResultMapWithBLOBsId()));
    } else {
        answer.addAttribute(new //$NON-NLS-1$
        Attribute(//$NON-NLS-1$
        "resultMap", introspectedTable.getBaseResultMapId()));
    }
    String parameterType;
    if (introspectedTable.getRules().generatePrimaryKeyClass()) {
        parameterType = introspectedTable.getPrimaryKeyType();
    } else {
        // select by primary key, but no primary key class. Fields
        // must be in the base record
        parameterType = introspectedTable.getBaseRecordType();
    }
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "parameterClass", parameterType));
    context.getCommentGenerator().addComment(answer);
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("select ");
    if (stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())) {
        sb.append('\'');
        sb.append(introspectedTable.getSelectByPrimaryKeyQueryId());
        //$NON-NLS-1$
        sb.append("' as QUERYID,");
    }
    answer.addElement(new TextElement(sb.toString()));
    answer.addElement(getBaseColumnListElement());
    if (introspectedTable.hasBLOBColumns()) {
        //$NON-NLS-1$
        answer.addElement(new TextElement(","));
        answer.addElement(getBlobColumnListElement());
    }
    sb.setLength(0);
    //$NON-NLS-1$
    sb.append("from ");
    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
    answer.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(Ibatis2FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn));
        answer.addElement(new TextElement(sb.toString()));
    }
    if (context.getPlugins().sqlMapSelectByPrimaryKeyElementGenerated(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 47 with XmlElement

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

the class AbstractXmlElementGenerator method getBlobColumnListElement.

protected XmlElement getBlobColumnListElement() {
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("include");
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "refid", introspectedTable.getIbatis2SqlMapNamespace() + "." + //$NON-NLS-1$
    introspectedTable.getBlobColumnListId()));
    return answer;
}
Also used : XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 48 with XmlElement

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

the class BlobColumnListElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("sql");
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "id", introspectedTable.getBlobColumnListId()));
    context.getCommentGenerator().addComment(answer);
    StringBuilder sb = new StringBuilder();
    Iterator<IntrospectedColumn> iter = introspectedTable.getBLOBColumns().iterator();
    while (iter.hasNext()) {
        sb.append(Ibatis2FormattingUtilities.getSelectListPhrase(iter.next()));
        if (iter.hasNext()) {
            //$NON-NLS-1$
            sb.append(", ");
        }
        if (sb.length() > 80) {
            answer.addElement(new TextElement(sb.toString()));
            sb.setLength(0);
        }
    }
    if (sb.length() > 0) {
        answer.addElement(new TextElement(sb.toString()));
    }
    if (context.getPlugins().sqlMapBlobColumnListElementGenerated(answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) TextElement(org.mybatis.generator.api.dom.xml.TextElement) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 49 with XmlElement

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

the class CountByExampleElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("select");
    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
    introspectedTable.getCountByExampleStatementId()));
    answer.addAttribute(new Attribute("parameterClass", //$NON-NLS-1$
    introspectedTable.getExampleType()));
    //$NON-NLS-1$ //$NON-NLS-2$
    answer.addAttribute(new Attribute("resultClass", "java.lang.Long"));
    context.getCommentGenerator().addComment(answer);
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("select count(*) from ");
    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));
    //$NON-NLS-1$
    XmlElement includeElement = new XmlElement("include");
    sb.setLength(0);
    sb.append(introspectedTable.getIbatis2SqlMapNamespace());
    sb.append('.');
    sb.append(introspectedTable.getExampleWhereClauseId());
    includeElement.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "refid", sb.toString()));
    answer.addElement(includeElement);
    if (context.getPlugins().sqlMapCountByExampleElementGenerated(answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
Also used : 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 50 with XmlElement

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

the class DeleteByPrimaryKeyElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("delete");
    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
    introspectedTable.getDeleteByPrimaryKeyStatementId()));
    String parameterClass;
    if (introspectedTable.getRules().generatePrimaryKeyClass()) {
        parameterClass = introspectedTable.getPrimaryKeyType();
    } else {
        parameterClass = introspectedTable.getBaseRecordType();
    }
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "parameterClass", parameterClass));
    context.getCommentGenerator().addComment(answer);
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("delete from ");
    sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
    answer.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(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn));
        answer.addElement(new TextElement(sb.toString()));
    }
    if (context.getPlugins().sqlMapDeleteByPrimaryKeyElementGenerated(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)

Aggregations

XmlElement (org.mybatis.generator.api.dom.xml.XmlElement)88 Attribute (org.mybatis.generator.api.dom.xml.Attribute)74 TextElement (org.mybatis.generator.api.dom.xml.TextElement)44 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