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

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


  }

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

    method.addBodyLine("UpdateByExampleParms parms = new UpdateByExampleParms(record, example);"); //$NON-NLS-1$

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

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

    if (context.getPlugins()
        .clientUpdateByExampleWithBLOBsMethodGenerated(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()
          .clientUpdateByExampleWithBLOBsMethodGenerated(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(getExampleMethodVisibility());
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator().getUpdateByExampleWithBLOBsMethodName(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);

    if (generateForJava5) {
      method.addSuppressTypeWarningsAnnotation();
    }

    StringBuilder sb = new StringBuilder();
    sb.append(method.getReturnType().getShortName());
    sb.append(" list = "); //$NON-NLS-1$
    sb.append(daoTemplate.getQueryForListMethod(introspectedTable.getIbatis2SqlMapNamespace(),
        introspectedTable.getSelectByExampleStatementId(), "example")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return list;"); //$NON-NLS-1$

    if (context.getPlugins().clientSelectByExampleWithoutBLOBsMethodGenerated(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().clientSelectByExampleWithoutBLOBsMethodGenerated(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);
    importedTypes.add(FullyQualifiedJavaType.getNewListInstance());

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

    FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
    ;
    if (generateForJava5) {
      FullyQualifiedJavaType fqjt;
      if (introspectedTable.getRules().generateBaseRecordClass()) {
        fqjt = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
      } else if (introspectedTable.getRules().generatePrimaryKeyClass()) {
        fqjt = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
      } else {
        throw new RuntimeException(getString("RuntimeError.12")); //$NON-NLS-1$
      }

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

    method.setReturnType(returnType);

    method.setName(getDAOMethodNameCalculator().getSelectByExampleWithoutBLOBsMethodName(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);

    FullyQualifiedJavaType returnType = method.getReturnType();
    StringBuilder sb = new StringBuilder();

    if (returnType != null) {
      sb.append("Object newKey = "); //$NON-NLS-1$
    }

    sb.append(daoTemplate.getInsertMethod(introspectedTable.getIbatis2SqlMapNamespace(),
        introspectedTable.getInsertSelectiveStatementId(), "record")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

    if (returnType != null) {
      if ("Object".equals(returnType.getShortName())) { //$NON-NLS-1$
        // no need to cast if the return type is Object
        method.addBodyLine("return newKey;"); //$NON-NLS-1$
      } else {
        sb.setLength(0);

        if (returnType.isPrimitive()) {
          PrimitiveTypeWrapper ptw = returnType.getPrimitiveTypeWrapper();
          sb.append("return (("); //$NON-NLS-1$
          sb.append(ptw.getShortName());
          sb.append(") newKey"); //$NON-NLS-1$
          sb.append(")."); //$NON-NLS-1$
          sb.append(ptw.getToPrimitiveMethod());
          sb.append(';');
        } else {
          sb.append("return ("); //$NON-NLS-1$
          sb.append(returnType.getShortName());
          sb.append(") newKey;"); //$NON-NLS-1$
        }

        method.addBodyLine(sb.toString());
      }
    }

    if (context.getPlugins().clientInsertSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) {
      topLevelClass.addImportedTypes(importedTypes);
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().clientInsertSelectiveMethodGenerated(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();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
      IntrospectedColumn introspectedColumn = introspectedTable.getColumn(introspectedTable.getGeneratedKey()
          .getColumn());
      if (introspectedColumn == null) {
        // the specified column doesn't exist, so don't do the generated
        // key
        // (the warning has already been reported)
        returnType = null;
      } else {
        returnType = introspectedColumn.getFullyQualifiedJavaType();
        importedTypes.add(returnType);
      }
    } else {
      returnType = null;
    }
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getDAOMethodNameCalculator().getInsertSelectiveMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules().calculateAllFieldsClass();

    importedTypes.add(parameterType);
    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);

    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());
      }
    }

    sb.setLength(0);
    sb.append("int rows = "); //$NON-NLS-1$
    sb.append(daoTemplate.getDeleteMethod(introspectedTable.getIbatis2SqlMapNamespace(),
        introspectedTable.getDeleteByPrimaryKeyStatementId(), "_key")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return rows;"); //$NON-NLS-1$

    if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(method, topLevelClass, introspectedTable)) {
      topLevelClass.addImportedTypes(importedTypes);
      topLevelClass.addMethod(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.