Example #1
0
 /**
  * 删除实体
  *
  * @param m 实体
  */
 @Transactional
 public void delete(M m) {
   if (m == null) {
     return;
   }
   if (m != null && m instanceof LogicDeleteable) {
     ((LogicDeleteable) m).markDeleted();
     baseRepository.save(m);
   } else {
     baseRepository.delete(m);
   }
 }
Example #2
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);
    }
  }
Example #3
0
 /**
  * 更新单个实体
  *
  * @param m 实体
  * @return 返回更新的实体
  */
 public M update(M m) {
   return baseRepository.save(m);
 }
Example #4
0
 public M saveAndFlush(M m) {
   m = save(m);
   baseRepository.flush();
   return m;
 }
Example #5
0
 /**
  * 按条件分页并排序统计实体数量
  *
  * @param searchable 条件
  * @return
  */
 public Long count(Searchable searchable) {
   return baseRepository.count(searchable.getSpecifications(entityClass));
 }
Example #6
0
 /**
  * 按条件分页并排序查询实体
  *
  * @param searchable 条件
  * @return
  */
 public Page<M> findAll(Searchable searchable) {
   return baseRepository.findAll(searchable.getSpecifications(entityClass), searchable.getPage());
 }
Example #7
0
 /**
  * 按条件排序查询实体
  *
  * @param searchable 条件
  * @return
  */
 public List<M> findAllBySort(Searchable searchable) {
   return baseRepository.findAll(searchable.getSpecifications(entityClass), searchable.getSort());
 }
Example #8
0
 /**
  * 分页及排序查询实体
  *
  * @param pageable 分页及排序数据
  * @return
  */
 public Page<M> findAll(Pageable pageable) {
   return baseRepository.findAll(pageable);
 }
Example #9
0
 /**
  * 按照顺序查询所有实体
  *
  * @param sort
  * @return
  */
 public List<M> findAll(Sort sort) {
   return baseRepository.findAll(sort);
 }
Example #10
0
 /**
  * 查询所有实体
  *
  * @return
  */
 public List<M> findAll() {
   return baseRepository.findAll();
 }
Example #11
0
 /**
  * 统计实体总数
  *
  * @return 实体总数
  */
 public long count() {
   return baseRepository.count();
 }
Example #12
0
 /**
  * 实体是否存在
  *
  * @param id 主键
  * @return 存在 返回true,否则false
  */
 public boolean exists(ID id) {
   return baseRepository.exists(id);
 }
Example #13
0
 /**
  * 按照主键查询
  *
  * @param id 主键
  * @return 返回id对应的实体
  */
 public M findOne(ID id) {
   return baseRepository.findOne(id);
 }