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

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


  /**
   * 添加方法
   *
   */
  protected Method getOtherInsertboolean(String methodName, IntrospectedTable introspectedTable, String tableName) {
    Method method = new Method();
    method.setName(methodName);
    method.setReturnType(returnType);
    method.addParameter(new Parameter(pojoType, "record"));
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    if (returnType==null) {
      sb.append("this.");
    } else {
      sb.append("return this.");
    }
    sb.append(getDaoShort());
    sb.append(methodName);
    sb.append("(");
    sb.append("record");
    sb.append(");");
    method.addBodyLine(sb.toString());
    return method;
  }
View Full Code Here


  /**
   * 添加方法
   *
   */
  protected void addMethod(TopLevelClass topLevelClass) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setSuccess");
    method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "success"));
    method.addBodyLine("this.success = success;");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
    method.setName("isSuccess");
    method.addBodyLine("return success;");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setMessage");
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "message"));
    method.addBodyLine("this.message = message;");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getStringInstance());
    method.setName("getMessage");
    method.addBodyLine("return message;");
    topLevelClass.addMethod(method);
  }
View Full Code Here

  /**
   * 添加方法
   *
   */
  protected void addMethod(TopLevelClass topLevelClass, String tableName) {
    Method method2 = new Method();
    for (int i = 0; i < methods.size(); i++) {
      Method method = new Method();
      method2 = methods.get(i);
      method = method2;
      method.removeAllBodyLines();
      method.removeAnnotation();
      StringBuilder sb = new StringBuilder();
      sb.append("return this.");
      sb.append(getDaoShort());
      sb.append(method.getName());
      sb.append("(");
      List<Parameter> list = method.getParameters();
      for (int j = 0; j < list.size(); j++) {
        sb.append(list.get(j).getName());
        sb.append(",");
      }
      sb.setLength(sb.length() - 1);
      sb.append(");");
      method.addBodyLine(sb.toString());
      topLevelClass.addMethod(method);
    }
    methods.clear();
  }
View Full Code Here

    return true;
  }

  @Override
  public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    Method method = topLevelClass.getMethods().get(0);
    addAnnotation(topLevelClass, method);
    method.addParameter(new Parameter(sqlMapClient, "sqlMapClient"));
    method.removeBodyLine(0);
    method.addBodyLine("super.setSqlMapClient(sqlMapClient);");
    return true;
  }
View Full Code Here

    for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
      if (!introspectedColumn.isJdbcCharacterColumn() || !introspectedColumn.isStringColumn()) {
        continue;
      }

      Method method = new Method();
      method.setVisibility(JavaVisibility.PUBLIC);
      method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), "value")); //$NON-NLS-1$

      StringBuilder sb = new StringBuilder();
      sb.append(introspectedColumn.getJavaProperty());
      sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
      sb.insert(0, "and"); //$NON-NLS-1$
      sb.append("LikeInsensitive"); //$NON-NLS-1$
      method.setName(sb.toString());
      method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());

      sb.setLength(0);
      sb.append("addCriterion(\"upper("); //$NON-NLS-1$
      sb.append(Ibatis2FormattingUtilities.getAliasedActualColumnName(introspectedColumn));
      sb.append(") like\", value.toUpperCase(), \""); //$NON-NLS-1$
      sb.append(introspectedColumn.getJavaProperty());
      sb.append("\");"); //$NON-NLS-1$
      method.addBodyLine(sb.toString());
      method.addBodyLine("return this;"); //$NON-NLS-1$

      criteria.addMethod(method);
    }

    return true;
View Full Code Here

*/
public abstract class AbstractJavaGenerator extends AbstractGenerator {
  public abstract List<CompilationUnit> getCompilationUnits();

  public static Method getGetter(Field field) {
    Method method = new Method();
    method.setName(getGetterMethodName(field.getName(), field.getType()));
    method.setReturnType(field.getType());
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append("return "); //$NON-NLS-1$
    sb.append(field.getName());
    sb.append(';');
    method.addBodyLine(sb.toString());
    return method;
  }
View Full Code Here

  public Method getJavaBeansGetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(fqjt);
    method.setName(getGetterMethodName(property, fqjt));
    context.getCommentGenerator().addGetterComment(method, introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    sb.append("return "); //$NON-NLS-1$
    sb.append(property);
    sb.append(';');
    method.addBodyLine(sb.toString());

    return method;
  }
View Full Code Here

  public Method getJavaBeansSetter(IntrospectedColumn introspectedColumn) {
    FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
    String property = introspectedColumn.getJavaProperty();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getSetterMethodName(property));
    method.addParameter(new Parameter(fqjt, property));
    context.getCommentGenerator().addSetterComment(method, introspectedTable, introspectedColumn);

    StringBuilder sb = new StringBuilder();
    if (isTrimStringsEnabled() && introspectedColumn.isStringColumn()) {
      sb.append("this."); //$NON-NLS-1$
      sb.append(property);
      sb.append(" = "); //$NON-NLS-1$
      sb.append(property);
      sb.append(" == null ? null : "); //$NON-NLS-1$
      sb.append(property);
      sb.append(".trim();"); //$NON-NLS-1$
      method.addBodyLine(sb.toString());
    } else {
      sb.append("this."); //$NON-NLS-1$
      sb.append(property);
      sb.append(" = "); //$NON-NLS-1$
      sb.append(property);
      sb.append(';');
      method.addBodyLine(sb.toString());
    }

    return method;
  }
View Full Code Here

    return rootClass;
  }

  protected void addDefaultConstructor(TopLevelClass topLevelClass) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName(topLevelClass.getType().getShortName());
    method.addBodyLine("super();"); //$NON-NLS-1$
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
  }
View Full Code Here

    addCheckedException(new FullyQualifiedJavaType("java.sql.SQLException")); //$NON-NLS-1$
  }

  @Override
  protected void configureConstructorTemplate() {
    Method constructor = new Method();
    constructor.setConstructor(true);
    constructor.setVisibility(JavaVisibility.PUBLIC);
    constructor.addParameter(new Parameter(sqlMapClientType, "sqlMapClient")); //$NON-NLS-1$
    constructor.addBodyLine("super();"); //$NON-NLS-1$
    constructor.addBodyLine("this.sqlMapClient = sqlMapClient;"); //$NON-NLS-1$
    setConstructorTemplate(constructor);
  }
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.