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

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


  }

  @Override
  public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable, "根据主键删除记录");
    if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(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);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator().getDeleteByPrimaryKeyMethodName(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

  }

  @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.getUpdateByExampleStatementId(), "parms")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

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

    if (context.getPlugins().clientUpdateByExampleWithoutBLOBsMethodGenerated(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().clientUpdateByExampleWithoutBLOBsMethodGenerated(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().getUpdateByExampleWithoutBLOBsMethodName(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);

    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.getInsertStatementId(), "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().clientInsertMethodGenerated(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().clientInsertMethodGenerated(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);
    DAOMethodNameCalculator methodNameCalculator = getDAOMethodNameCalculator();
    method.setName(methodNameCalculator.getInsertMethodName(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

    innerClass.setVisibility(JavaVisibility.PROTECTED);
    innerClass.setStatic(true);
    innerClass.setSuperClass(introspectedTable.getExampleType());
    context.getCommentGenerator().addClassComment(innerClass, introspectedTable);

    Method method = new Method();
    method.setConstructor(true);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(innerClass.getType().getShortName());
    method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "record")); //$NON-NLS-1$
    method.addParameter(new Parameter(new FullyQualifiedJavaType(introspectedTable.getExampleType()), "example")); //$NON-NLS-1$
    method.addBodyLine("super(example);"); //$NON-NLS-1$
    method.addBodyLine("this.record = record;"); //$NON-NLS-1$
    innerClass.addMethod(method);

    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(FullyQualifiedJavaType.getObjectInstance());
    field.setName("record"); //$NON-NLS-1$
    innerClass.addField(field);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getObjectInstance());
    method.setName("getRecord"); //$NON-NLS-1$
    method.addBodyLine("return record;"); //$NON-NLS-1$
    innerClass.addMethod(method);

    topLevelClass.addInnerClass(innerClass);
  }
View Full Code Here

public class UpdateByExampleSelectiveMethodGenerator extends AbstractDAOElementGenerator {

  @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.getUpdateByExampleSelectiveStatementId(), "parms")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

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

    if (context.getPlugins()
        .clientUpdateByExampleSelectiveMethodGenerated(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.