Interface EntityQueryModel

All Superinterfaces:
Supplier<List<is.codion.framework.domain.entity.Entity>>

public interface EntityQueryModel extends Supplier<List<is.codion.framework.domain.entity.Entity>>
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 Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Specifies an additional condition supplier.
  • Method Summary

    Modifier and Type
    Method
    Description
    is.codion.common.value.ValueSet<is.codion.framework.domain.entity.attribute.Attribute<?>>
    Returns the ValueSet controlling which attributes are included when querying entities.
    is.codion.common.state.StateObserver
    When using the default query mechanism, the conditionChanged() 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.State
    Returns a State controlling whether this query model should query all underlying entities when no query condition has been set.
     
    is.codion.framework.db.EntityConnectionProvider
     
    entityQueryModel(EntityConditionModel entityConditionModel)
     
    is.codion.framework.domain.entity.EntityType
     
    List<is.codion.framework.domain.entity.Entity>
    get()
    Performs a query and returns the result.
    Controls the additional HAVING condition, which can be used in conjunction with conditions().
    is.codion.common.value.Value<Integer>
    Returns the Value controlling the maximum number of rows to fetch, a null value means all rows should be fetched
    is.codion.common.value.Value<is.codion.framework.domain.entity.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>>>
    A Value controlling the override query.
    void
    Resets the conditionChanged() state, using the current condition.
    Controls the additional WHERE condition, which can be used in conjunction with conditions().
  • 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.
      Specified by:
      get in interface Supplier<List<is.codion.framework.domain.entity.Entity>>
      Returns:
      entities selected from the database according to the query condition.
    • conditions

      EntityConditionModel conditions()
      Returns:
      the EntityConditionModel instance used by this query model
    • where

      Controls the additional WHERE condition, which can be used in conjunction with conditions(). The condition supplier may return null in case of no condition. Note that in order for the conditionChanged() StateObserver to indicate a changed condition, the additional condition must be set via Mutable.set(Object), changing the return value of the underlying Supplier instance does not trigger a changed condition.
      Returns:
      the EntityQueryModel.AdditionalCondition instance controlling the additional WHERE condition
    • having

      Controls the additional HAVING condition, which can be used in conjunction with conditions(). The condition supplier may return null in case of no condition. Note that in order for the conditionChanged() StateObserver to indicate a changed condition, the additional condition must be set via Mutable.set(Object), changing the return value of the underlying Supplier instance does not trigger a changed condition.
      Returns:
      the EntityQueryModel.AdditionalCondition instance controlling the additional HAVING condition
    • conditionRequired

      is.codion.common.state.State conditionRequired()
      Returns a State 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

      is.codion.common.state.StateObserver conditionChanged()
      When using the default query mechanism, the conditionChanged() 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 the conditionChanged() state, using the current condition.
    • attributes

      is.codion.common.value.ValueSet<is.codion.framework.domain.entity.attribute.Attribute<?>> attributes()
      Returns the ValueSet controlling which attributes are included when querying entities. Note that an empty ValueSet indicates that the default select attributes should be used.
      Returns:
      the ValueSet controlling the selected attributes
    • limit

      is.codion.common.value.Value<Integer> limit()
      Returns the Value 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

      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 Value controlling 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 the conditionRequired() State, which prevents a refresh as long as the StateObserver controlled via this method is disabled. The default StateObserver is simply TableConditionModel.enabled(). Override for a more fine grained control, such as requiring a specific column condition to be enabled.
      Returns:
      the Value controlling the StateObserver specifying 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()
      A Value controlling the override query. Use this to replace the default query.
      Returns:
      the Value controlling the query override
    • entityQueryModel

      static EntityQueryModel entityQueryModel(EntityConditionModel entityConditionModel)
      Parameters:
      entityConditionModel - the EntityConditionModel
      Returns:
      a new EntityQueryModel instance based on the given EntityConditionModel