/**
   * 添加实现类
   *
   * @param introspectedTable
   * @param tableName
   * @param files
   */
  protected void addServiceImpl(
      TopLevelClass topLevelClass,
      IntrospectedTable introspectedTable,
      String tableName,
      List<GeneratedJavaFile> files) {
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    // 设置实现的接口
    topLevelClass.addSuperInterface(interfaceType);

    if (enableAnnotation) {
      topLevelClass.addAnnotation("@Service");
      topLevelClass.addImportedType(service);
    }
    // 添加引用dao
    addField(topLevelClass, tableName);
    // 添加方法
    topLevelClass.addMethod(countByExample(introspectedTable, tableName));
    topLevelClass.addMethod(selectByPrimaryKey(introspectedTable, tableName));
    topLevelClass.addMethod(selectByExample(introspectedTable, tableName));

    /** type 的意义 pojo 1 ;key 2 ;example 3 ;pojo+example 4 */
    if (enableDeleteByPrimaryKey) {
      topLevelClass.addMethod(
          getOtherInteger("deleteByPrimaryKey", introspectedTable, tableName, 2));
    }
    if (enableUpdateByPrimaryKeySelective) {
      topLevelClass.addMethod(
          getOtherInteger("updateByPrimaryKeySelective", introspectedTable, tableName, 1));
    }
    if (enableUpdateByPrimaryKey) {
      topLevelClass.addMethod(
          getOtherInteger("updateByPrimaryKey", introspectedTable, tableName, 1));
    }
    if (enableDeleteByExample) {
      topLevelClass.addMethod(getOtherInteger("deleteByExample", introspectedTable, tableName, 3));
    }
    if (enableUpdateByExampleSelective) {
      topLevelClass.addMethod(
          getOtherInteger("updateByExampleSelective", introspectedTable, tableName, 4));
    }
    if (enableUpdateByExample) {
      topLevelClass.addMethod(getOtherInteger("updateByExample", introspectedTable, tableName, 4));
    }
    if (enableInsert) {
      topLevelClass.addMethod(getOtherInsertboolean("insert", introspectedTable, tableName));
    }
    if (enableInsertSelective) {
      topLevelClass.addMethod(
          getOtherInsertboolean("insertSelective", introspectedTable, tableName));
    }
    // 生成文件
    GeneratedJavaFile file =
        new GeneratedJavaFile(
            topLevelClass,
            project,
            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
            context.getJavaFormatter());
    files.add(file);
  }
Пример #2
0
  protected void makeSerializable(
      TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    if (addGWTInterface) {
      topLevelClass.addImportedType(gwtSerializable);
      topLevelClass.addSuperInterface(gwtSerializable);
    }

    if (!suppressJavaInterface) {
      topLevelClass.addImportedType(serializable);
      topLevelClass.addSuperInterface(serializable);

      Field field = new Field();
      field.setFinal(true);
      field.setInitializationString("1L"); // $NON-NLS-1$
      field.setName("serialVersionUID"); // $NON-NLS-1$
      field.setStatic(true);
      field.setType(new FullyQualifiedJavaType("long")); // $NON-NLS-1$
      field.setVisibility(JavaVisibility.PRIVATE);
      context.getCommentGenerator().addFieldComment(field, introspectedTable);

      topLevelClass.addField(field);
    }
  }
Пример #3
0
  @Override
  public boolean modelBaseRecordClassGenerated(
      TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    topLevelClass.addImportedType("java.io.Serializable");
    topLevelClass.addSuperInterface(new FullyQualifiedJavaType("java.io.Serializable"));

    Field field = new Field();
    // private static final long serialVersionUID = 1L;
    field.setName("serialVersionUID");
    field.setType(new FullyQualifiedJavaType("long"));
    field.setStatic(true);
    field.setFinal(true);
    field.setInitializationString("1L");
    topLevelClass.addField(field);
    return super.modelBaseRecordClassGenerated(topLevelClass, introspectedTable);
  }