Package org.mybatis.generator.api.dom.java

Examples of org.mybatis.generator.api.dom.java.Method


  @Override
  public void addInterfaceElements(Interface interfaze) {
    if (getExampleMethodVisibility() == JavaVisibility.PUBLIC) {
      Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
      Method method = getMethodShell(importedTypes);
      context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable, "根据条件更新属性不为空的记录");
      if (context.getPlugins()
          .clientUpdateByExampleSelectiveMethodGenerated(method, interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
View Full Code Here


      parameterType = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
    }

    importedTypes.add(parameterType);

    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator().getUpdateByExampleSelectiveMethodName(introspectedTable));
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$
    method.addParameter(new Parameter(new FullyQualifiedJavaType(introspectedTable.getExampleType()), "example")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
      method.addException(fqjt);
      importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
View Full Code Here

  }

  @Override
  public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);

    StringBuilder sb = new StringBuilder();
    sb.append("int rows = "); //$NON-NLS-1$
    sb.append(daoTemplate.getUpdateMethod(introspectedTable.getIbatis2SqlMapNamespace(),
        introspectedTable.getUpdateByPrimaryKeyStatementId(), "record")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

    method.addBodyLine("return rows;"); //$NON-NLS-1$

    if (context.getPlugins().clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(method, topLevelClass,
        introspectedTable)) {
      topLevelClass.addImportedTypes(importedTypes);
      topLevelClass.addMethod(method);
View Full Code Here

  }

  @Override
  public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable, "根据主键更新记录");
    if (context.getPlugins().clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(method, interfaze,
        introspectedTable)) {
      interfaze.addImportedTypes(importedTypes);
      interfaze.addMethod(method);
View Full Code Here

  private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    importedTypes.add(parameterType);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator().getUpdateByPrimaryKeyWithoutBLOBsMethodName(introspectedTable));
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
      method.addException(fqjt);
      importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
View Full Code Here

  protected void addService(Interface interface1,IntrospectedTable introspectedTable, String tableName, List<GeneratedJavaFile> files) {

    interface1.setVisibility(JavaVisibility.PUBLIC);

    // 添加方法
    Method method = countByExample(introspectedTable, tableName);
    method.removeAllBodyLines();
    interface1.addMethod(method);

    method = selectByPrimaryKey(introspectedTable, tableName);
    method.removeAllBodyLines();
    interface1.addMethod(method);

    method = selectByExample(introspectedTable, tableName);
    method.removeAllBodyLines();
    interface1.addMethod(method);

    if (enableDeleteByPrimaryKey) {
      method = getOtherInteger("deleteByPrimaryKey", introspectedTable, tableName, 2);
      method.removeAllBodyLines();
      interface1.addMethod(method);
    }
    if (enableUpdateByPrimaryKeySelective) {
      method = getOtherInteger("updateByPrimaryKeySelective", introspectedTable, tableName, 1);
      method.removeAllBodyLines();
      interface1.addMethod(method);
    }
    if (enableUpdateByPrimaryKey) {
      method = getOtherInteger("updateByPrimaryKey", introspectedTable, tableName, 1);
      method.removeAllBodyLines();
      interface1.addMethod(method);
    }
    if (enableDeleteByExample) {
      method = getOtherInteger("deleteByExample", introspectedTable, tableName, 3);
      method.removeAllBodyLines();
      interface1.addMethod(method);
    }
    if (enableUpdateByExampleSelective) {
      method = getOtherInteger("updateByExampleSelective", introspectedTable, tableName, 4);
      method.removeAllBodyLines();
      interface1.addMethod(method);
    }
    if (enableUpdateByExample) {
      method = getOtherInteger("updateByExample", introspectedTable, tableName, 4);
      method.removeAllBodyLines();
      interface1.addMethod(method);
    }
    if (enableInsert) {
      method = getOtherInsertboolean("insert", introspectedTable, tableName);
      method.removeAllBodyLines();
      interface1.addMethod(method);
    }
    if (enableInsertSelective) {
      method = getOtherInsertboolean("insertSelective", introspectedTable, tableName);
      method.removeAllBodyLines();
      interface1.addMethod(method);
    }

    GeneratedJavaFile file = new GeneratedJavaFile(interface1, project);
    files.add(file);
View Full Code Here

  /**
   * 添加方法
   *
   */
  protected Method selectByPrimaryKey(IntrospectedTable introspectedTable, String tableName) {
    Method method = new Method();
    method.setName("selectByPrimaryKey");
    method.setReturnType(pojoType);
    if (introspectedTable.getRules().generatePrimaryKeyClass()) {
      FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
      method.addParameter(new Parameter(type, "key"));
    } else {
      for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
        FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
        method.addParameter(new Parameter(type, introspectedColumn.getJavaProperty()));
      }
    }
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    // method.addBodyLine("try {");
    sb.append("return this.");
    sb.append(getDaoShort());
    sb.append("selectByPrimaryKey");
    sb.append("(");
    for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
      sb.append(introspectedColumn.getJavaProperty());
      sb.append(",");
    }
    sb.setLength(sb.length() - 1);
    sb.append(");");
    method.addBodyLine(sb.toString());
    // method.addBodyLine("} catch (Exception e) {");
    // method.addBodyLine("logger.error(\"Exception: \", e);");
    // method.addBodyLine("return null;");
    // method.addBodyLine("}");
    return method;
View Full Code Here

  /**
   * 添加方法
   *
   */
  protected Method countByExample(IntrospectedTable introspectedTable, String tableName) {
    Method method = new Method();
    method.setName("countByExample");
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.addParameter(new Parameter(pojoCriteriaType, "example"));
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append("int count = this.");
    sb.append(getDaoShort());
    sb.append("countByExample");
    sb.append("(");
    sb.append("example");
    sb.append(");");
    method.addBodyLine(sb.toString());
    method.addBodyLine("logger.debug(\"count: {}\", count);");
    method.addBodyLine("return count;");
    return method;
  }
View Full Code Here

  /**
   * 添加方法
   *
   */
  protected Method selectByExample(IntrospectedTable introspectedTable, String tableName) {
    Method method = new Method();
    method.setName("selectByExample");
    method.setReturnType(new FullyQualifiedJavaType("List<" + tableName + ">"));
    method.addParameter(new Parameter(pojoCriteriaType, "example"));
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append("return this.");
    sb.append(getDaoShort());
    if (introspectedTable.hasBLOBColumns()) {
      sb.append("selectByExampleWithoutBLOBs");
    } else {
      sb.append("selectByExample");
    }
    sb.append("(");
    sb.append("example");
    sb.append(");");
    method.addBodyLine(sb.toString());
    return method;
  }
View Full Code Here

  /**
   * 添加方法
   *
   */
  protected Method getOtherInteger(String methodName, IntrospectedTable introspectedTable, String tableName, int type) {
    Method method = new Method();
    method.setName(methodName);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    String params = addParams(introspectedTable, method, type);
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    // method.addBodyLine("try {");
    sb.append("return this.");
    sb.append(getDaoShort());
    if (introspectedTable.hasBLOBColumns()
        && (!"updateByPrimaryKeySelective".equals(methodName) && !"deleteByPrimaryKey".equals(methodName)
            && !"deleteByExample".equals(methodName) && !"updateByExampleSelective".equals(methodName))) {
      sb.append(methodName + "WithoutBLOBs");
    } else {
      sb.append(methodName);
    }
    sb.append("(");
    sb.append(params);
    sb.append(");");
    method.addBodyLine(sb.toString());
    return method;
  }
View Full Code Here

TOP

Related Classes of org.mybatis.generator.api.dom.java.Method

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.