Search in sources :

Example 21 with TextElement

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

the class SelectByExampleWithBLOBsElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    String fqjt = introspectedTable.getExampleType();
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("select");
    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
    introspectedTable.getSelectByExampleWithBLOBsStatementId()));
    answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
    introspectedTable.getResultMapWithBLOBsId()));
    //$NON-NLS-1$
    answer.addAttribute(new Attribute("parameterType", fqjt));
    context.getCommentGenerator().addComment(answer);
    //$NON-NLS-1$
    answer.addElement(new TextElement("select"));
    //$NON-NLS-1$
    XmlElement ifElement = new XmlElement("if");
    //$NON-NLS-1$ //$NON-NLS-2$
    ifElement.addAttribute(new Attribute("test", "distinct"));
    //$NON-NLS-1$
    ifElement.addElement(new TextElement("distinct"));
    answer.addElement(ifElement);
    StringBuilder sb = new StringBuilder();
    if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
        sb.append('\'');
        sb.append(introspectedTable.getSelectByExampleQueryId());
        //$NON-NLS-1$
        sb.append("' as QUERYID,");
        answer.addElement(new TextElement(sb.toString()));
    }
    answer.addElement(getBaseColumnListElement());
    //$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()));
    answer.addElement(getExampleIncludeElement());
    //$NON-NLS-1$
    ifElement = new XmlElement("if");
    //$NON-NLS-1$ //$NON-NLS-2$
    ifElement.addAttribute(new Attribute("test", "orderByClause != null"));
    //$NON-NLS-1$
    ifElement.addElement(new TextElement("order by ${orderByClause}"));
    answer.addElement(ifElement);
    if (context.getPlugins().sqlMapSelectByExampleWithBLOBsElementGenerated(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 22 with TextElement

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

the class SelectByExampleWithoutBLOBsElementGenerator method addElements.

@Override
public void addElements(XmlElement parentElement) {
    String fqjt = introspectedTable.getExampleType();
    //$NON-NLS-1$
    XmlElement answer = new XmlElement("select");
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "id", introspectedTable.getSelectByExampleStatementId()));
    answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
    introspectedTable.getBaseResultMapId()));
    //$NON-NLS-1$
    answer.addAttribute(new Attribute("parameterType", fqjt));
    context.getCommentGenerator().addComment(answer);
    //$NON-NLS-1$
    answer.addElement(new TextElement("select"));
    //$NON-NLS-1$
    XmlElement ifElement = new XmlElement("if");
    //$NON-NLS-1$ //$NON-NLS-2$
    ifElement.addAttribute(new Attribute("test", "distinct"));
    //$NON-NLS-1$
    ifElement.addElement(new TextElement("distinct"));
    answer.addElement(ifElement);
    StringBuilder sb = new StringBuilder();
    if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
        sb.append('\'');
        sb.append(introspectedTable.getSelectByExampleQueryId());
        //$NON-NLS-1$
        sb.append("' as QUERYID,");
        answer.addElement(new TextElement(sb.toString()));
    }
    answer.addElement(getBaseColumnListElement());
    sb.setLength(0);
    //$NON-NLS-1$
    sb.append("from ");
    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));
    answer.addElement(getExampleIncludeElement());
    //$NON-NLS-1$
    ifElement = new XmlElement("if");
    //$NON-NLS-1$ //$NON-NLS-2$
    ifElement.addAttribute(new Attribute("test", "orderByClause != null"));
    //$NON-NLS-1$
    ifElement.addElement(new TextElement("order by ${orderByClause}"));
    answer.addElement(ifElement);
    if (context.getPlugins().sqlMapSelectByExampleWithoutBLOBsElementGenerated(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 23 with TextElement

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

the class SimpleSelectByPrimaryKeyElementGenerator 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()));
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "resultMap", introspectedTable.getBaseResultMapId()));
    String parameterType;
    // field, then they are coming in a map.
    if (introspectedTable.getPrimaryKeyColumns().size() > 1) {
        //$NON-NLS-1$
        parameterType = "map";
    } else {
        parameterType = introspectedTable.getPrimaryKeyColumns().get(0).getFullyQualifiedJavaType().toString();
    }
    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("select ");
    if (stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())) {
        sb.append('\'');
        sb.append(introspectedTable.getSelectByPrimaryKeyQueryId());
        //$NON-NLS-1$
        sb.append("' as QUERYID,");
    }
    Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns().iterator();
    while (iter.hasNext()) {
        sb.append(MyBatis3FormattingUtilities.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()));
    }
    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(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.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 24 with TextElement

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

the class UpdateByExampleWithBLOBsElementGenerator 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.getUpdateByExampleWithBLOBsStatementId()));
    //$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.getAllColumns()).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().sqlMapUpdateByExampleWithBLOBsElementGenerated(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 25 with TextElement

use of org.mybatis.generator.api.dom.xml.TextElement 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)

Aggregations

TextElement (org.mybatis.generator.api.dom.xml.TextElement)45 XmlElement (org.mybatis.generator.api.dom.xml.XmlElement)44 Attribute (org.mybatis.generator.api.dom.xml.Attribute)40 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)27 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)5 ArrayList (java.util.ArrayList)4 GeneratedKey (org.mybatis.generator.config.GeneratedKey)4 Date (java.util.Date)2 GeneratedXmlFile (org.mybatis.generator.api.GeneratedXmlFile)2 Document (org.mybatis.generator.api.dom.xml.Document)2 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)2