Provides entities fetched from a database.
The default query mechanism can be overridden by using
query()
.
Function<EntityQueryModel, List<Entity>> query = queryModel -> {
EntityConnection connection = queryModel.connectionProvider().connection();
return connection.select(Employee.NAME.equalTo("John"));
};
tableModel.queryModel().query().set(query);
- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Specifies an additional condition supplier. -
Method Summary
Modifier and TypeMethodDescriptionReturns theValueSet
controlling which attributes are included when querying entities.When using the default query mechanism, theconditionChanged()
state is reset after each successful query.It can be necessary to prevent the user from selecting too much data, when working with a large dataset.Returns aState
controlling whether this query model should query all underlying entities when no query condition has been set.static EntityQueryModel
entityQueryModel
(EntityConditionModel entityConditionModel) get()
Performs a query and returns the result.having()
Controls the additional HAVING condition, which can be used in conjunction withconditions()
.limit()
Returns theValue
controlling the maximum number of rows to fetch, a null value means all rows should be fetchedorderBy()
Controls the order by clause to use when selecting the data for this model.query()
AValue
controlling the override query.void
Resets theconditionChanged()
state, using the current condition.where()
Controls the additional WHERE condition, which can be used in conjunction withconditions()
.
-
Method Details
-
entityType
EntityType entityType()- Returns:
- the type of the entity this query model is based on
-
connectionProvider
EntityConnectionProvider connectionProvider()- Returns:
- the connection provider
-
get
Performs a query and returns the result. Note that if a query condition is required (conditionRequired()
) and the condition is not enabled (conditionEnabled()
) an empty list is returned. -
conditions
EntityConditionModel conditions()- Returns:
- the
EntityConditionModel
instance used by this query model
-
where
Controls the additional WHERE condition, which can be used in conjunction withconditions()
. The condition supplier may return null in case of no condition. Note that in order for theconditionChanged()
StateObserver
to indicate a changed condition, the additional condition must be set viaMutable.set(Object)
, changing the return value of the underlyingSupplier
instance does not trigger a changed condition.- Returns:
- the
EntityQueryModel.AdditionalCondition
instance controlling the additional WHERE condition
-
having
EntityQueryModel.AdditionalCondition having()Controls the additional HAVING condition, which can be used in conjunction withconditions()
. The condition supplier may return null in case of no condition. Note that in order for theconditionChanged()
StateObserver
to indicate a changed condition, the additional condition must be set viaMutable.set(Object)
, changing the return value of the underlyingSupplier
instance does not trigger a changed condition.- Returns:
- the
EntityQueryModel.AdditionalCondition
instance controlling the additional HAVING condition
-
conditionRequired
State conditionRequired()Returns aState
controlling whether this query model should query all underlying entities when no query condition has been set. Setting this value to 'true' prevents all rows from being fetched by accident, when no condition has been set, which is recommended for queries with a large underlying dataset.- Returns:
- a
State
controlling whether this query model requires a query condition - See Also:
-
conditionChanged
StateObserver conditionChanged()When using the default query mechanism, theconditionChanged()
state is reset after each successful query.- Returns:
- a
StateObserver
indicating if the search condition has changed since last reset - See Also:
-
resetConditionChanged
void resetConditionChanged()Resets theconditionChanged()
state, using the current condition. -
attributes
Returns theValueSet
controlling which attributes are included when querying entities. Note that an emptyValueSet
indicates that the default select attributes should be used.- Returns:
- the
ValueSet
controlling the selected attributes
-
limit
Returns theValue
controlling the maximum number of rows to fetch, a null value means all rows should be fetched- Returns:
- the
Value
controlling the query limit
-
orderBy
Controls the order by clause to use when selecting the data for this model. Setting this value to null reverts back to the default order by for the underlying entity, if one has been specified- Returns:
- the
Value
controlling the order by clause - See Also:
-
conditionEnabled
Value<StateObserver> conditionEnabled()It can be necessary to prevent the user from selecting too much data, when working with a large dataset. This can be done by enabling theconditionRequired()
State
, which prevents a refresh as long as theStateObserver
controlled via this method is disabled. The defaultStateObserver
is simplyTableConditionModel.enabled()
. Override for a more fine grained control, such as requiring a specific column condition to be enabled.- Returns:
- the
Value
controlling theStateObserver
specifying if enough conditions are enabled for a safe refresh - See Also:
-
query
Value<Function<EntityQueryModel,List<Entity>>> query()AValue
controlling the override query. Use this to replace the default query.- Returns:
- the
Value
controlling the query override
-
entityQueryModel
- Parameters:
entityConditionModel
- theEntityConditionModel
- Returns:
- a new
EntityQueryModel
instance based on the givenEntityConditionModel
-