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.
Base service for constructing and executing complex queries.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>buildRangeSpecification(RangeFilter<X> filter, jakarta.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,X> org.springframework.data.jpa.domain.Specification<ENTITY> buildReferringEntitySpecification(Filter<X> filter, jakarta.persistence.metamodel.SetAttribute<ENTITY, OTHER> reference, jakarta.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, jakarta.persistence.metamodel.SingularAttribute<? super ENTITY, OTHER> reference, jakarta.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>
org.springframework.data.jpa.domain.Specification<ENTITY>buildReferringEntitySpecification(Filter<X> filter, Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.SetJoin<MISC, OTHER>> functionToEntity, Function<jakarta.persistence.criteria.SetJoin<MISC, OTHER>, jakarta.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 extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>buildReferringEntitySpecification(RangeFilter<X> filter, jakarta.persistence.metamodel.SetAttribute<ENTITY, OTHER> reference, jakarta.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 <OTHER,MISC, X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>buildReferringEntitySpecification(RangeFilter<X> filter, Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.SetJoin<MISC, OTHER>> functionToEntity, Function<jakarta.persistence.criteria.SetJoin<MISC, OTHER>, jakarta.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 <X> org.springframework.data.jpa.domain.Specification<ENTITY>buildSpecification(Filter<X> filter, jakarta.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> org.springframework.data.jpa.domain.Specification<ENTITY>buildSpecification(Filter<X> filter, Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.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 extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>buildSpecification(RangeFilter<X> filter, Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<String>> metaclassFunction) Helper function to return a specification for filtering on aStringfield, where equality, containment, and null/non-null conditions are supported.protected org.springframework.data.jpa.domain.Specification<ENTITY>buildStringSpecification(StringFilter filter, jakarta.persistence.metamodel.SingularAttribute<? super ENTITY, String> field) Helper function to return a specification for filtering on aStringfield, where equality, containment, and null/non-null conditions are supported.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>byFieldEmptiness(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<Set<X>>> metaclassFunction, boolean specified) byFieldEmptiness.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>byFieldSpecified(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<String>> metaclassFunction, String value) doesNotContainSpecification.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>equalsSpecification(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, X value) greaterThan.protected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>greaterThanOrEqualTo(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, X value) greaterThanOrEqualTo.protected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>lessThan(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, X value) lessThan.protected <X extends Comparable<? super X>>
org.springframework.data.jpa.domain.Specification<ENTITY>lessThanOrEqualTo(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, X value) lessThanOrEqualTo.protected org.springframework.data.jpa.domain.Specification<ENTITY>likeUpperSpecification(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<String>> metaclassFunction, String value) likeUpperSpecification.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>notEqualsSpecification(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, Collection<X> values) valueIn.protected <X> org.springframework.data.jpa.domain.Specification<ENTITY>valueNotIn(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, Collection<X> values) valueNotIn.protected StringwrapLikeQuery(String txt) wrapLikeQuery.
-
Constructor Details
-
QueryService
public QueryService()
-
-
Method Details
-
buildSpecification
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> buildSpecification(Filter<X> filter, jakarta.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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.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, jakarta.persistence.metamodel.SingularAttribute<? super ENTITY, String> field) Helper function to return a specification for filtering on aStringfield, 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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<String>> metaclassFunction) Helper function to return a specification for filtering on aStringfield, 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, jakarta.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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.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, jakarta.persistence.metamodel.SingularAttribute<? super ENTITY, OTHER> reference, jakarta.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, jakarta.persistence.metamodel.SetAttribute<ENTITY, OTHER> reference, jakarta.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, org.springframework.data.jpa.domain.Specification<ENTITY> buildReferringEntitySpecificationX> (Filter<X> filter, Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.SetJoin<MISC, OTHER>> functionToEntity, Function<jakarta.persistence.criteria.SetJoin<MISC, OTHER>, jakarta.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, jakarta.persistence.metamodel.SetAttribute<ENTITY, OTHER> reference, jakarta.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, org.springframework.data.jpa.domain.Specification<ENTITY> buildReferringEntitySpecificationX extends Comparable<? super X>> (RangeFilter<X> filter, Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.SetJoin<MISC, OTHER>> functionToEntity, Function<jakarta.persistence.criteria.SetJoin<MISC, OTHER>, jakarta.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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.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<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<String>> metaclassFunction, String value) likeUpperSpecification.
-
doesNotContainSpecification
protected org.springframework.data.jpa.domain.Specification<ENTITY> doesNotContainSpecification(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<String>> metaclassFunction, String value) doesNotContainSpecification.
-
byFieldSpecified
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> byFieldSpecified(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, boolean specified) byFieldSpecified.
- Type Parameters:
X- a X object.- Parameters:
metaclassFunction- aFunctionobject.specified- a boolean.- Returns:
- a
Specificationobject.
-
byFieldEmptiness
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> byFieldEmptiness(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<Set<X>>> metaclassFunction, boolean specified) byFieldEmptiness.
- Type Parameters:
X- a X object.- Parameters:
metaclassFunction- aFunctionobject.specified- a boolean.- Returns:
- a
Specificationobject.
-
valueIn
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> valueIn(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, Collection<X> values) valueIn.
- Type Parameters:
X- a X object.- Parameters:
metaclassFunction- aFunctionobject.values- aCollectionobject.- Returns:
- a
Specificationobject.
-
valueNotIn
protected <X> org.springframework.data.jpa.domain.Specification<ENTITY> valueNotIn(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, Collection<X> values) valueNotIn.
- Type Parameters:
X- a X object.- Parameters:
metaclassFunction- aFunctionobject.values- aCollectionobject.- Returns:
- a
Specificationobject.
-
greaterThanOrEqualTo
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> greaterThanOrEqualTo(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, X value) greaterThanOrEqualTo.
- Type Parameters:
X- a X object.- Parameters:
metaclassFunction- aFunctionobject.value- a X object.- Returns:
- a
Specificationobject.
-
greaterThan
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> greaterThan(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, X value) greaterThan.
- Type Parameters:
X- a X object.- Parameters:
metaclassFunction- aFunctionobject.value- a X object.- Returns:
- a
Specificationobject.
-
lessThanOrEqualTo
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> lessThanOrEqualTo(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, X value) lessThanOrEqualTo.
- Type Parameters:
X- a X object.- Parameters:
metaclassFunction- aFunctionobject.value- a X object.- Returns:
- a
Specificationobject.
-
lessThan
protected <X extends Comparable<? super X>> org.springframework.data.jpa.domain.Specification<ENTITY> lessThan(Function<jakarta.persistence.criteria.Root<ENTITY>, jakarta.persistence.criteria.Expression<X>> metaclassFunction, X value) lessThan.
- Type Parameters:
X- a X object.- Parameters:
metaclassFunction- aFunctionobject.value- a X object.- Returns:
- a
Specificationobject.
-
wrapLikeQuery
wrapLikeQuery.
-
distinct
distinct.
- Parameters:
distinct- a boolean.- Returns:
- a
Specificationobject.
-