Package tech.jhipster.service
Class QueryService<ENTITY>
- java.lang.Object
-
- tech.jhipster.service.QueryService<ENTITY>
-
- Type Parameters:
ENTITY
- the type of the entity which is queried.
@Transactional(readOnly=true) public abstract class QueryService<ENTITY> extends Object
Base service for constructing and executing complex queries.
-
-
Constructor Summary
Constructors Constructor Description QueryService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>buildRangeSpecification(RangeFilter<X> filter, javax.persistence.metamodel.SingularAttribute<? super ENTITY,X> field)
Helper function to return a specification for filtering on a singleComparable
, where equality, less than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are supported.protected <OTHER,MISC,X>
org.springframework.data.jpa.domain.Specification<ENTITY>buildReferringEntitySpecification(Filter<X> filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.SetJoin<MISC,OTHER>> functionToEntity, Function<javax.persistence.criteria.SetJoin<MISC,OTHER>,javax.persistence.criteria.Expression<X>> entityToColumn)
Helper function to return a specification for filtering on one-to-many or many-to-many reference.Usage:protected <OTHER,X>
org.springframework.data.jpa.domain.Specification<ENTITY>buildReferringEntitySpecification(Filter<X> filter, javax.persistence.metamodel.SetAttribute<ENTITY,OTHER> reference, javax.persistence.metamodel.SingularAttribute<OTHER,X> valueField)
Helper function to return a specification for filtering on one-to-many or many-to-many reference.protected <OTHER,X>
org.springframework.data.jpa.domain.Specification<ENTITY>buildReferringEntitySpecification(Filter<X> filter, javax.persistence.metamodel.SingularAttribute<? super ENTITY,OTHER> reference, javax.persistence.metamodel.SingularAttribute<? super OTHER,X> valueField)
Helper function to return a specification for filtering on one-to-one or many-to-one reference.protected <OTHER,MISC,X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>buildReferringEntitySpecification(RangeFilter<X> filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.SetJoin<MISC,OTHER>> functionToEntity, Function<javax.persistence.criteria.SetJoin<MISC,OTHER>,javax.persistence.criteria.Expression<X>> entityToColumn)
Helper function to return a specification for filtering on one-to-many or many-to-many reference.Where equality, less than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are supported.protected <OTHER,X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>buildReferringEntitySpecification(RangeFilter<X> filter, javax.persistence.metamodel.SetAttribute<ENTITY,OTHER> reference, javax.persistence.metamodel.SingularAttribute<OTHER,X> valueField)
Helper function to return a specification for filtering on one-to-many or many-to-many reference.Where equality, less than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are supported.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>
buildSpecification(Filter<X> filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction)
Helper function to return a specification for filtering on a single field, where equality, and null/non-null conditions are supported.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>
buildSpecification(Filter<X> filter, javax.persistence.metamodel.SingularAttribute<? super ENTITY,X> field)
Helper function to return a specification for filtering on a single field, where equality, and null/non-null conditions are supported.protected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>buildSpecification(RangeFilter<X> filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction)
Helper function to return a specification for filtering on a singleComparable
, where equality, less than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are supported.protected org.springframework.data.jpa.domain.Specification<ENTITY>
buildSpecification(StringFilter filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<String>> metaclassFunction)
Helper function to return a specification for filtering on aString
field, where equality, containment, and null/non-null conditions are supported.protected org.springframework.data.jpa.domain.Specification<ENTITY>
buildStringSpecification(StringFilter filter, javax.persistence.metamodel.SingularAttribute<? super ENTITY,String> field)
Helper function to return a specification for filtering on aString
field, where equality, containment, and null/non-null conditions are supported.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>
byFieldEmptiness(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<Set<X>>> metaclassFunction, boolean specified)
byFieldEmptiness.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>
byFieldSpecified(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, boolean specified)
byFieldSpecified.protected org.springframework.data.jpa.domain.Specification<ENTITY>
distinct(boolean distinct)
distinct.protected org.springframework.data.jpa.domain.Specification<ENTITY>
doesNotContainSpecification(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<String>> metaclassFunction, String value)
doesNotContainSpecification.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>
equalsSpecification(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
Generic method, which based on a Root<ENTITY> returns an Expression which type is the same as the given 'value' type.protected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>greaterThan(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
greaterThan.protected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>greaterThanOrEqualTo(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
greaterThanOrEqualTo.protected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>lessThan(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
lessThan.protected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>lessThanOrEqualTo(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
lessThanOrEqualTo.protected org.springframework.data.jpa.domain.Specification<ENTITY>
likeUpperSpecification(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<String>> metaclassFunction, String value)
likeUpperSpecification.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>
notEqualsSpecification(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
Generic method, which based on a Root<ENTITY> returns an Expression which type is the same as the given 'value' type.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>
valueIn(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, Collection<X> values)
valueIn.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>
valueNotIn(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, Collection<X> values)
valueNotIn.protected String
wrapLikeQuery(String txt)
wrapLikeQuery.
-
-
-
Method Detail
-
buildSpecification
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> buildSpecification(Filter<X> filter, javax.persistence.metamodel.SingularAttribute<? super ENTITY,X> field)
Helper function to return a specification for filtering on a single field, where equality, and null/non-null conditions are supported.- Type Parameters:
X
- The type of the attribute which is filtered.- Parameters:
filter
- the individual attribute filter coming from the frontend.field
- the JPA static metamodel representing the field.- Returns:
- a Specification
-
buildSpecification
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> buildSpecification(Filter<X> filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction)
Helper function to return a specification for filtering on a single field, where equality, and null/non-null conditions are supported.- Type Parameters:
X
- The type of the attribute which is filtered.- Parameters:
filter
- the individual attribute filter coming from the frontend.metaclassFunction
- the function, which navigates from the current entity to a column, for which the filter applies.- Returns:
- a Specification
-
buildStringSpecification
protected org.springframework.data.jpa.domain.Specification<ENTITY> buildStringSpecification(StringFilter filter, javax.persistence.metamodel.SingularAttribute<? super ENTITY,String> field)
Helper function to return a specification for filtering on aString
field, where equality, containment, and null/non-null conditions are supported.- Parameters:
filter
- the individual attribute filter coming from the frontend.field
- the JPA static metamodel representing the field.- Returns:
- a Specification
-
buildSpecification
protected org.springframework.data.jpa.domain.Specification<ENTITY> buildSpecification(StringFilter filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<String>> metaclassFunction)
Helper function to return a specification for filtering on aString
field, where equality, containment, and null/non-null conditions are supported.- Parameters:
filter
- the individual attribute filter coming from the frontend.metaclassFunction
- lambda, which based on a Root<ENTITY> returns Expression - basicaly picks a column- Returns:
- a Specification
-
buildRangeSpecification
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> buildRangeSpecification(RangeFilter<X> filter, javax.persistence.metamodel.SingularAttribute<? super ENTITY,X> field)
Helper function to return a specification for filtering on a singleComparable
, where equality, less than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are supported.- Type Parameters:
X
- The type of the attribute which is filtered.- Parameters:
filter
- the individual attribute filter coming from the frontend.field
- the JPA static metamodel representing the field.- Returns:
- a Specification
-
buildSpecification
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> buildSpecification(RangeFilter<X> filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction)
Helper function to return a specification for filtering on a singleComparable
, where equality, less than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are supported.- Type Parameters:
X
- The type of the attribute which is filtered.- Parameters:
filter
- the individual attribute filter coming from the frontend.metaclassFunction
- lambda, which based on a Root<ENTITY> returns Expression - basicaly picks a column- Returns:
- a Specification
-
buildReferringEntitySpecification
protected <OTHER,X> org.springframework.data.jpa.domain.Specification<ENTITY> buildReferringEntitySpecification(Filter<X> filter, javax.persistence.metamodel.SingularAttribute<? super ENTITY,OTHER> reference, javax.persistence.metamodel.SingularAttribute<? super OTHER,X> valueField)
Helper function to return a specification for filtering on one-to-one or many-to-one reference. Usage:Specification<Employee> specByProjectId = buildReferringEntitySpecification(criteria.getProjectId(), Employee_.project, Project_.id); Specification<Employee> specByProjectName = buildReferringEntitySpecification(criteria.getProjectName(), Employee_.project, Project_.name);
- Type Parameters:
OTHER
- The type of the referenced entity.X
- The type of the attribute which is filtered.- Parameters:
filter
- the filter object which contains a value, which needs to match or a flag if nullness is checked.reference
- the attribute of the static metamodel for the referring entity.valueField
- the attribute of the static metamodel of the referred entity, where the equality should be checked.- Returns:
- a Specification
-
buildReferringEntitySpecification
protected <OTHER,X> org.springframework.data.jpa.domain.Specification<ENTITY> buildReferringEntitySpecification(Filter<X> filter, javax.persistence.metamodel.SetAttribute<ENTITY,OTHER> reference, javax.persistence.metamodel.SingularAttribute<OTHER,X> valueField)
Helper function to return a specification for filtering on one-to-many or many-to-many reference. Usage:Specification<Employee> specByEmployeeId = buildReferringEntitySpecification(criteria.getEmployeId(), Project_.employees, Employee_.id); Specification<Employee> specByEmployeeName = buildReferringEntitySpecification(criteria.getEmployeName(), Project_.project, Project_.name);
- Type Parameters:
OTHER
- The type of the referenced entity.X
- The type of the attribute which is filtered.- Parameters:
filter
- the filter object which contains a value, which needs to match or a flag if emptiness is checked.reference
- the attribute of the static metamodel for the referring entity.valueField
- the attribute of the static metamodel of the referred entity, where the equality should be checked.- Returns:
- a Specification
-
buildReferringEntitySpecification
protected <OTHER,MISC,X> org.springframework.data.jpa.domain.Specification<ENTITY> buildReferringEntitySpecification(Filter<X> filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.SetJoin<MISC,OTHER>> functionToEntity, Function<javax.persistence.criteria.SetJoin<MISC,OTHER>,javax.persistence.criteria.Expression<X>> entityToColumn)
Helper function to return a specification for filtering on one-to-many or many-to-many reference.Usage:Specification<Employee> specByEmployeeId = buildReferringEntitySpecification( criteria.getEmployeId(), root -> root.get(Project_.company).join(Company_.employees), entity -> entity.get(Employee_.id)); Specification<Employee> specByProjectName = buildReferringEntitySpecification( criteria.getProjectName(), root -> root.get(Project_.project) entity -> entity.get(Project_.name));
- Type Parameters:
OTHER
- The type of the referenced entity.MISC
- The type of the entity which is the last before the OTHER in the chain.X
- The type of the attribute which is filtered.- Parameters:
filter
- the filter object which contains a value, which needs to match or a flag if emptiness is checked.functionToEntity
- the function, which joins he current entity to the entity set, on which the filtering is applied.entityToColumn
- the function, which of the static metamodel of the referred entity, where the equality should be checked.- Returns:
- a Specification
-
buildReferringEntitySpecification
protected <OTHER,X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> buildReferringEntitySpecification(RangeFilter<X> filter, javax.persistence.metamodel.SetAttribute<ENTITY,OTHER> reference, javax.persistence.metamodel.SingularAttribute<OTHER,X> valueField)
Helper function to return a specification for filtering on one-to-many or many-to-many reference.Where equality, less than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are supported. Usage:Specification<Employee> specByEmployeeId = buildReferringEntitySpecification(criteria.getEmployeId(), Project_.employees, Employee_.id); Specification<Employee> specByEmployeeName = buildReferringEntitySpecification(criteria.getEmployeName(), Project_.project, Project_.name);
- Type Parameters:
X
- The type of the attribute which is filtered.OTHER
- The type of the referenced entity.- Parameters:
filter
- the filter object which contains a value, which needs to match or a flag if emptiness is checked.reference
- the attribute of the static metamodel for the referring entity.valueField
- the attribute of the static metamodel of the referred entity, where the equality should be checked.- Returns:
- a Specification
-
buildReferringEntitySpecification
protected <OTHER,MISC,X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> buildReferringEntitySpecification(RangeFilter<X> filter, Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.SetJoin<MISC,OTHER>> functionToEntity, Function<javax.persistence.criteria.SetJoin<MISC,OTHER>,javax.persistence.criteria.Expression<X>> entityToColumn)
Helper function to return a specification for filtering on one-to-many or many-to-many reference.Where equality, less than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are supported. Usage:Specification<Employee> specByEmployeeId = buildReferringEntitySpecification( criteria.getEmployeId(), root -> root.get(Project_.company).join(Company_.employees), entity -> entity.get(Employee_.id)); Specification<Employee> specByProjectName = buildReferringEntitySpecification( criteria.getProjectName(), root -> root.get(Project_.project) entity -> entity.get(Project_.name));
- Type Parameters:
X
- The type of the attribute which is filtered.OTHER
- The type of the referenced entity.MISC
- The type of the entity which is the last before the OTHER in the chain.- Parameters:
filter
- the filter object which contains a value, which needs to match or a flag if emptiness is checked.functionToEntity
- the function, which joins he current entity to the entity set, on which the filtering is applied.entityToColumn
- the function, which of the static metamodel of the referred entity, where the equality should be checked.- Returns:
- a Specification
-
equalsSpecification
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> equalsSpecification(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
Generic method, which based on a Root<ENTITY> returns an Expression which type is the same as the given 'value' type.- Type Parameters:
X
- The type of the attribute which is filtered.- Parameters:
metaclassFunction
- function which returns the column which is used for filtering.value
- the actual value to filter for.- Returns:
- a Specification.
-
notEqualsSpecification
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> notEqualsSpecification(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
Generic method, which based on a Root<ENTITY> returns an Expression which type is the same as the given 'value' type.- Type Parameters:
X
- The type of the attribute which is filtered.- Parameters:
metaclassFunction
- function which returns the column which is used for filtering.value
- the actual value to exclude for.- Returns:
- a Specification.
-
likeUpperSpecification
protected org.springframework.data.jpa.domain.Specification<ENTITY> likeUpperSpecification(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<String>> metaclassFunction, String value)
likeUpperSpecification.
-
doesNotContainSpecification
protected org.springframework.data.jpa.domain.Specification<ENTITY> doesNotContainSpecification(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<String>> metaclassFunction, String value)
doesNotContainSpecification.
-
byFieldSpecified
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> byFieldSpecified(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, boolean specified)
byFieldSpecified.
- Type Parameters:
X
- a X object.- Parameters:
metaclassFunction
- aFunction
object.specified
- a boolean.- Returns:
- a
Specification
object.
-
byFieldEmptiness
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> byFieldEmptiness(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<Set<X>>> metaclassFunction, boolean specified)
byFieldEmptiness.
- Type Parameters:
X
- a X object.- Parameters:
metaclassFunction
- aFunction
object.specified
- a boolean.- Returns:
- a
Specification
object.
-
valueIn
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> valueIn(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, Collection<X> values)
valueIn.
- Type Parameters:
X
- a X object.- Parameters:
metaclassFunction
- aFunction
object.values
- aCollection
object.- Returns:
- a
Specification
object.
-
valueNotIn
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> valueNotIn(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, Collection<X> values)
valueNotIn.
- Type Parameters:
X
- a X object.- Parameters:
metaclassFunction
- aFunction
object.values
- aCollection
object.- Returns:
- a
Specification
object.
-
greaterThanOrEqualTo
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> greaterThanOrEqualTo(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
greaterThanOrEqualTo.
- Type Parameters:
X
- a X object.- Parameters:
metaclassFunction
- aFunction
object.value
- a X object.- Returns:
- a
Specification
object.
-
greaterThan
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> greaterThan(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
greaterThan.
- Type Parameters:
X
- a X object.- Parameters:
metaclassFunction
- aFunction
object.value
- a X object.- Returns:
- a
Specification
object.
-
lessThanOrEqualTo
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> lessThanOrEqualTo(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
lessThanOrEqualTo.
- Type Parameters:
X
- a X object.- Parameters:
metaclassFunction
- aFunction
object.value
- a X object.- Returns:
- a
Specification
object.
-
lessThan
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> lessThan(Function<javax.persistence.criteria.Root<ENTITY>,javax.persistence.criteria.Expression<X>> metaclassFunction, X value)
lessThan.
- Type Parameters:
X
- a X object.- Parameters:
metaclassFunction
- aFunction
object.value
- a X object.- Returns:
- a
Specification
object.
-
distinct
protected org.springframework.data.jpa.domain.Specification<ENTITY> distinct(boolean distinct)
distinct.
- Parameters:
distinct
- a boolean.- Returns:
- a
Specification
object.
-
-