Package org.mybatis.generator.api.dom.xml

Examples of org.mybatis.generator.api.dom.xml.TextElement


        XmlConstants.IBATIS2_SQL_MAP_CONFIG_SYSTEM_ID);

    XmlElement root = new XmlElement("sqlMapConfig"); //$NON-NLS-1$
    document.setRootElement(root);

    root.addElement(new TextElement("<!--")); //$NON-NLS-1$
    root.addElement(new TextElement("  This file is generated by MyBatis Generator.")); //$NON-NLS-1$
    root.addElement(new TextElement(
        "  This file is the shell of an SqlMapConfig file - in many cases you will need to add")); //$NON-NLS-1$
    root.addElement(new TextElement("    to this file before it is usable by iBATIS.")); //$NON-NLS-1$

    StringBuilder sb = new StringBuilder();
    sb.append("  This file was generated on "); //$NON-NLS-1$
    sb.append(new Date());
    sb.append('.');
    root.addElement(new TextElement(sb.toString()));

    root.addElement(new TextElement("-->")); //$NON-NLS-1$

    XmlElement settings = new XmlElement("settings"); //$NON-NLS-1$
    settings.addAttribute(new Attribute("useStatementNamespaces", "true")); //$NON-NLS-1$ //$NON-NLS-2$
    root.addElement(settings);
View Full Code Here


    StringBuilder sb = new StringBuilder();

    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getNonPrimaryKeyColumns().iterator();
    while (iter.hasNext()) {
      IntrospectedColumn introspectedColumn = iter.next();

      sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
      sb.append(" = "); //$NON-NLS-1$
      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) {
        sb.append("  and "); //$NON-NLS-1$
      } else {
        sb.append("where "); //$NON-NLS-1$
        and = true;
      }

      sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
      sb.append(" = "); //$NON-NLS-1$
      sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
      answer.addElement(new TextElement(sb.toString()));
    }

    if (context.getPlugins().sqlMapUpdateByPrimaryKeyWithBLOBsElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
View Full Code Here

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("delete from "); //$NON-NLS-1$
    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));
    answer.addElement(getExampleIncludeElement());

    if (context.getPlugins().sqlMapDeleteByExampleElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
View Full Code Here

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("delete from "); //$NON-NLS-1$
    sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    boolean and = false;
    for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
      sb.setLength(0);
      if (and) {
        sb.append("  and "); //$NON-NLS-1$
      } else {
        sb.append("where "); //$NON-NLS-1$
        and = true;
      }

      sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
      sb.append(" = "); //$NON-NLS-1$
      sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
      answer.addElement(new TextElement(sb.toString()));
    }

    if (context.getPlugins().sqlMapDeleteByPrimaryKeyElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
View Full Code Here

    StringBuilder sb = new StringBuilder();

    sb.append("insert into "); //$NON-NLS-1$
    sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    XmlElement insertTrimElement = new XmlElement("trim"); //$NON-NLS-1$
    insertTrimElement.addAttribute(new Attribute("prefix", "(")); //$NON-NLS-1$ //$NON-NLS-2$
    insertTrimElement.addAttribute(new Attribute("suffix", ")")); //$NON-NLS-1$ //$NON-NLS-2$
    insertTrimElement.addAttribute(new Attribute("suffixOverrides", ",")); //$NON-NLS-1$ //$NON-NLS-2$
    answer.addElement(insertTrimElement);

    XmlElement valuesTrimElement = new XmlElement("trim"); //$NON-NLS-1$
    valuesTrimElement.addAttribute(new Attribute("prefix", "values (")); //$NON-NLS-1$ //$NON-NLS-2$
    valuesTrimElement.addAttribute(new Attribute("suffix", ")")); //$NON-NLS-1$ //$NON-NLS-2$
    valuesTrimElement.addAttribute(new Attribute("suffixOverrides", ",")); //$NON-NLS-1$ //$NON-NLS-2$
    answer.addElement(valuesTrimElement);

    for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
      if (introspectedColumn.isIdentity()) {
        // cannot set values on identity fields
        continue;
      }

      if (introspectedColumn.isSequenceColumn() || introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
        // if it is a sequence column, it is not optional
        // This is required for MyBatis3 because MyBatis3 parses
        // and calculates the SQL before executing the selectKey

        // if it is primitive, we cannot do a null check
        sb.setLength(0);
        sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
        sb.append(',');
        insertTrimElement.addElement(new TextElement(sb.toString()));

        sb.setLength(0);
        sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
        sb.append(',');
        valuesTrimElement.addElement(new TextElement(sb.toString()));

        continue;
      }

      XmlElement insertNotNullElement = new XmlElement("if"); //$NON-NLS-1$
      sb.setLength(0);
      sb.append(introspectedColumn.getJavaProperty());
      sb.append(" != null"); //$NON-NLS-1$
      insertNotNullElement.addAttribute(new Attribute("test", sb.toString())); //$NON-NLS-1$

      sb.setLength(0);
      sb.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
      sb.append(',');
      insertNotNullElement.addElement(new TextElement(sb.toString()));
      insertTrimElement.addElement(insertNotNullElement);

      XmlElement valuesNotNullElement = new XmlElement("if"); //$NON-NLS-1$
      sb.setLength(0);
      sb.append(introspectedColumn.getJavaProperty());
      sb.append(" != null"); //$NON-NLS-1$
      valuesNotNullElement.addAttribute(new Attribute("test", sb.toString())); //$NON-NLS-1$

      sb.setLength(0);
      sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn));
      sb.append(',');
      valuesNotNullElement.addElement(new TextElement(sb.toString()));
      valuesTrimElement.addElement(valuesNotNullElement);
    }

    if (context.getPlugins().sqlMapInsertSelectiveElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
View Full Code Here

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("select count(*) from "); //$NON-NLS-1$
    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));
    answer.addElement(getExampleIncludeElement());

    if (context.getPlugins().sqlMapCountByExampleElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
View Full Code Here

    StringBuilder sb = new StringBuilder();

    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getNonPrimaryKeyColumns().iterator();
    while (iter.hasNext()) {
      IntrospectedColumn introspectedColumn = iter.next();

      sb.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
      sb.append(" = "); //$NON-NLS-1$
      sb.append(Ibatis2FormattingUtilities.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) {
        sb.append("  and "); //$NON-NLS-1$
      } else {
        sb.append("where "); //$NON-NLS-1$
        and = true;
      }

      sb.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
      sb.append(" = "); //$NON-NLS-1$
      sb.append(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn));
      answer.addElement(new TextElement(sb.toString()));
    }

    if (context.getPlugins().sqlMapUpdateByPrimaryKeyWithBLOBsElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
View Full Code Here

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
      IntrospectedColumn introspectedColumn = iter.next();

      sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
      sb.append(" = "); //$NON-NLS-1$
      sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "record.")); //$NON-NLS-1$

      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);
