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

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


  private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    importedTypes.add(type);
    importedTypes.add(FullyQualifiedJavaType.getNewListInstance());

    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());

    FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
    if (generateForJava5) {
      FullyQualifiedJavaType fqjt;
      if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
        fqjt = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType());
      } else {
        // the blob fields must be rolled up into the base class
        fqjt = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
      }

      importedTypes.add(fqjt);
      returnType.addTypeArgument(fqjt);
    }
    method.setReturnType(returnType);

    method.setName(getDAOMethodNameCalculator().getSelectByExampleWithBLOBsMethodName(introspectedTable));
    method.addParameter(new Parameter(type, "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);

    // generate the implementation method
    StringBuilder sb = new StringBuilder();

    sb.append("Integer count = (Integer)  "); //$NON-NLS-1$
    sb.append(daoTemplate.getQueryForObjectMethod(introspectedTable.getIbatis2SqlMapNamespace(),
        introspectedTable.getCountByExampleStatementId(), "example")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

    if (generateForJava5) {
      method.addBodyLine("return count;"); //$NON-NLS-1$
    } else {
      method.addBodyLine("return count.intValue();"); //$NON-NLS-1$
    }

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

  @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().clientCountByExampleMethodGenerated(method, interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
      }
View Full Code Here

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

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

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

    return method;
  }
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.getUpdateByPrimaryKeyWithBLOBsStatementId(), "record")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

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

    if (context.getPlugins().clientUpdateByPrimaryKeyWithBLOBsMethodGenerated(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().clientUpdateByPrimaryKeyWithBLOBsMethodGenerated(method, interfaze, introspectedTable)) {
      interfaze.addImportedTypes(importedTypes);
      interfaze.addMethod(method);
    }
View Full Code Here

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

    importedTypes.add(parameterType);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator().getUpdateByPrimaryKeyWithBLOBsMethodName(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

  }

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

    // generate the implementation method
    StringBuilder sb = new StringBuilder();

    if (!introspectedTable.getRules().generatePrimaryKeyClass()) {
      // no primary key class, but primary key is enabled. Primary
      // key columns must be in the base class.
      FullyQualifiedJavaType keyType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
      topLevelClass.addImportedType(keyType);

      sb.setLength(0);
      sb.append(keyType.getShortName());
      sb.append(" _key = new "); //$NON-NLS-1$
      sb.append(keyType.getShortName());
      sb.append("();"); //$NON-NLS-1$
      method.addBodyLine(sb.toString());

      for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
        sb.setLength(0);
        sb.append("_key."); //$NON-NLS-1$
        sb.append(getSetterMethodName(introspectedColumn.getJavaProperty()));
        sb.append('(');
        sb.append(introspectedColumn.getJavaProperty());
        sb.append(");"); //$NON-NLS-1$
        method.addBodyLine(sb.toString());
      }
    }

    FullyQualifiedJavaType returnType = method.getReturnType();

    sb.setLength(0);
    sb.append(returnType.getShortName());
    sb.append(" record = ("); //$NON-NLS-1$
    sb.append(returnType.getShortName());
    sb.append(") "); //$NON-NLS-1$
    sb.append(daoTemplate.getQueryForObjectMethod(introspectedTable.getIbatis2SqlMapNamespace(),
        introspectedTable.getSelectByPrimaryKeyStatementId(), "_key")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return record;"); //$NON-NLS-1$

    if (context.getPlugins().clientSelectByPrimaryKeyMethodGenerated(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().clientSelectByPrimaryKeyMethodGenerated(method, interfaze, introspectedTable)) {
      interfaze.addImportedTypes(importedTypes);
      interfaze.addMethod(method);
    }
View Full Code Here

      interfaze.addMethod(method);
    }
  }

  private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);

    FullyQualifiedJavaType returnType = introspectedTable.getRules().calculateAllFieldsClass();
    method.setReturnType(returnType);
    importedTypes.add(returnType);

    method.setName(getDAOMethodNameCalculator().getSelectByPrimaryKeyMethodName(introspectedTable));

    if (introspectedTable.getRules().generatePrimaryKeyClass()) {
      FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
      importedTypes.add(type);
      method.addParameter(new Parameter(type, "_key")); //$NON-NLS-1$
    } else {
      for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
        FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
        importedTypes.add(type);
        method.addParameter(new Parameter(type, introspectedColumn.getJavaProperty()));
      }
    }

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

    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
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.