Search in sources :

Example 36 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 {
        // 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,");
    }
    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(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 37 with TextElement

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

the class SimpleSelectAllElementGenerator 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.getSelectAllStatementId()));
    answer.addAttribute(new //$NON-NLS-1$
    Attribute(//$NON-NLS-1$
    "resultMap", introspectedTable.getBaseResultMapId()));
    context.getCommentGenerator().addComment(answer);
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("select ");
    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()));
    String orderByClause = introspectedTable.getTableConfigurationProperty(PropertyRegistry.TABLE_SELECT_ALL_ORDER_BY_CLAUSE);
    boolean hasOrderBy = StringUtility.stringHasValue(orderByClause);
    if (hasOrderBy) {
        sb.setLength(0);
        //$NON-NLS-1$
        sb.append("order by ");
        sb.append(orderByClause);
        answer.addElement(new TextElement(sb.toString()));
    }
    if (context.getPlugins().sqlMapSelectAllElementGenerated(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 38 with TextElement

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

the class UpdateByExampleSelectiveElementGenerator 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.getUpdateByExampleSelectiveStatementId()));
    //$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()));
    //$NON-NLS-1$
    XmlElement dynamicElement = new XmlElement("set");
    answer.addElement(dynamicElement);
    for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getAllColumns())) {
        //$NON-NLS-1$
        XmlElement isNotNullElement = new XmlElement("if");
        sb.setLength(0);
        //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty("record."));
        //$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.getAliasedEscapedColumnName(introspectedColumn));
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, //$NON-NLS-1$
        "record."));
        sb.append(',');
        isNotNullElement.addElement(new TextElement(sb.toString()));
    }
    answer.addElement(getUpdateByExampleIncludeElement());
    if (context.getPlugins().sqlMapUpdateByExampleSelectiveElementGenerated(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 39 with TextElement

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

the class MapperConfigPlugin method contextGenerateAdditionalXmlFiles.

@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles() {
    Document document = new Document(XmlConstants.MYBATIS3_MAPPER_CONFIG_PUBLIC_ID, XmlConstants.MYBATIS3_MAPPER_CONFIG_SYSTEM_ID);
    //$NON-NLS-1$
    XmlElement root = new XmlElement("configuration");
    document.setRootElement(root);
    //$NON-NLS-1$
    root.addElement(new TextElement("<!--"));
    root.addElement(new TextElement(//$NON-NLS-1$
    "  This file is generated by MyBatis Generator."));
    root.addElement(new TextElement(//$NON-NLS-1$
    "  This file is the shell of a Mapper Config file - in many cases you will need to add"));
    root.addElement(new TextElement(//$NON-NLS-1$
    "    to this file before it is usable by MyBatis."));
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("  This file was generated on ");
    sb.append(new Date());
    sb.append('.');
    root.addElement(new TextElement(sb.toString()));
    //$NON-NLS-1$
    root.addElement(new TextElement("-->"));
    //$NON-NLS-1$
    XmlElement mappers = new XmlElement("mappers");
    root.addElement(mappers);
    XmlElement mapper;
    for (String mapperFile : mapperFiles) {
        //$NON-NLS-1$
        mapper = new XmlElement("mapper");
        //$NON-NLS-1$
        mapper.addAttribute(new Attribute("resource", mapperFile));
        mappers.addElement(mapper);
    }
    GeneratedXmlFile gxf = new GeneratedXmlFile(document, properties.getProperty("fileName", //$NON-NLS-1$ //$NON-NLS-2$
    "MapperConfig.xml"), //$NON-NLS-1$
    properties.getProperty("targetPackage"), //$NON-NLS-1$
    properties.getProperty("targetProject"), false, context.getXmlFormatter());
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>(1);
    answer.add(gxf);
    return answer;
}
Also used : TextElement(org.mybatis.generator.api.dom.xml.TextElement) Attribute(org.mybatis.generator.api.dom.xml.Attribute) ArrayList(java.util.ArrayList) 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) Date(java.util.Date) GeneratedXmlFile(org.mybatis.generator.api.GeneratedXmlFile)

Example 40 with TextElement

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

the class SqlMapConfigPlugin method contextGenerateAdditionalXmlFiles.

@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles() {
    Document document = new Document(XmlConstants.IBATIS2_SQL_MAP_CONFIG_PUBLIC_ID, XmlConstants.IBATIS2_SQL_MAP_CONFIG_SYSTEM_ID);
    //$NON-NLS-1$
    XmlElement root = new XmlElement("sqlMapConfig");
    document.setRootElement(root);
    //$NON-NLS-1$
    root.addElement(new TextElement("<!--"));
    root.addElement(new TextElement(//$NON-NLS-1$
    "  This file is generated by MyBatis Generator."));
    root.addElement(new TextElement(//$NON-NLS-1$
    "  This file is the shell of an SqlMapConfig file - in many cases you will need to add"));
    root.addElement(new TextElement(//$NON-NLS-1$
    "    to this file before it is usable by iBATIS."));
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("  This file was generated on ");
    sb.append(new Date());
    sb.append('.');
    root.addElement(new TextElement(sb.toString()));
    //$NON-NLS-1$
    root.addElement(new TextElement("-->"));
    //$NON-NLS-1$
    XmlElement settings = new XmlElement("settings");
    //$NON-NLS-1$ //$NON-NLS-2$
    settings.addAttribute(new Attribute("useStatementNamespaces", "true"));
    root.addElement(settings);
    XmlElement sqlMap;
    for (String sqlMapFile : sqlMapFiles) {
        //$NON-NLS-1$
        sqlMap = new XmlElement("sqlMap");
        //$NON-NLS-1$
        sqlMap.addAttribute(new Attribute("resource", sqlMapFile));
        root.addElement(sqlMap);
    }
    GeneratedXmlFile gxf = new GeneratedXmlFile(document, properties.getProperty("fileName", //$NON-NLS-1$ //$NON-NLS-2$
    "SqlMapConfig.xml"), //$NON-NLS-1$
    properties.getProperty("targetPackage"), //$NON-NLS-1$
    properties.getProperty("targetProject"), false, context.getXmlFormatter());
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>(1);
    answer.add(gxf);
    return answer;
}
Also used : TextElement(org.mybatis.generator.api.dom.xml.TextElement) Attribute(org.mybatis.generator.api.dom.xml.Attribute) ArrayList(java.util.ArrayList) 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) Date(java.util.Date) GeneratedXmlFile(org.mybatis.generator.api.GeneratedXmlFile)

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