Filtered Query

abstract class FilteredQuery<T>

The FilteredQuery<T> class is an abstract helper designed to facilitate the dynamic creation and execution of filtered queries using JPA Criteria API. It is structured to simplify filtering, querying, and pagination of entities from a database while allowing custom predicates to be added dynamically by subclasses

Author

Tecknobit - N7ghtm4r3

Since

1.0.5

Parameters

<T>

Type of the entities to retrieve

Constructors

Link copied to clipboard
constructor(entityType: Class<T>, entityManager: EntityManager, rawFilters: Set<String>)
Constructor to init the FilteredQuery

Properties

Link copied to clipboard
protected val criteriaBuilder: CriteriaBuilder
criteriaBuilder the builder to add the criteria to filter the query
Link copied to clipboard
protected val entityManager: EntityManager
entityManager manage the entities
Link copied to clipboard
protected val predicates: ArrayList<Predicate>
predicates the list of predicates to apply to the query
Link copied to clipboard
protected val query: CriteriaQuery<T>
query the criteria prepared query to execute
Link copied to clipboard
rawFilters the filters all together in raw format
Link copied to clipboard
protected val root: Root<T>
root the root table

Functions

Link copied to clipboard
protected open fun extractFiltersByPattern(pattern: Pattern): HashSet<String>
Method to extract from the rawFilters the specific set of filters
Link copied to clipboard
protected abstract fun fillPredicates()
Wrapper method to fill all the predicates dynamically
Link copied to clipboard
open fun getEntities(): List<T>
Method to get the entities executing the query
open fun getEntities(pageable: Pageable): List<T>
Method to get the paginated entities executing the query
Link copied to clipboard
private open fun prepareQuery()
Method to prepare the query adding the predicates