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
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSpecifies an additional condition supplier. -
Method Summary
Modifier and TypeMethodDescriptionis.codion.common.value.ValueSet<is.codion.framework.domain.entity.attribute.Attribute<?>>Returns theValueSetcontrolling which attributes are included when querying entities.is.codion.common.state.StateObserverWhen using the default query mechanism, theconditionChanged()state is reset after each successful query.is.codion.common.value.Value<is.codion.common.state.StateObserver>It can be necessary to prevent the user from selecting too much data, when working with a large dataset.is.codion.common.state.StateReturns aStatecontrolling whether this query model should query all underlying entities when no query condition has been set.is.codion.framework.db.EntityConnectionProviderstatic EntityQueryModelentityQueryModel(EntityConditionModel entityConditionModel) is.codion.framework.domain.entity.EntityTypeList<is.codion.framework.domain.entity.Entity>get()Performs a query and returns the result.having()Controls the additional HAVING condition, which can be used in conjunction withconditions().is.codion.common.value.Value<Integer>limit()Returns theValuecontrolling the maximum number of rows to fetch, a null value means all rows should be fetchedis.codion.common.value.Value<is.codion.framework.domain.entity.OrderBy>orderBy()Controls the order by clause to use when selecting the data for this model.is.codion.common.value.Value<Function<EntityQueryModel,List<is.codion.framework.domain.entity.Entity>>> query()AValuecontrolling the override query.voidResets theconditionChanged()state, using the current condition.where()Controls the additional WHERE condition, which can be used in conjunction withconditions().
-
Method Details
-
entityType
is.codion.framework.domain.entity.EntityType entityType()- Returns:
- the type of the entity this query model is based on
-
connectionProvider
is.codion.framework.db.EntityConnectionProvider connectionProvider()- Returns:
- the connection provider
-
get
List<is.codion.framework.domain.entity.Entity> 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
EntityConditionModelinstance 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()StateObserverto indicate a changed condition, the additional condition must be set viaMutable.set(Object), changing the return value of the underlyingSupplierinstance does not trigger a changed condition.- Returns:
- the
EntityQueryModel.AdditionalConditioninstance 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()StateObserverto indicate a changed condition, the additional condition must be set viaMutable.set(Object), changing the return value of the underlyingSupplierinstance does not trigger a changed condition.- Returns:
- the
EntityQueryModel.AdditionalConditioninstance controlling the additional HAVING condition
-
conditionRequired
is.codion.common.state.State conditionRequired()Returns aStatecontrolling 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
Statecontrolling whether this query model requires a query condition - See Also:
-
conditionChanged
is.codion.common.state.StateObserver conditionChanged()When using the default query mechanism, theconditionChanged()state is reset after each successful query.- Returns:
- a
StateObserverindicating if the search condition has changed since last reset - See Also:
-
resetConditionChanged
void resetConditionChanged()Resets theconditionChanged()state, using the current condition. -
attributes
is.codion.common.value.ValueSet<is.codion.framework.domain.entity.attribute.Attribute<?>> attributes()Returns theValueSetcontrolling which attributes are included when querying entities. Note that an emptyValueSetindicates that the default select attributes should be used.- Returns:
- the
ValueSetcontrolling the selected attributes
-
limit
is.codion.common.value.Value<Integer> limit()Returns theValuecontrolling the maximum number of rows to fetch, a null value means all rows should be fetched- Returns:
- the
Valuecontrolling the query limit
-
orderBy
is.codion.common.value.Value<is.codion.framework.domain.entity.OrderBy> 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
Valuecontrolling the order by clause - See Also:
-
EntityDefinition.orderBy()
-
conditionEnabled
is.codion.common.value.Value<is.codion.common.state.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 theStateObservercontrolled via this method is disabled. The defaultStateObserveris simplyTableConditionModel.enabled(). Override for a more fine grained control, such as requiring a specific column condition to be enabled.- Returns:
- the
Valuecontrolling theStateObserverspecifying if enough conditions are enabled for a safe refresh - See Also:
-
query
is.codion.common.value.Value<Function<EntityQueryModel,List<is.codion.framework.domain.entity.Entity>>> query()AValuecontrolling the override query. Use this to replace the default query.- Returns:
- the
Valuecontrolling the query override
-
entityQueryModel
- Parameters:
entityConditionModel- theEntityConditionModel- Returns:
- a new
EntityQueryModelinstance based on the givenEntityConditionModel
-