EntityQuery infrastructure

EntityModule provides an abstraction layer for querying entities. This abstraction is built around the concept of an EntityQuery.

What is an EntityQuery?

Much like a SQL statement, an EntityQuery represents a query to perform on a list of entities (which can in theory be any collection of objects). An EntityQuery can specify one or more predicates that the entities must match, as well as one or more ordering clauses for sorting the resulting items.

An EntityQueryExecutor can execute the EntityQuery and return the collection of entities that match the query.

EntityQuery and entity views

A lot of the default views generated by EntityModule require the presence of an EntityQueryExecutor to function correctly. For example association views use EntityQuery to retrieve the entities associated with another item.

An executor is automatically registered if one can be determined based on the backing data repository, see default support.

EntityQuery Language

Executing a query

Performance

Default support

Any automatically registered Spring Data repository that implements either of the following will have automatic EntityQuery support:

  • JpaSpecificationExecutor

  • QueryDslPredicateExecutor

Depending on the actual repository implementation, some query operations may or may not be supported.

Adding EntityQuery support

EntityQueryExecutor

The EntityQueryExecutor is responsible for executing an EntityQuery and returning the entities requested. An EntityConfiguration can have a single EntityQueryExecutor.class attribute holding the executor instance.

Default implementations exist for JpaSpecificationExecutor and QueryDslPredicateExecutor. This means that any entity configurations having a repository of this type will get an EntityQueryExecutor created automatically.

Since the EntityQueryExecutor is backed by a specific repository implementation, supported functionality also depends on the actual backing repository.

The presence of the EntityQueryExecutor is a requirement for the default entity views.

AssociatedEntityQueryExecutor

Like EntityQueryExecutor that is registered on the EntityConfiguration, every EntityAssociation can have an AssociatedEntityQueryExecutor registered. The AssociatedEntityQueryExecutor allows executing queries in the context of a single parent object.

Like the EntityQueryExecutor, the AssociatedEntityQueryExecutor is usually added automatically.

The presence of the AssociatedEntityQueryExecutor is a requirement for the default association entity views.