Search in sources :

Example 16 with Attribute

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

the class ResultMapWithoutBLOBsElementGenerator method addResultMapElements.

private void addResultMapElements(XmlElement answer) {
    for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
        //$NON-NLS-1$
        XmlElement resultElement = new XmlElement("id");
        resultElement.addAttribute(new Attribute("column", //$NON-NLS-1$
        MyBatis3FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn)));
        resultElement.addAttribute(new Attribute("property", //$NON-NLS-1$
        introspectedColumn.getJavaProperty()));
        resultElement.addAttribute(new //$NON-NLS-1$
        Attribute(//$NON-NLS-1$
        "jdbcType", introspectedColumn.getJdbcTypeName()));
        if (stringHasValue(introspectedColumn.getTypeHandler())) {
            resultElement.addAttribute(new Attribute("typeHandler", //$NON-NLS-1$
            introspectedColumn.getTypeHandler()));
        }
        answer.addElement(resultElement);
    }
    List<IntrospectedColumn> columns;
    if (isSimple) {
        columns = introspectedTable.getNonPrimaryKeyColumns();
    } else {
        columns = introspectedTable.getBaseColumns();
    }
    for (IntrospectedColumn introspectedColumn : columns) {
        //$NON-NLS-1$
        XmlElement resultElement = new XmlElement("result");
        resultElement.addAttribute(new Attribute("column", //$NON-NLS-1$
        MyBatis3FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn)));
        resultElement.addAttribute(new Attribute("property", //$NON-NLS-1$
        introspectedColumn.getJavaProperty()));
        resultElement.addAttribute(new //$NON-NLS-1$
        Attribute(//$NON-NLS-1$
        "jdbcType", introspectedColumn.getJdbcTypeName()));
        if (stringHasValue(introspectedColumn.getTypeHandler())) {
            resultElement.addAttribute(new Attribute("typeHandler", //$NON-NLS-1$
            introspectedColumn.getTypeHandler()));
        }
        answer.addElement(resultElement);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 17 with Attribute

use of org.mybatis.generator.api.dom.xml.Attribute 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 18 with Attribute

use of org.mybatis.generator.api.dom.xml.Attribute 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 19 with Attribute

use of org.mybatis.generator.api.dom.xml.Attribute 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 20 with Attribute

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

Aggregations

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