Ejemplo n.º 1
0
  public XmlElement toXmlElement() {
    XmlElement xmlElement = new XmlElement("ignoreColumn"); // $NON-NLS-1$
    xmlElement.addAttribute(new Attribute("column", columnName)); // $NON-NLS-1$

    if (StringUtility.stringHasValue(configuredDelimitedColumnName)) {
      xmlElement.addAttribute(
          new Attribute("delimitedColumnName", configuredDelimitedColumnName)); // $NON-NLS-1$
    }

    return xmlElement;
  }
  public XmlElement toXmlElement() {
    XmlElement answer = new XmlElement("sqlMapGenerator"); // $NON-NLS-1$

    if (targetPackage != null) {
      answer.addAttribute(new Attribute("targetPackage", targetPackage)); // $NON-NLS-1$
    }

    if (targetProject != null) {
      answer.addAttribute(new Attribute("targetProject", targetProject)); // $NON-NLS-1$
    }

    addPropertyXmlElements(answer);

    return answer;
  }
  /**
   * Adds a suitable comment to warn users that the element was generated, and when it was
   * generated.
   */
  public void addComment(XmlElement xmlElement) {
    xmlElement.addElement(new TextElement("<!--")); // $NON-NLS-1$
    xmlElement.addElement(
        new TextElement(
            "  WARNING - This element is automatically generated by Apache iBATIS ibator, do not modify.")); //$NON-NLS-1$

    String s = getDateString();
    if (s != null) {
      StringBuilder sb = new StringBuilder();
      sb.append("  This element was generated on "); // $NON-NLS-1$
      sb.append(s);
      sb.append('.');
      xmlElement.addElement(new TextElement(sb.toString()));
    }

    xmlElement.addElement(new TextElement("-->")); // $NON-NLS-1$
  }
  @Override
  public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); // $NON-NLS-1$

    answer.addAttribute(
        new Attribute(
            "id", introspectedTable.getUpdateByPrimaryKeyWithBLOBsStatementId())); // $NON-NLS-1$

    String parameterType;

    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
      parameterType = introspectedTable.getRecordWithBLOBsType();
    } else {
      parameterType = introspectedTable.getBaseRecordType();
    }

    answer.addAttribute(
        new Attribute(
            "parameterClass", //$NON-NLS-1$
            parameterType));

    ibatorContext.getCommentGenerator().addComment(answer);

    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 (ibatorContext
        .getPlugins()
        .sqlMapUpdateByPrimaryKeyWithBLOBsElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
  }
  @Override
  public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("resultMap"); // $NON-NLS-1$
    answer.addAttribute(
        new Attribute(
            "id", //$NON-NLS-1$
            introspectedTable.getBaseResultMapId()));

    String returnType;
    if (introspectedTable.getRules().generateBaseRecordClass()) {
      returnType = introspectedTable.getBaseRecordType();
    } else {
      returnType = introspectedTable.getPrimaryKeyType();
    }

    answer.addAttribute(
        new Attribute(
            "type", //$NON-NLS-1$
            returnType));

    ibatorContext.getCommentGenerator().addComment(answer);

    int i = 1;
    if (StringUtility.stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())
        || StringUtility.stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
      i++;
    }

    for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
      XmlElement resultElement = new XmlElement("id"); // $NON-NLS-1$

      resultElement.addAttribute(
          new Attribute(
              "column",
              Ibatis3FormattingUtilities.getRenamedColumnNameForResultMap(
                  introspectedColumn))); //$NON-NLS-1$
      resultElement.addAttribute(
          new Attribute("property", introspectedColumn.getJavaProperty())); // $NON-NLS-1$
      resultElement.addAttribute(
          new Attribute(
              "jdbcType", //$NON-NLS-1$
              introspectedColumn.getJdbcTypeName()));

      if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
        resultElement.addAttribute(
            new Attribute("typeHandler", introspectedColumn.getTypeHandler())); // $NON-NLS-1$
      }

      answer.addElement(resultElement);
    }

    for (IntrospectedColumn introspectedColumn : introspectedTable.getBaseColumns()) {
      XmlElement resultElement = new XmlElement("result"); // $NON-NLS-1$

      resultElement.addAttribute(
          new Attribute(
              "column",
              Ibatis3FormattingUtilities.getRenamedColumnNameForResultMap(
                  introspectedColumn))); //$NON-NLS-1$
      resultElement.addAttribute(
          new Attribute("property", introspectedColumn.getJavaProperty())); // $NON-NLS-1$
      resultElement.addAttribute(
          new Attribute(
              "jdbcType", //$NON-NLS-1$
              introspectedColumn.getJdbcTypeName()));

      if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
        resultElement.addAttribute(
            new Attribute("typeHandler", introspectedColumn.getTypeHandler())); // $NON-NLS-1$
      }

      answer.addElement(resultElement);
    }

    if (ibatorContext
        .getPlugins()
        .sqlMapResultMapWithoutBLOBsElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
  }