Пример #1
0
 private void addLimitParam(
     TopLevelClass topLevelClass, IntrospectedTable introspectedTable, String name) {
   CommentGenerator commentGenerator = context.getCommentGenerator();
   Field field = new Field();
   field.setVisibility(JavaVisibility.PROTECTED);
   field.setType(FullyQualifiedJavaType.getIntInstance());
   field.setName(name);
   field.setInitializationString("0");
   commentGenerator.addFieldComment(field, introspectedTable);
   topLevelClass.addField(field);
   char c = name.charAt(0);
   String camel = Character.toUpperCase(c) + name.substring(1);
   Method method = new Method();
   method.setVisibility(JavaVisibility.PUBLIC);
   method.setName("set" + camel);
   method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), name));
   method.addBodyLine("this." + name + "=" + name + ";");
   commentGenerator.addGeneralMethodComment(method, introspectedTable);
   topLevelClass.addMethod(method);
   method = new Method();
   method.setVisibility(JavaVisibility.PUBLIC);
   method.setReturnType(FullyQualifiedJavaType.getIntInstance());
   method.setName("get" + camel);
   method.addBodyLine("return " + name + ";");
   commentGenerator.addGeneralMethodComment(method, introspectedTable);
   topLevelClass.addMethod(method);
 }
  private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType parameterType;

    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
      parameterType = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType());
    } else {
      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);

    return method;
  }
 /** 添加方法 */
 protected Method getOtherInteger(
     String methodName, IntrospectedTable introspectedTable, String tableName, int type) {
   Method method = new Method();
   method.setName(methodName);
   method.setReturnType(FullyQualifiedJavaType.getIntInstance());
   String params = addParams(introspectedTable, method, type);
   method.setVisibility(JavaVisibility.PUBLIC);
   StringBuilder sb = new StringBuilder();
   // method.addBodyLine("try {");
   sb.append("return this.");
   sb.append(getDaoShort());
   if (introspectedTable.hasBLOBColumns()
       && (!"updateByPrimaryKeySelective".equals(methodName)
           && !"deleteByPrimaryKey".equals(methodName)
           && !"deleteByExample".equals(methodName)
           && !"updateByExampleSelective".equals(methodName))) {
     sb.append(methodName + "WithoutBLOBs");
   } else {
     sb.append(methodName);
   }
   sb.append("(");
   sb.append(params);
   sb.append(");");
   method.addBodyLine(sb.toString());
   return method;
 }
 /** 添加方法 */
 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");
   sb.append("(");
   sb.append("example");
   sb.append(");");
   method.addBodyLine(sb.toString());
   method.addBodyLine("logger.debug(\"count: {}\", count);");
   method.addBodyLine("return count;");
   return method;
 }
  @Override
  public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(introspectedTable.getDeleteByExampleStatementId());
    method.addParameter(new Parameter(type, "condition")); // $NON-NLS-1$

    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);

    addMapperAnnotations(interfaze, method);

    if (context
        .getPlugins()
        .clientDeleteByExampleMethodGenerated(method, interfaze, introspectedTable)) {
      interfaze.addImportedTypes(importedTypes);
      interfaze.addMethod(method);
    }
  }