Package org.appng.persistence.repository
Class SearchRepositoryImpl<T,ID extends Serializable>
- java.lang.Object
-
- org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,ID>
-
- org.appng.persistence.repository.SearchRepositoryImpl<T,ID>
-
- Type Parameters:
T
- the domain classID
- the type of the Id of the domain class
- All Implemented Interfaces:
SearchRepository<T,ID>
,org.springframework.data.jpa.repository.JpaRepository<T,ID>
,org.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
,org.springframework.data.jpa.repository.support.JpaRepositoryImplementation<T,ID>
,org.springframework.data.repository.CrudRepository<T,ID>
,org.springframework.data.repository.PagingAndSortingRepository<T,ID>
,org.springframework.data.repository.query.QueryByExampleExecutor<T>
,org.springframework.data.repository.Repository<T,ID>
- Direct Known Subclasses:
EnversSearchRepositoryImpl
,QueryDslSearchRepositoryImpl
public class SearchRepositoryImpl<T,ID extends Serializable> extends org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,ID> implements SearchRepository<T,ID>
DefaultSearchRepository
implementation.
Use this class as the base class for yourSearchRepository
implementations:<repositories base-class="org.appng.persistence.repository.SearchRepositoryImpl">
See 4.6.2. Adding custom behavior to all repositories from the reference Documentation for further details.- Author:
- Matthias Müller
-
-
Field Summary
Fields Modifier and Type Field Description protected Class<T>
domainClass
protected javax.persistence.EntityManager
entityManager
-
Constructor Summary
Constructors Constructor Description SearchRepositoryImpl(Class<T> domainType, javax.persistence.EntityManager entityManager)
SearchRepositoryImpl(org.springframework.data.jpa.repository.support.JpaEntityInformation<T,?> entityInformation, javax.persistence.EntityManager entityManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SearchQuery<T>
createSearchQuery()
Creates and returns a newSearchQuery
.void
detach(T entity)
Detaches the entity from the underlyingEntityManager
.org.springframework.data.domain.Page<T>
findAll(org.springframework.data.domain.Pageable pageable)
Collection<T>
getHistory(ID id)
Returns all previous revisions (starting with the newest) for the entity with the given ID (if the domain-class is audited).T
getOne(ID id)
Retrieves an entity by its id.T
getRevision(ID id, Number revision)
Returns the requested revision of the entity with the requested ID (if the domain-class is audited);Number
getRevisionNumber(ID id)
If the domain-class is audited, the latest revision number of the entity is returned.boolean
isUnique(ID id, String[] properties, Object[] values)
Checks whether the given properties are unique for this domain type.boolean
isUnique(ID id, String property, Object value)
Checks whether the given property is unique for this domain type.List<T>
search(String queryString, Object... args)
Performs a search with the given query-String.org.springframework.data.domain.Page<T>
search(String queryString, String entityName, org.springframework.data.domain.Pageable pageable, Object... args)
Performs a paginated search based upon the given query-String.Note that the query string must start with "from <Entity> <entityName>"!org.springframework.data.domain.Page<T>
search(SearchQuery<T> searchQuery, org.springframework.data.domain.Pageable pageable)
Performs a paginated search with the givenSearchQuery
.org.springframework.data.domain.Page<T>
search(org.springframework.data.domain.Pageable pageable)
Performs a paginated search.
In contrast toPagingAndSortingRepository.findAll(Pageable)
, this method is able to re-calculate the pagination.-
Methods inherited from class org.springframework.data.jpa.repository.support.SimpleJpaRepository
count, count, count, delete, deleteAll, deleteAll, deleteAllById, deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteById, exists, exists, existsById, findAll, findAll, findAll, findAll, findAll, findAll, findAll, findAll, findAllById, findBy, findById, findOne, findOne, flush, getById, getCountQuery, getCountQuery, getDomainClass, getQuery, getQuery, getQuery, getQuery, getQueryHints, getReferenceById, getRepositoryMethodMetadata, readPage, readPage, save, saveAll, saveAllAndFlush, saveAndFlush, setEscapeCharacter, setRepositoryMethodMetadata
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save
-
Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, findAll, findAll, findAllById, flush, getById, getReferenceById, saveAll, saveAllAndFlush, saveAndFlush
-
-
-
-
Constructor Detail
-
SearchRepositoryImpl
public SearchRepositoryImpl(org.springframework.data.jpa.repository.support.JpaEntityInformation<T,?> entityInformation, javax.persistence.EntityManager entityManager)
-
-
Method Detail
-
getOne
public T getOne(ID id)
Description copied from interface:SearchRepository
Retrieves an entity by its id.- Specified by:
getOne
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Serializable>
- Specified by:
getOne
in interfaceSearchRepository<T,ID extends Serializable>
- Overrides:
getOne
in classorg.springframework.data.jpa.repository.support.SimpleJpaRepository<T,ID extends Serializable>
- Parameters:
id
- must not be null.- Returns:
- the entity with the given id or null if none found.
-
findAll
public org.springframework.data.domain.Page<T> findAll(org.springframework.data.domain.Pageable pageable)
- Specified by:
findAll
in interfaceorg.springframework.data.repository.PagingAndSortingRepository<T,ID extends Serializable>
- Overrides:
findAll
in classorg.springframework.data.jpa.repository.support.SimpleJpaRepository<T,ID extends Serializable>
-
search
public org.springframework.data.domain.Page<T> search(org.springframework.data.domain.Pageable pageable)
Description copied from interface:SearchRepository
Performs a paginated search.
In contrast toPagingAndSortingRepository.findAll(Pageable)
, this method is able to re-calculate the pagination. This means, ifPageable.getOffset()
returns a higher number thanPage.getTotalElements()
, a newPageable
is created, starting with page 0.- Specified by:
search
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
pageable
- aPageable
- Returns:
- a
Page
containing the result
-
search
public org.springframework.data.domain.Page<T> search(String queryString, String entityName, org.springframework.data.domain.Pageable pageable, Object... args)
Description copied from interface:SearchRepository
Performs a paginated search based upon the given query-String.Note that the query string must start with "from <Entity> <entityName>"!- Specified by:
search
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
queryString
- the JPQL-query, starting with "from <Entity> <entityName>"entityName
- the alias used for the entity within the query.
E.g. if your query isfrom Foo f
, then the entityName needs to bef
.pageable
- aPageable
args
- the parameters to be applied to theQuery
, usingQuery.setParameter(int, Object)
.- Returns:
- a
Page
containing the result
-
search
public List<T> search(String queryString, Object... args)
Description copied from interface:SearchRepository
Performs a search with the given query-String.- Specified by:
search
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
queryString
- the JPQL-queryargs
- the parameters to be applied to theQuery
, usingQuery.setParameter(int, Object)
.- Returns:
- a
Page
containing the result
-
search
public org.springframework.data.domain.Page<T> search(SearchQuery<T> searchQuery, org.springframework.data.domain.Pageable pageable)
Description copied from interface:SearchRepository
Performs a paginated search with the givenSearchQuery
.- Specified by:
search
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
searchQuery
- theSearchQuery
pageable
- aPageable
(optional)- Returns:
- a
Page
containing the result. Whenpageable
is null, a single page containing all results will be returned
-
getHistory
public Collection<T> getHistory(ID id)
Description copied from interface:SearchRepository
Returns all previous revisions (starting with the newest) for the entity with the given ID (if the domain-class is audited).- Specified by:
getHistory
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
id
- the ID of the entity- Returns:
- the previous revisions of the entity, if any
-
getRevision
public T getRevision(ID id, Number revision)
Description copied from interface:SearchRepository
Returns the requested revision of the entity with the requested ID (if the domain-class is audited);- Specified by:
getRevision
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
id
- the ID of the entityrevision
- the revision of the entity- Returns:
- the requested revision of the entity with the requested ID. If either the entity or the revision does not
exist,
null
is returned.
-
getRevisionNumber
public Number getRevisionNumber(ID id)
Description copied from interface:SearchRepository
If the domain-class is audited, the latest revision number of the entity is returned.- Specified by:
getRevisionNumber
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
id
- the ID of the entity to get the revision for.- Returns:
- the revision of the entity, or
null
if the domain-class is not audited or an entity with this ID does not exist
-
isUnique
public boolean isUnique(ID id, String property, Object value)
Description copied from interface:SearchRepository
Checks whether the given property is unique for this domain type.- Specified by:
isUnique
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
id
- the ID of the entity to check, may benull
if it's a new entityproperty
- the name of the property to check uniqueness for, must not benull
value
- the value of the property to check uniqueness for, must not benull
- Returns:
true
, if there is no other entity where the given property has the given value,false
otherwise
-
isUnique
public boolean isUnique(ID id, String[] properties, Object[] values)
Description copied from interface:SearchRepository
Checks whether the given properties are unique for this domain type.- Specified by:
isUnique
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
id
- the ID of the entity to check, may benull
if it's a new entityproperties
- the names of the properties to check uniqueness for, must not benull
values
- the values of the properties to check uniqueness for, must not benull
- Returns:
true
, if there is no other entity where the given properties have the given values,false
otherwise
-
detach
public void detach(T entity)
Description copied from interface:SearchRepository
Detaches the entity from the underlyingEntityManager
.- Specified by:
detach
in interfaceSearchRepository<T,ID extends Serializable>
- Parameters:
entity
- the entity to detach
-
createSearchQuery
public SearchQuery<T> createSearchQuery()
Description copied from interface:SearchRepository
Creates and returns a newSearchQuery
.- Specified by:
createSearchQuery
in interfaceSearchRepository<T,ID extends Serializable>
- Returns:
- the
SearchQuery
-
-