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

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


  @Override
  public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    // 接口方法
    List<Method> methods = interfaze.getMethods();
    FullyQualifiedJavaType types = new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>");
    Parameter parameter = new Parameter(types, "condition", "@Param(\"condition\")");
    Parameter parameter2 = new Parameter(criteria, "example");
    interfaze.addImportedType(FullyQualifiedJavaType.getNewMapInstance());
    boolean first = true;
    for (int i = 0; i < methods.size(); i++) {
      Method method = methods.get(i);
      if (method.getFormattedContent(0, true).contains("Example")) {
View Full Code Here


      IntrospectedTable introspectedTable) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
    method.setName("equals"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "that")); //$NON-NLS-1$
    if (introspectedTable.isJava5Targeted()) {
      method.addAnnotation("@Override"); //$NON-NLS-1$
    }

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

        || rules.generateUpdateByExampleWithoutBLOBs()) {
      Method method = new Method();
      method.setVisibility(JavaVisibility.PROTECTED);
      method.setConstructor(true);
      method.setName(criteria.getShortName());
      method.addParameter(new Parameter(criteria, "example")); //$NON-NLS-1$
      method.addBodyLine("this.orderByClause = example.orderByClause;"); //$NON-NLS-1$
      method.addBodyLine("this.condition = example.condition;"); //$NON-NLS-1$
      method.addBodyLine("this.distinct = example.distinct;"); //$NON-NLS-1$
      method.addBodyLine("this.limit = example.limit;"); //$NON-NLS-1$
      method.addBodyLine("this.start = example.start;"); //$NON-NLS-1$
      topLevelClass.addMethod(method);
    }

    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(types);
    field.setName("condition"); //$NON-NLS-1$
    addFieldComment(field, "存放条件查询值");
    topLevelClass.addField(field);

    // add field, getter, setter for distinct
    field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
    field.setName("distinct"); //$NON-NLS-1$
    addFieldComment(field, "是否相异");
    topLevelClass.addField(field);

    // add field, getter, setter for orderby clause
    field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getStringInstance());
    field.setName("orderByClause"); //$NON-NLS-1$
    addFieldComment(field, "排序字段");
    topLevelClass.addField(field);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName("Criteria"); //$NON-NLS-1$
    method.addBodyLine("condition = new HashMap<String, Object>();"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("clear"); //$NON-NLS-1$
    method.addBodyLine("condition.clear();"); //$NON-NLS-1$
    method.addBodyLine("orderByClause = null;"); //$NON-NLS-1$
    method.addBodyLine("distinct = false;"); //$NON-NLS-1$
    method.addBodyLine("this.limit=null;"); //$NON-NLS-1$
    method.addBodyLine("this.start=null;"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(criteria);
    method.setName("put"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value")); //$NON-NLS-1$
    method.addBodyLine("this.condition.put(condition, value);"); //$NON-NLS-1$
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            查询的条件名称"+OutputUtilities.lineSeparator+"\t * @param value"+OutputUtilities.lineSeparator+"\t *            查询的值", "condition");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setOrderByClause"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClause")); //$NON-NLS-1$
    method.addBodyLine("this.orderByClause = orderByClause;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            排序字段", "orderByClause");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setDistinct"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "distinct")); //$NON-NLS-1$
    method.addBodyLine("this.distinct = distinct;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            是否相异", "distinct");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setCondition"); //$NON-NLS-1$
    method.addParameter(new Parameter(types, "condition")); //$NON-NLS-1$
    method.addBodyLine("this.condition = condition;"); //$NON-NLS-1$
    method.addDeprecated();
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(types);
    method.setName("getCondition"); //$NON-NLS-1$
    method.addBodyLine("return condition;"); //$NON-NLS-1$
    method.addDeprecated();
    topLevelClass.addMethod(method);
    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(FullyQualifiedJavaType.getInteger());
    field.setName("limit"); //$NON-NLS-1$
    topLevelClass.addField(field);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setLimit"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "limit")); //$NON-NLS-1$
    method.addBodyLine("this.limit = limit;"); //$NON-NLS-1$
    addSetterComment(method, "每页大小,即mysql中的length", "limit");
    topLevelClass.addMethod(method);

    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(FullyQualifiedJavaType.getInteger());
    field.setName("start"); //$NON-NLS-1$
    topLevelClass.addField(field);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setStart"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "start")); //$NON-NLS-1$
    method.addBodyLine("this.start = start;"); //$NON-NLS-1$
    addSetterComment(method, "开始行数,即mysql中的offset", "start");
    topLevelClass.addMethod(method);

    GeneratedJavaFile file = new GeneratedJavaFile(topLevelClass, context.getJavaModelGeneratorConfiguration()
View Full Code Here

  @Override
  public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    // 接口方法
    List<Method> methods = interfaze.getMethods();
    Parameter parameter = new Parameter(criteria, "example", "@Param(\"example\")");
    Parameter parameter2 = new Parameter(criteria, "example");
    boolean first = true;
    for (int i = 0; i < methods.size(); i++) {
      Method method = methods.get(i);
      if (method.getFormattedContent(0, true).contains("Example")) {
        int size = method.getParameters().size();
View Full Code Here

    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 {");
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");
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()) {
View Full Code Here

   */
  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 {
View Full Code Here

   * type 的意义 pojo 1 key 2 example 3 pojo+example 4
   */
  protected String addParams(IntrospectedTable introspectedTable, Method method, int type1) {
    switch (type1) {
    case 1:
      method.addParameter(new Parameter(pojoType, "record"));
      return "record";
    case 2:
      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()));
        }
      }
      StringBuffer sb = new StringBuffer();
      for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
        sb.append(introspectedColumn.getJavaProperty());
        sb.append(",");
      }
      if(sb!=null&&sb.length()>1)
      sb.setLength(sb.length() - 1);
      return sb.toString();
    case 3:
      method.addParameter(new Parameter(pojoCriteriaType, "example"));
      return "example";
    case 4:

      method.addParameter(0, new Parameter(pojoType, "record"));
      method.addParameter(1, new Parameter(pojoCriteriaType, "example"));
      return "record, example";
    default:
      break;
    }
    return null;
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);
View Full Code Here

TOP

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

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.