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

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


   * @return the selectKey element
   */
  protected XmlElement getSelectKey(IntrospectedColumn introspectedColumn, GeneratedKey generatedKey) {
    String identityColumnType = introspectedColumn.getFullyQualifiedJavaType().getFullyQualifiedName();

    XmlElement answer = new XmlElement("selectKey"); //$NON-NLS-1$
    answer.addAttribute(new Attribute("resultClass", identityColumnType)); //$NON-NLS-1$
    answer.addAttribute(new Attribute("keyProperty", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
    if (stringHasValue(generatedKey.getType())) {
      answer.addAttribute(new Attribute("type", generatedKey.getType())); //$NON-NLS-1$ 
    }
    answer.addElement(new TextElement(generatedKey.getRuntimeSqlStatement()));

    return answer;
  }
View Full Code Here


    super();
  }

  @Override
  public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$

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

    String returnType;
    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
      returnType = introspectedTable.getRecordWithBLOBsType();
    } else {
      // table has BLOBs, but no BLOB class - BLOB fields must be
      // in the base class
      returnType = introspectedTable.getBaseRecordType();
    }

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

    if (!introspectedTable.isConstructorBased()) {
      answer.addAttribute(new Attribute("extends", //$NON-NLS-1$
          introspectedTable.getBaseResultMapId()));
    }

    context.getCommentGenerator().addComment(answer);
View Full Code Here

    return answer;
  }

  protected XmlElement getBaseColumnListElement() {
    XmlElement answer = new XmlElement("include"); //$NON-NLS-1$
    answer.addAttribute(new Attribute("refid", //$NON-NLS-1$
        introspectedTable.getIbatis2SqlMapNamespace() + "." + introspectedTable.getBaseColumnListId())); //$NON-NLS-1$
    return answer;
  }
View Full Code Here

    }
  }

  private void addResultMapElements(XmlElement answer) {
    for (IntrospectedColumn introspectedColumn : introspectedTable.getBLOBColumns()) {
      XmlElement resultElement = new XmlElement("result"); //$NON-NLS-1$

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

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

      answer.addElement(resultElement);
    }
  }
View Full Code Here

        introspectedTable.getIbatis2SqlMapNamespace() + "." + introspectedTable.getBaseColumnListId())); //$NON-NLS-1$
    return answer;
  }

  protected XmlElement getBlobColumnListElement() {
    XmlElement answer = new XmlElement("include"); //$NON-NLS-1$
    answer.addAttribute(new Attribute("refid", //$NON-NLS-1$
        introspectedTable.getIbatis2SqlMapNamespace() + "." + introspectedTable.getBlobColumnListId())); //$NON-NLS-1$
    return answer;
  }
View Full Code Here

      answer.addElement(resultElement);
    }
  }

  private void addResultMapConstructorElements(XmlElement answer) {
    XmlElement constructor = new XmlElement("constructor"); //$NON-NLS-1$

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

      resultElement.addAttribute(new Attribute(
          "column", MyBatis3FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn))); //$NON-NLS-1$
      resultElement.addAttribute(new Attribute("jdbcType", introspectedColumn.getJdbcTypeName())); //$NON-NLS-1$
      resultElement.addAttribute(new Attribute("javaType", //$NON-NLS-1$
          introspectedColumn.getFullyQualifiedJavaType().getFullyQualifiedName()));

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

      constructor.addElement(resultElement);
    }

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

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

      if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
        // need to use the MyBatis type alias for a primitive byte
        StringBuilder sb = new StringBuilder();
        sb.append('_');
        sb.append(introspectedColumn.getFullyQualifiedJavaType().getShortName());
        resultElement.addAttribute(new Attribute("javaType", //$NON-NLS-1$
            sb.toString()));

      } else if ("byte[]".equals(introspectedColumn.getFullyQualifiedJavaType() //$NON-NLS-1$
          .getFullyQualifiedName())) {
        // need to use the MyBatis type alias for a primitive byte arry
        resultElement.addAttribute(new Attribute("javaType", //$NON-NLS-1$
            "_byte[]")); //$NON-NLS-1$
      } else {
        resultElement.addAttribute(new Attribute("javaType", //$NON-NLS-1$
            introspectedColumn.getFullyQualifiedJavaType().getFullyQualifiedName()));
      }

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

      constructor.addElement(resultElement);
    }
View Full Code Here

    super();
  }

  @Override
  public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$

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

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();

    Iterator<IntrospectedColumn> iter = introspectedTable.getBLOBColumns().iterator();
    while (iter.hasNext()) {
      sb.append(Ibatis2FormattingUtilities.getSelectListPhrase(iter.next()));

      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().sqlMapBlobColumnListElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
View Full Code Here

  @Override
  public void addElements(XmlElement parentElement) {
    String fqjt = introspectedTable.getExampleType();

    XmlElement answer = new XmlElement("select"); //$NON-NLS-1$

    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
        introspectedTable.getSelectByExampleStatementId()));
    answer.addAttribute(new Attribute("resultMap", introspectedTable.getBaseResultMapId())); //$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());

    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().sqlMapSelectByExampleWithoutBLOBsElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
View Full Code Here

  @Override
  public void addElements(XmlElement parentElement) {
    boolean useColumnIndex = isTrue(introspectedTable
        .getTableConfigurationProperty(PropertyRegistry.TABLE_USE_COLUMN_INDEXES));

    XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$

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

    String returnType;
    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
      returnType = introspectedTable.getRecordWithBLOBsType();
    } else {
      // table has BLOBs, but no BLOB class - BLOB fields must be
      // in the base class
      returnType = introspectedTable.getBaseRecordType();
    }

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

    StringBuilder sb = new StringBuilder();
    sb.append(introspectedTable.getIbatis2SqlMapNamespace());
    sb.append('.');
    sb.append(introspectedTable.getBaseResultMapId());
    answer.addAttribute(new Attribute("extends", sb.toString())); //$NON-NLS-1$

    context.getCommentGenerator().addComment(answer);

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

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

      if (useColumnIndex) {
        resultElement.addAttribute(new Attribute("columnIndex", Integer.toString(i++))); //$NON-NLS-1$
      } else {
        resultElement.addAttribute(new Attribute(
            "column", Ibatis2FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn))); //$NON-NLS-1$
      }
      resultElement.addAttribute(new Attribute("property", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
      resultElement.addAttribute(new Attribute("jdbcType", introspectedColumn.getJdbcTypeName())); //$NON-NLS-1$

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

      answer.addElement(resultElement);
    }
View Full Code Here

    super();
  }

  @Override
  public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

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

    context.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.getBaseColumns().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().sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(answer, introspectedTable)) {
      parentElement.addElement(answer);
    }
View Full Code Here

TOP

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

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.