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