Exemplo n.º 1
0
  /**
   * 根据主键删除相应实体
   *
   * @param ids 实体
   */
  @Transactional
  public void delete(ID[] ids) {
    if (ArrayUtils.isEmpty(ids)) {
      return;
    }
    List<M> models = new ArrayList<M>();
    for (ID id : ids) {
      M model = null;
      try {
        model = (M) entityClass.newInstance();
      } catch (Exception e) {
        throw new RuntimeException("batch delete " + entityClass.getName() + " error", e);
      }
      try {
        BeanUtils.setProperty(model, "id", id);
      } catch (Exception e) {
        throw new RuntimeException(
            "batch delete " + entityClass.getName() + " error, can not set id", e);
      }

      models.add(model);
    }

    if (models.get(0) instanceof LogicDeleteable) {
      String hql =
          String.format(
              "update %s o set o.deleted=true where o in (?1)", this.entityClass.getSimpleName());
      baseDefaultRepositoryImpl.batchUpdate(hql, models);
    } else {
      baseRepository.deleteInBatch(models);
    }
  }