类 BaseServiceImpl<T extends BaseEntity,​ID,​BR extends BaseRepository>

  • 所有已实现的接口:
    Observer, IBaseService<T,​ID>

    @Transactional
    public class BaseServiceImpl<T extends BaseEntity,​ID,​BR extends BaseRepository>
    extends Observable
    implements IBaseService<T,​ID>, Observer
    这个类是BaseServcie的实现类,组件的实现类可以继承这个类来利用可以用的方法 继承JDK中的Observable,是为了是观察者模式来处理多表缓存的一致性 继承Observable,说明自己可以被别人观察,实现Observer说明自己也可以观察别人
    • 字段详细资料

      • em

        protected javax.persistence.EntityManager em
      • clazz

        protected Class<T extends BaseEntity> clazz
        Description:获取T的Class对象是关键,看构造方法
      • br

        @Autowired
        public BR extends BaseRepository br
        Description:注入需要的Repository接口的代理类
    • 构造器详细资料

      • BaseServiceImpl

        public BaseServiceImpl()
        Description:无参构造函数,获得T1的clazz对象
    • 方法详细资料

      • findAll

        public org.springframework.data.domain.Page<T> findAll​(org.springframework.data.domain.Pageable var1)
        从接口复制的说明: IBaseService
        Description:
        指定者:
        findAll 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        var1 - 分页对象
        返回:
        Page
      • findOne

        public <S extends TOptional<S> findOne​(org.springframework.data.domain.Example<S> example)
        从接口复制的说明: IBaseService
        Returns a single entity matching the given Example or null if none was found.
        指定者:
        findOne 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        example - must not be null.
        返回:
        a single entity matching the given Example or Optional.empty() if none was found.
      • findAll

        public <S extends TList<S> findAll​(org.springframework.data.domain.Example<S> var1)
        从接口复制的说明: IBaseService
        Returns all entities matching the given Example. In case no match could be found an empty Iterable is returned.
        指定者:
        findAll 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        var1 - must not be null.
        返回:
        all entities matching the given Example.
      • findAll

        public <S extends TList<S> findAll​(org.springframework.data.domain.Example<S> var1,
                                             org.springframework.data.domain.Sort var2)
        从接口复制的说明: IBaseService
        Returns all entities matching the given Example applying the given Sort. In case no match could be found an empty Iterable is returned.
        指定者:
        findAll 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        var1 - must not be null.
        var2 - the Sort specification to sort the results by, must not be null.
        返回:
        all entities matching the given Example.
      • findAll

        public <S extends T> org.springframework.data.domain.Page<S> findAll​(org.springframework.data.domain.Example<S> example,
                                                                             org.springframework.data.domain.Pageable pageable)
        从接口复制的说明: IBaseService
        Returns a Page of entities matching the given Example. In case no match could be found, an empty Page is returned.
        指定者:
        findAll 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        example - must not be null.
        pageable - can be null.
        返回:
        a Page of entities matching the given Example.
      • existsById

        public boolean existsById​(ID var1)
        从接口复制的说明: IBaseService
        Description: 根据ID检查实体是否存在
        指定者:
        existsById 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        var1 - id主键
        返回:
        boolean true存在,false 不存在
      • count

        public <S extends T> long count​(org.springframework.data.domain.Example<S> example)
        从接口复制的说明: IBaseService
        Returns the number of instances matching the given Example.
        指定者:
        count 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        example - the Example to count instances for. Must not be null.
        返回:
        the number of instances matching the Example.
      • exists

        public <S extends T> boolean exists​(org.springframework.data.domain.Example<S> example)
        从接口复制的说明: IBaseService
        Checks whether the data store contains elements that match the given Example.
        指定者:
        exists 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        example - the Example to use for the existence check. Must not be null.
        返回:
        true if the data store contains elements that match the given Example.
      • existsByEntityProperty

        public boolean existsByEntityProperty​(String propertyName,
                                              String propertyValue)
                                       throws NoSuchFieldException
        从接口复制的说明: IBaseService
        Description: 根据实体的属性名称判断,实体是否存在, 注意:使用此方法,要自己保证属性名称的正确性,否则抛异常!
        指定者:
        existsByEntityProperty 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        propertyName - 实体的属性名,暂时支持字符串类型
        propertyValue - 实体的属性名对应的值,仅支持简单的基本类型的值为字符串的,不支持其他的自定义类的类型
        返回:
        boolean true实体存在;false 不存在。
        抛出:
        NoSuchFieldException
      • update

        public <S extends T> S update​(S var1)
        从接口复制的说明: IBaseService
        Description:更新实体的方法,很多时候保存和更新的处理逻辑是不一样的,权限也是不一样的,所以单独分开
        指定者:
        update 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        var1 - 要更新的实体
        返回:
        S
      • advancedQuery

        public List<T> advancedQuery​(T entity)
        Description: 不分页的高级查询,无条件时,最多返回最新的25条记录
        指定者:
        advancedQuery 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        entity - 包含高级查询条件的实体
        返回:
        java.util.List
      • advancedQuery

        public org.springframework.data.domain.Page<T> advancedQuery​(T entity,
                                                                     org.springframework.data.domain.Pageable pageable)
        Description: 高级查询带分页的功能,如果没有查询条件,仅分页返回
        指定者:
        advancedQuery 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        entity - 包含高级查询条件的实体
        pageable - 分页参数对象
        返回:
        org.springframework.data.domain.Page
      • checkPropertyAndValueValidity

        private void checkPropertyAndValueValidity​(T entity)
        Description:检查属性名和属性值的合法性,不合法的属性和值都会被移除
      • getSpecification

        private org.springframework.data.jpa.domain.Specification<T> getSpecification​(T entity)
        Description: 根据条件集合构建查询的表达式
        返回:
        org.springframework.data.jpa.domain.Specification
      • getSpec4PropSetByLike

        private org.springframework.data.jpa.domain.Specification<Object> getSpec4PropSetByLike​(String property,
                                                                                                String value)
        构造查询条件: 获取某个属性的模糊查询匹配的不重复集合,通常数据给ui界面选择使用
        参数:
        property - 要查询的属性
        value - 属性值,可以为空串
        返回:
      • getPropTypeString

        private String getPropTypeString​(String key,
                                         T entity)
        Description:利用反射获取属性的字符串类型
        返回:
        java.lang.String
      • getPropType

        private Class<?> getPropType​(String key,
                                     T entity)
        Description:利用反射获取属性的反射类型
        返回:
        Class
      • isPropertyIllegal

        private boolean isPropertyIllegal​(String property)
        检查属性名是否非法
        参数:
        property -
        返回:
        true--非法;false--合法
      • handleGroupsCondition

        private org.springframework.data.jpa.domain.Specification<T> handleGroupsCondition​(Map<String,​List<BaseSearchField>> groups,
                                                                                           T entity)
        处理多个分组条件的,条件查询构造
      • handleSingleGroupCondition

        private org.springframework.data.jpa.domain.Specification<T> handleSingleGroupCondition​(List<BaseSearchField> fields,
                                                                                                T entity)
        处理同一个组内查询条件的查询条件转换
      • genPredicate4SingleGroup

        private javax.persistence.criteria.Predicate genPredicate4SingleGroup​(List<BaseSearchField> fields,
                                                                              javax.persistence.criteria.Root<T> root,
                                                                              javax.persistence.criteria.CriteriaBuilder cb,
                                                                              T entity)
        处理单个组内的条件生成
      • registObservers

        public void registObservers​(Observer... observers)
        注册观察者,即哪些组件观察自己,让子类调用此方法实现观察者注册
        指定者:
        registObservers 在接口中 IBaseService<T extends BaseEntity,​ID>
      • notifyOthers

        public void notifyOthers​(Object arg)
        自己的状态改变了,通知所有依赖自己的组件进行缓存清除, 通常的增删改的方法都需要调用这个方法,来维持 cache right!
        指定者:
        notifyOthers 在接口中 IBaseService<T extends BaseEntity,​ID>
        参数:
        arg - 通知观察者时可以传递礼物arg,即数据,如果不需要数据就传递null;