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

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


  {
    element.addElement(0, new TextElement(
        "select * from (select a.*, rownum rn from ("));
    element.addElement(new TextElement(") a"));

    XmlElement whereElement_1 = new XmlElement("where");
    XmlElement ifElement_1 = new XmlElement("if");
    ifElement_1.addAttribute(new Attribute("test",
        "startIndex != null and pageSize != null"));
    ifElement_1.addElement(new TextElement(
        "rownum <= (${startIndex} + ${pageSize})"));
    whereElement_1.addElement(ifElement_1);
    element.addElement(whereElement_1);

    element.addElement(new TextElement(")"));

    XmlElement whereElement_2 = new XmlElement("where");
    XmlElement ifElement_2 = new XmlElement("if");
    ifElement_2.addAttribute(new Attribute("test", "startIndex != null"));
    ifElement_2.addElement(new TextElement("rn >= ${startIndex}"));
    whereElement_2.addElement(ifElement_2);
    element.addElement(whereElement_2);

    return true;
  }
View Full Code Here


  {
    element.addElement(0, new TextElement(
        "select * from (select a.*, rownum rn from ("));
    element.addElement(new TextElement(") a"));

    XmlElement whereElement_1 = new XmlElement("where");
    XmlElement ifElement_1 = new XmlElement("if");
    ifElement_1.addAttribute(new Attribute("test",
        "startIndex != null and pageSize != null"));
    ifElement_1.addElement(new TextElement(
        "rownum <= (${startIndex} + ${pageSize})"));
    whereElement_1.addElement(ifElement_1);
    element.addElement(whereElement_1);

    element.addElement(new TextElement(")"));

    XmlElement whereElement_2 = new XmlElement("where");
    XmlElement ifElement_2 = new XmlElement("if");
    ifElement_2.addAttribute(new Attribute("test", "startIndex != null"));
    ifElement_2.addElement(new TextElement("rn >= ${startIndex}"));
    whereElement_2.addElement(ifElement_2);
    element.addElement(whereElement_2);

    return true;
  }
View Full Code Here

    Properties props = new Properties();
    try
    {
      props.load(new FileInputStream(new File(this.getClass()
          .getResource("/com/eatle/persistent/generator/generatorConfig.properties").toURI())));
      XmlElement selectKeyElement = new XmlElement("selectKey");
      selectKeyElement.addAttribute(new Attribute("resultType", "long"));
      selectKeyElement.addAttribute(new Attribute("keyProperty", "id"));
      selectKeyElement.addAttribute(new Attribute("order", "BEFORE"));
      selectKeyElement.addElement(new TextElement("select "
          + props.getProperty("sequenceName")
          + ".NEXTVAL as ID from dual "));

      element.addElement(selectKeyElement);
    }
View Full Code Here

    // 替换所有条件parameterType中的pojoExample
    List<Element> list = document.getRootElement().getElements();
    logger.info(list.size() + "");
    for (int i = 0; i < list.size(); i++) {
      XmlElement xml = (XmlElement) list.get(i);
      String content = xml.getFormattedContent(0);
      if (content.contains(introspectedTable.getExampleType())) {
        List<Attribute> attrs = xml.getAttributes();
        for (int j = 0; j < attrs.size(); j++) {
          if (attrs.get(j).getName().equals("parameterType")) {
            attrs.get(j).setValue(criteria.getFullyQualifiedName());
          }
        }
      } else if (content.contains("Update_By_Example_Where_Clause")) {
        if (xml.getElements().size() == 3) {
          xml = (XmlElement) xml.getElements().get(2);
          xml = (XmlElement) xml.getElements().get(0);
          xml.getAttributes().get(0).setValue("Example_Where_Clause");
        } else {
          for (int j = 0; j < xml.getElements().size(); j++) {
            Element xmls = xml.getElements().get(j);
            if (xmls.getFormattedContent(0).contains("Update_By_Example_Where_Clause")) {
              xml = (XmlElement) xmls;
              xml = (XmlElement) xml.getElements().get(0);
              xml.getAttributes().get(0).setValue("Example_Where_Clause");
            }
          }
        }
      }
    }
    // Example_Where_Clause
    XmlElement Where_Clause = (XmlElement) document.getRootElement().getElements().get(1);
    // 移除第一个
    Where_Clause.removeElement(0);

    StringBuilder sb = new StringBuilder();
    XmlElement dynamicElement = new XmlElement("trim"); //$NON-NLS-1$
    dynamicElement.addAttribute(new Attribute("prefix", "where")); //$NON-NLS-1$ //$NON-NLS-2$
    dynamicElement.addAttribute(new Attribute("prefixOverrides", "and|or")); //$NON-NLS-1$ //$NON-NLS-2$
    Where_Clause.addElement(dynamicElement);

    for (IntrospectedColumn introspectedColumn : introspectedTable.getNonPrimaryKeyColumns()) {
      XmlElement isNotNullElement = new XmlElement("if"); //$NON-NLS-1$
        String va = introspectedColumn.getJavaProperty("condition.") + " != null";
        isNotNullElement.addAttribute(new Attribute("test", va)); //$NON-NLS-1$ //$NON-NLS-2$
      dynamicElement.addElement(isNotNullElement);

      sb.setLength(0);
      sb.append(" and "); //$NON-NLS-1$
      sb.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
      sb.append(" = "); //$NON-NLS-1$
      sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "condition."));
      isNotNullElement.addElement(new TextElement(sb.toString()));
    }
    document.getRootElement().getElements().remove(2);
    return true;
  }