View Full Code Here

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("delete from "); //$NON-NLS-1$
    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$
    sb.setLength(0);
    sb.append(introspectedTable.getIbatis2SqlMapNamespace());
    sb.append('.');
View Full Code Here

    XmlElement chooseElement = new XmlElement("choose"); //$NON-NLS-1$
    middleForEachElement.addElement(chooseElement);

    XmlElement when = new XmlElement("when"); //$NON-NLS-1$
    when.addAttribute(new Attribute("test", "criterion.noValue")); //$NON-NLS-1$ //$NON-NLS-2$
    when.addElement(new TextElement("and ${criterion.condition}")); //$NON-NLS-1$
    chooseElement.addElement(when);

    when = new XmlElement("when"); //$NON-NLS-1$
    when.addAttribute(new Attribute("test", "criterion.singleValue")); //$NON-NLS-1$ //$NON-NLS-2$
    sb.setLength(0);
    sb.append("and ${criterion.condition} #{criterion.value"); //$NON-NLS-1$
    if (typeHandled) {
      sb.append(typeHandlerString);
    }
    sb.append('}');
    when.addElement(new TextElement(sb.toString()));
    chooseElement.addElement(when);

    when = new XmlElement("when"); //$NON-NLS-1$
    when.addAttribute(new Attribute("test", "criterion.betweenValue")); //$NON-NLS-1$ //$NON-NLS-2$
    sb.setLength(0);
    sb.append("and ${criterion.condition} #{criterion.value"); //$NON-NLS-1$
    if (typeHandled) {
      sb.append(typeHandlerString);
    }
    sb.append("} and #{criterion.secondValue"); //$NON-NLS-1$
    if (typeHandled) {
      sb.append(typeHandlerString);
    }
    sb.append('}');
    when.addElement(new TextElement(sb.toString()));
    chooseElement.addElement(when);

    when = new XmlElement("when"); //$NON-NLS-1$
    when.addAttribute(new Attribute("test", "criterion.listValue")); //$NON-NLS-1$ //$NON-NLS-2$
    when.addElement(new TextElement("and ${criterion.condition}")); //$NON-NLS-1$
    XmlElement innerForEach = new XmlElement("foreach"); //$NON-NLS-1$
    innerForEach.addAttribute(new Attribute("collection", "criterion.value")); //$NON-NLS-1$ //$NON-NLS-2$
    innerForEach.addAttribute(new Attribute("item", "listItem")); //$NON-NLS-1$ //$NON-NLS-2$
    innerForEach.addAttribute(new Attribute("open", "(")); //$NON-NLS-1$ //$NON-NLS-2$
    innerForEach.addAttribute(new Attribute("close", ")")); //$NON-NLS-1$ //$NON-NLS-2$
    innerForEach.addAttribute(new Attribute("separator", ",")); //$NON-NLS-1$ //$NON-NLS-2$
    sb.setLength(0);
    sb.append("#{listItem"); //$NON-NLS-1$
    if (typeHandled) {
      sb.append(typeHandlerString);
    }
    sb.append('}');
    innerForEach.addElement(new TextElement(sb.toString()));
    when.addElement(innerForEach);
    chooseElement.addElement(when);

    return middleForEachElement;
  }
View Full Code Here

TOP

Related Classes of org.mybatis.generator.api.dom.xml.TextElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.