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

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


    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(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
      sb.append(" = "); //$NON-NLS-1$
      sb.append(Ibatis2FormattingUtilities.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 insertElement = new XmlElement("dynamic"); //$NON-NLS-1$
    insertElement.addAttribute(new Attribute("prepend", "(")); //$NON-NLS-1$ //$NON-NLS-2$
    answer.addElement(insertElement);

    answer.addElement(new TextElement("values")); //$NON-NLS-1$

    XmlElement valuesElement = new XmlElement("dynamic"); //$NON-NLS-1$
    valuesElement.addAttribute(new Attribute("prepend", "(")); //$NON-NLS-1$ //$NON-NLS-2$
    answer.addElement(valuesElement);

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

      XmlElement insertNotNullElement = new XmlElement("isNotNull"); //$NON-NLS-1$
      insertNotNullElement.addAttribute(new Attribute("prepend", ",")); //$NON-NLS-1$ //$NON-NLS-2$
      insertNotNullElement.addAttribute(new Attribute("property", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
      insertNotNullElement.addElement(new TextElement(Ibatis2FormattingUtilities
          .getEscapedColumnName(introspectedColumn)));
      insertElement.addElement(insertNotNullElement);

      XmlElement valuesNotNullElement = new XmlElement("isNotNull"); //$NON-NLS-1$
      valuesNotNullElement.addAttribute(new Attribute("prepend", ",")); //$NON-NLS-1$ //$NON-NLS-2$
      valuesNotNullElement.addAttribute(new Attribute("property", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
      valuesNotNullElement.addElement(new TextElement(Ibatis2FormattingUtilities
          .getParameterClause(introspectedColumn)));
      valuesElement.addElement(valuesNotNullElement);
    }

    insertElement.addElement(new TextElement(")")); //$NON-NLS-1$
    valuesElement.addElement(new TextElement(")")); //$NON-NLS-1$

    if (gk != null && !gk.isPlacedBeforeInsertInIbatis2()) {
      IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
      // if the column is null, then it's a configuration error. The
      // warning has already been reported
View Full Code Here

        insertClause.append(", "); //$NON-NLS-1$
        valuesClause.append(", "); //$NON-NLS-1$
      }

      if (valuesClause.length() > 80) {
        answer.addElement(new TextElement(insertClause.toString()));
        insertClause.setLength(0);
        OutputUtilities.xmlIndent(insertClause, 1);

        valuesClauses.add(valuesClause.toString());
        valuesClause.setLength(0);
        OutputUtilities.xmlIndent(valuesClause, 1);
      }
    }

    insertClause.append(')');
    answer.addElement(new TextElement(insertClause.toString()));

    valuesClause.append(')');
    valuesClauses.add(valuesClause.toString());

    for (String clause : valuesClauses) {
      answer.addElement(new TextElement(clause));
    }

    if (context.getPlugins().sqlMapInsertElementGenerated(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()));

    XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$
    sb.setLength(0);
    sb.append(introspectedTable.getIbatis2SqlMapNamespace());
    sb.append('.');
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(Ibatis2FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
      sb.append(" = "); //$NON-NLS-1$
      sb.append(Ibatis2FormattingUtilities.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("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.getAllColumns().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

    XmlElement isEqualElement = new XmlElement("isEqual"); //$NON-NLS-1$
    isEqualElement.addAttribute(new Attribute("property", "oredCriteria[].valid")); //$NON-NLS-1$ //$NON-NLS-2$
    isEqualElement.addAttribute(new Attribute("compareValue", "true")); //$NON-NLS-1$ //$NON-NLS-2$
    outerIterateElement.addElement(isEqualElement);

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

    XmlElement innerIterateElement = new XmlElement("iterate"); //$NON-NLS-1$
    innerIterateElement.addAttribute(new Attribute("prepend", "and")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addAttribute(new Attribute("property", "oredCriteria[].criteriaWithoutValue")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addAttribute(new Attribute("conjunction", "and")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addElement(new TextElement("$oredCriteria[].criteriaWithoutValue[]$")); //$NON-NLS-1$
    isEqualElement.addElement(innerIterateElement);

    innerIterateElement = new XmlElement("iterate"); //$NON-NLS-1$
    innerIterateElement.addAttribute(new Attribute("prepend", "and")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addAttribute(new Attribute("property", "oredCriteria[].criteriaWithSingleValue")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addAttribute(new Attribute("conjunction", "and")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement
        .addElement(new TextElement(
            "$oredCriteria[].criteriaWithSingleValue[].condition$ #oredCriteria[].criteriaWithSingleValue[].value#")); //$NON-NLS-1$
    isEqualElement.addElement(innerIterateElement);

    innerIterateElement = new XmlElement("iterate"); //$NON-NLS-1$
    innerIterateElement.addAttribute(new Attribute("prepend", "and")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addAttribute(new Attribute("property", "oredCriteria[].criteriaWithListValue")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addAttribute(new Attribute("conjunction", "and")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addElement(new TextElement("$oredCriteria[].criteriaWithListValue[].condition$")); //$NON-NLS-1$
    XmlElement innerInnerIterateElement = new XmlElement("iterate"); //$NON-NLS-1$
    innerInnerIterateElement.addAttribute(new Attribute("property", //$NON-NLS-1$
        "oredCriteria[].criteriaWithListValue[].values")); //$NON-NLS-1$
    innerInnerIterateElement.addAttribute(new Attribute("open", "(")); //$NON-NLS-1$ //$NON-NLS-2$
    innerInnerIterateElement.addAttribute(new Attribute("close", ")")); //$NON-NLS-1$ //$NON-NLS-2$
    innerInnerIterateElement.addAttribute(new Attribute("conjunction", ",")); //$NON-NLS-1$ //$NON-NLS-2$
    innerInnerIterateElement.addElement(new TextElement("#oredCriteria[].criteriaWithListValue[].values[]#")); //$NON-NLS-1$
    innerIterateElement.addElement(innerInnerIterateElement);
    isEqualElement.addElement(innerIterateElement);

    innerIterateElement = new XmlElement("iterate"); //$NON-NLS-1$
    innerIterateElement.addAttribute(new Attribute("prepend", "and")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addAttribute(new Attribute("property", "oredCriteria[].criteriaWithBetweenValue")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addAttribute(new Attribute("conjunction", "and")); //$NON-NLS-1$ //$NON-NLS-2$
    innerIterateElement.addElement(new TextElement("$oredCriteria[].criteriaWithBetweenValue[].condition$")); //$NON-NLS-1$
    innerIterateElement.addElement(new TextElement("#oredCriteria[].criteriaWithBetweenValue[].values[0]# and")); //$NON-NLS-1$
    innerIterateElement.addElement(new TextElement("#oredCriteria[].criteriaWithBetweenValue[].values[1]#")); //$NON-NLS-1$
    isEqualElement.addElement(innerIterateElement);

    // if any of the columns have a user defined type handler, then we need
    // to add additional inner iterate elements that specify the type
    // handler
    for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
      if (stringHasValue(introspectedColumn.getTypeHandler())) {
        // name the property based on the column name, then
        // add the type handler to the parameter declaration
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        innerIterateElement = new XmlElement("iterate"); //$NON-NLS-1$
        innerIterateElement.addAttribute(new Attribute("prepend", "and")); //$NON-NLS-1$ //$NON-NLS-2$

        sb1.append("oredCriteria[]."); //$NON-NLS-1$
        sb1.append(introspectedColumn.getJavaProperty());
        sb1.append("CriteriaWithSingleValue"); //$NON-NLS-1$

        innerIterateElement.addAttribute(new Attribute("property", sb1.toString())); //$NON-NLS-1$
        innerIterateElement.addAttribute(new Attribute("conjunction", "and")); //$NON-NLS-1$ //$NON-NLS-2$

        sb2.append(sb1);

        sb1.insert(0, '$');
        sb1.append("[].condition$ ");//$NON-NLS-1$

        sb2.insert(0, '#');
        sb2.append("[].value,handler=");//$NON-NLS-1$
        sb2.append(introspectedColumn.getTypeHandler());
        sb2.append('#');

        sb1.append(sb2);

        innerIterateElement.addElement(new TextElement(sb1.toString()));
        isEqualElement.addElement(innerIterateElement);

        sb1.setLength(0);
        sb2.setLength(0);
        sb1.append("oredCriteria[]."); //$NON-NLS-1$
        sb1.append(introspectedColumn.getJavaProperty());
        sb1.append("CriteriaWithListValue"); //$NON-NLS-1$

        innerIterateElement = new XmlElement("iterate"); //$NON-NLS-1$
        innerIterateElement.addAttribute(new Attribute("prepend", "and")); //$NON-NLS-1$ //$NON-NLS-2$
        innerIterateElement.addAttribute(new Attribute("property", sb1.toString())); //$NON-NLS-1$
        innerIterateElement.addAttribute(new Attribute("conjunction", "and")); //$NON-NLS-1$ //$NON-NLS-2$

        sb2.append('$');
        sb2.append(sb1);
        sb2.append("[].condition$"); //$NON-NLS-1$

        innerIterateElement.addElement(new TextElement(sb2.toString()));

        sb2.setLength(0);
        sb2.append(sb1);
        sb2.append("[].values"); //$NON-NLS-1$

        innerInnerIterateElement = new XmlElement("iterate"); //$NON-NLS-1$
        innerInnerIterateElement.addAttribute(new Attribute("property", //$NON-NLS-1$
            sb2.toString()));
        innerInnerIterateElement.addAttribute(new Attribute("open", "(")); //$NON-NLS-1$ //$NON-NLS-2$
        innerInnerIterateElement.addAttribute(new Attribute("close", ")")); //$NON-NLS-1$ //$NON-NLS-2$
        innerInnerIterateElement.addAttribute(new Attribute("conjunction", ",")); //$NON-NLS-1$ //$NON-NLS-2$

        sb2.setLength(0);
        sb2.append('#');
        sb2.append(sb1);
        sb2.append("[].values[],handler="); //$NON-NLS-1$
        sb2.append(introspectedColumn.getTypeHandler());
        sb2.append('#');

        innerInnerIterateElement.addElement(new TextElement(sb2.toString()));
        innerIterateElement.addElement(innerInnerIterateElement);
        isEqualElement.addElement(innerIterateElement);

        sb1.setLength(0);
        sb2.setLength(0);
        sb1.append("oredCriteria[]."); //$NON-NLS-1$
        sb1.append(introspectedColumn.getJavaProperty());
        sb1.append("CriteriaWithBetweenValue"); //$NON-NLS-1$

        innerIterateElement = new XmlElement("iterate"); //$NON-NLS-1$
        innerIterateElement.addAttribute(new Attribute("prepend", "and")); //$NON-NLS-1$ //$NON-NLS-2$
        innerIterateElement.addAttribute(new Attribute("property", sb1.toString())); //$NON-NLS-1$
        innerIterateElement.addAttribute(new Attribute("conjunction", "and")); //$NON-NLS-1$ //$NON-NLS-2$

        sb2.append('$');
        sb2.append(sb1);
        sb2.append("[].condition$"); //$NON-NLS-1$

        innerIterateElement.addElement(new TextElement(sb2.toString()));

        sb2.setLength(0);
        sb2.append(sb1);

        sb1.insert(0, '#');
        sb1.append("[].values[0],handler="); //$NON-NLS-1$
        sb1.append(introspectedColumn.getTypeHandler());
        sb1.append("# and"); //$NON-NLS-1$

        sb2.insert(0, '#');
        sb2.append("[].values[1],handler="); //$NON-NLS-1$
        sb2.append(introspectedColumn.getTypeHandler());
        sb2.append('#');

        innerIterateElement.addElement(new TextElement(sb1.toString()));
        innerIterateElement.addElement(new TextElement(sb2.toString()));
        isEqualElement.addElement(innerIterateElement);
      }
    }

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

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

    answer.addAttribute(new Attribute("resultMap", introspectedTable.getResultMapWithBLOBsId())); //$NON-NLS-1$
    answer.addAttribute(new Attribute("parameterType", fqjt)); //$NON-NLS-1$

    context.getCommentGenerator().addComment(answer);

    answer.addElement(new TextElement("select")); //$NON-NLS-1$
    XmlElement ifElement = new XmlElement("if"); //$NON-NLS-1$
    ifElement.addAttribute(new Attribute("test", "distinct")); //$NON-NLS-1$ //$NON-NLS-2$
    ifElement.addElement(new TextElement("distinct")); //$NON-NLS-1$
    answer.addElement(ifElement);

    StringBuilder sb = new StringBuilder();
    if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
      sb.append('\'');
      sb.append(introspectedTable.getSelectByExampleQueryId());
      sb.append("' as QUERYID,"); //$NON-NLS-1$
      answer.addElement(new TextElement(sb.toString()));
    }

    answer.addElement(getBaseColumnListElement());
    answer.addElement(new TextElement(",")); //$NON-NLS-1$
    answer.addElement(getBlobColumnListElement());

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

    ifElement = new XmlElement("if"); //$NON-NLS-1$
    ifElement.addAttribute(new Attribute("test", "orderByClause != null")); //$NON-NLS-1$ //$NON-NLS-2$
    ifElement.addElement(new TextElement("order by ${orderByClause}")); //$NON-NLS-1$
    answer.addElement(ifElement);

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

        insertClause.append(", "); //$NON-NLS-1$
        valuesClause.append(", "); //$NON-NLS-1$
      }

      if (valuesClause.length() > 80) {
        answer.addElement(new TextElement(insertClause.toString()));
        insertClause.setLength(0);
        OutputUtilities.xmlIndent(insertClause, 1);

        valuesClauses.add(valuesClause.toString());
        valuesClause.setLength(0);
        OutputUtilities.xmlIndent(valuesClause, 1);
      }
    }

    insertClause.append(')');
    answer.addElement(new TextElement(insertClause.toString()));

    valuesClause.append(')');
    valuesClauses.add(valuesClause.toString());

    for (String clause : valuesClauses) {
      answer.addElement(new TextElement(clause));
    }

    if (gk != null && !gk.isPlacedBeforeInsertInIbatis2()) {
      IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
      // if the column is null, then it's a configuration error. The
View Full Code Here

      if (iter.hasNext()) {
        sb.append(", "); //$NON-NLS-1$
      }

      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().sqlMapBaseColumnListElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
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.