View Full Code Here

  @Override
  public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(XmlElement element,
      IntrospectedTable introspectedTable) {
    if (databaseType.contains("oracle")) {
      XmlElement oracleHeadIncludeElement = new XmlElement("include");
      oracleHeadIncludeElement.addAttribute(new Attribute("refid", "common.Oracle_Pagination_Head"));
      // 在第一个地方增加
      element.addElement(0, oracleHeadIncludeElement);

      XmlElement oracleTailIncludeElement = new XmlElement("include");
      oracleTailIncludeElement.addAttribute(new Attribute("refid", "common.Oracle_Pagination_Tail"));
      // 在最后增加
      element.addElement(element.getElements().size(), oracleTailIncludeElement);
    } else if (databaseType.contains("mysql")) {
      XmlElement mysqlLimitIncludeElement = new XmlElement("include");
      mysqlLimitIncludeElement.addAttribute(new Attribute("refid", "common.Mysql_Pagination_Limit"));
      // 在最后增加
      element.addElement(element.getElements().size(), mysqlLimitIncludeElement);
    }
    return true;
  }
View Full Code Here

  @Override
  public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(XmlElement element,
      IntrospectedTable introspectedTable) {
    if (databaseType.contains("oracle")) {
      XmlElement oracleHeadIncludeElement = new XmlElement("include");
      oracleHeadIncludeElement.addAttribute(new Attribute("refid", "common.Oracle_Pagination_Head"));
      // 在第一个地方增加
      element.addElement(0, oracleHeadIncludeElement);

      XmlElement oracleTailIncludeElement = new XmlElement("include");
      oracleTailIncludeElement.addAttribute(new Attribute("refid", "common.Oracle_Pagination_Tail"));
      // 在最后增加
      element.addElement(element.getElements().size(), oracleTailIncludeElement);
    } else if (databaseType.contains("mysql")) {
      XmlElement mysqlLimitIncludeElement = new XmlElement("include");
      mysqlLimitIncludeElement.addAttribute(new Attribute("refid", "common.Mysql_Pagination_Limit"));
      // 在最后增加
      element.addElement(element.getElements().size(), mysqlLimitIncludeElement);
    }
    return true;
  }
View Full Code Here

  }

  @Override
  public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles(IntrospectedTable introspectedTable) {
    Document document = new Document(XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID, XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
    XmlElement answer = new XmlElement("mapper"); //$NON-NLS-1$
    document.setRootElement(answer);
    answer.addAttribute(new Attribute("namespace", //$NON-NLS-1$
        "common"));

    if (databaseType.contains("oracle")) {
      answer.addElement(getOracleHead());
      answer.addElement(getOracleTail());
    } else if (databaseType.contains("mysql")) {
      answer.addElement(getMysqlLimit());
    }

    GeneratedXmlFile gxf = new GeneratedXmlFile(document, properties.getProperty("fileName", "common_SqlMap.xml"), //$NON-NLS-1$ //$NON-NLS-2$
        context.getSqlMapGeneratorConfiguration().getTargetPackage(), //$NON-NLS-1$
        context.getSqlMapGeneratorConfiguration().getTargetProject(), //$NON-NLS-1$
View Full Code Here

    files.add(gxf);
    return files;
  }

  private XmlElement getOracleHead() {
    XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$

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

    XmlElement outerisNotEmptyElement = new XmlElement("if");
    outerisNotEmptyElement.addAttribute(new Attribute("test", "limit != null and start != null"));
    outerisNotEmptyElement.addElement(new TextElement("<![CDATA[ select * from ( select row_.*, rownum rownum_ from ( ]]>"));
    answer.addElement(outerisNotEmptyElement);
    return answer;
  }
View Full Code Here

    answer.addElement(outerisNotEmptyElement);
    return answer;
  }

  private XmlElement getOracleTail() {
    XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$

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

    XmlElement outerisNotEmptyElement = new XmlElement("if");
    outerisNotEmptyElement.addAttribute(new Attribute("test", "limit != null and start != null"));
    outerisNotEmptyElement.addElement(new TextElement(
        "<![CDATA[ ) row_ where rownum <= (#{limit} + #{start}) ) where rownum_ > #{start} ]]>"));
    answer.addElement(outerisNotEmptyElement);
    return answer;
  }
View Full Code Here

  public void setTypeHandler(String typeHandler) {
    this.typeHandler = typeHandler;
  }

  public XmlElement toXmlElement() {
    XmlElement xmlElement = new XmlElement("columnOverride"); //$NON-NLS-1$
    xmlElement.addAttribute(new Attribute("column", columnName)); //$NON-NLS-1$

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

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

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

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

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

    addPropertyXmlElements(xmlElement);

    return xmlElement;
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.