Interface EntityEditModel

All Known Implementing Classes:
AbstractEntityEditModel

public interface EntityEditModel
Specifies a class for editing Entity instances. The underlying attribute values are available via value(Attribute).
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Represents a task for deleting entities.
    static interface 
    Provides access to the active entity being edited.
    static interface 
    Provides access the an Attribute value in the entity being edited.
    static interface 
    Represents a task for inserting entities, split up for use with a background thread.
    static interface 
    Represents a task for updating entities.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final is.codion.common.property.PropertyValue<Boolean>
    Specifies whether foreign key values should persist by default when defaults are set Value type: Boolean Default value: true
    static final is.codion.common.property.PropertyValue<Boolean>
    Specifies whether edit models post their insert, update and delete events to EntityEditEvents Value type: Boolean Default value: true
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities)
    Adds the given entities to all foreign key models based on that entity type
    is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>
     
    is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>
     
    is.codion.common.observer.Observer<?>
     
    is.codion.common.observer.Observer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>>
     
    is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>
     
    is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>
     
    is.codion.common.observer.Observer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>>
     
    is.codion.framework.db.EntityConnection
    Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.
    is.codion.framework.db.EntityConnectionProvider
     
    Creates a new EntityEditModel.Delete instance for deleting the active entity.
    createDelete(Collection<is.codion.framework.domain.entity.Entity> entities)
    Creates a new EntityEditModel.Delete instance for deleting the given entities.
    createForeignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
    Creates a EntitySearchModel for looking up entities referenced by the given foreign key, using the search attributes defined for that entity type.
    Creates a new EntityEditModel.Insert instance for inserting the active entity.
    createInsert(Collection<is.codion.framework.domain.entity.Entity> entities)
    Creates a new EntityEditModel.Insert instance for inserting the given entities.
    Creates a new EntityEditModel.Update instance for updating the active entity.
    createUpdate(Collection<is.codion.framework.domain.entity.Entity> entities)
    Creates a new EntityEditModel.Update instance for updating the given entities.
    is.codion.framework.domain.entity.Entity
    Note: This method must be called on the UI thread in case a panel has been based on this model.
    Collection<is.codion.framework.domain.entity.Entity>
    delete(Collection<is.codion.framework.domain.entity.Entity> entities)
    Note: This method must be called on the UI thread in case a panel has been based on this model.
    is.codion.common.state.State
    Disabling delete causes an exception being thrown when deleting.
    is.codion.framework.domain.entity.Entities
     
    Returns a EntityEditModel.EditableEntity wrapping the entity being edited.
    is.codion.framework.domain.entity.EntityDefinition
     
    is.codion.framework.domain.entity.EntityType
     
    foreignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
     
    is.codion.framework.domain.entity.Entity
    Note: This method must be called on the UI thread in case a panel has been based on this model.
    Collection<is.codion.framework.domain.entity.Entity>
    insert(Collection<is.codion.framework.domain.entity.Entity> entities)
    Note: This method must be called on the UI thread in case a panel has been based on this model.
    is.codion.common.state.State
    Disabling insert causes an exception being thrown when inserting.
    is.codion.common.state.State
     
    is.codion.common.state.State
    Making this edit model read-only prevents any changes from being persisted to the database, trying to insert, update or delete will cause an exception being thrown, it does not prevent editing.
    void
    remove(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities)
    Removes the given entities from all foreign key models based on that entity type and clears any foreign key values referencing them.
    void
    replace(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities)
    For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding entity from entities, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.
    is.codion.framework.domain.entity.Entity
    Note: This method must be called on the UI thread in case a panel has been based on this model.
    Collection<is.codion.framework.domain.entity.Entity>
    update(Collection<is.codion.framework.domain.entity.Entity> entities)
    Note: This method must be called on the UI thread in case a panel has been based on this model.
    is.codion.common.state.State
    Disabling update causes an exception being thrown when updating.
    is.codion.common.state.State
    Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.
    void
    validate(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
    Validates the value associated with the given attribute, using the underlying validator.
    void
    validate(is.codion.framework.domain.entity.Entity entity)
    Validates the given entity, using the underlying validator.
    void
    validate(Collection<is.codion.framework.domain.entity.Entity> entities)
    Validates the given entities, using the underlying validator.
    value(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Returns the EntityEditModel.EditableValue instance representing attribute in this edit model.
  • Field Details

  • Method Details

    • entityType

      is.codion.framework.domain.entity.EntityType entityType()
      Returns:
      the type of the entity this edit model is based on
    • connectionProvider

      is.codion.framework.db.EntityConnectionProvider connectionProvider()
      Returns:
      the connection provider used by this edit model
    • connection

      is.codion.framework.db.EntityConnection connection()
      Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.
      Returns:
      the connection used by this edit model
    • entity

      Returns a EntityEditModel.EditableEntity wrapping the entity being edited. Observable.get() returns an immutable copy of the Entity instance being edited, while Mutable.set(Object) copies the values from the given Entity into the underlying Entity. Note that value changes must go through the EntityEditModel.EditableValue accessible via value(Attribute).
      Returns:
      the EntityEditModel.EditableEntity wrapping the Entity instance being edited
      See Also:
      • Entity.immutable()
    • value

      <T> EntityEditModel.EditableValue<T> value(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Returns the EntityEditModel.EditableValue instance representing attribute in this edit model.
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the EntityEditModel.EditableValue representing the given attribute
    • entities

      is.codion.framework.domain.entity.Entities entities()
      Returns:
      the underlying domain entities
    • entityDefinition

      is.codion.framework.domain.entity.EntityDefinition entityDefinition()
      Returns:
      the definition of the underlying entity
    • readOnly

      is.codion.common.state.State readOnly()
      Making this edit model read-only prevents any changes from being persisted to the database, trying to insert, update or delete will cause an exception being thrown, it does not prevent editing. Use insertEnabled(), updateEnabled() and deleteEnabled() to configure the enabled state of those specific actions.
      Returns:
      the State controlling whether this model is read only
    • insertEnabled

      is.codion.common.state.State insertEnabled()
      Disabling insert causes an exception being thrown when inserting.
      Returns:
      the State controlling whether inserting is enabled via this edit model
    • updateEnabled

      is.codion.common.state.State updateEnabled()
      Disabling update causes an exception being thrown when updating.
      Returns:
      the State controlling whether updating is enabled via this edit model
    • updateMultipleEnabled

      is.codion.common.state.State updateMultipleEnabled()
      Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.
      Returns:
      the State controlling whether updating multiple entities is enabled
    • deleteEnabled

      is.codion.common.state.State deleteEnabled()
      Disabling delete causes an exception being thrown when deleting.
      Returns:
      the State controlling whether deleting is enabled via this edit model
    • createForeignKeySearchModel

      EntitySearchModel createForeignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
      Creates a EntitySearchModel for looking up entities referenced by the given foreign key, using the search attributes defined for that entity type.
      Parameters:
      foreignKey - the foreign key for which to create a EntitySearchModel
      Returns:
      a EntitySearchModel for looking up entities of the type referenced by the given foreign key attribute,
      Throws:
      IllegalStateException - in case no searchable attributes can be found for the entity type referenced by the given foreign key
    • foreignKeySearchModel

      EntitySearchModel foreignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
      Parameters:
      foreignKey - the foreign key for which to retrieve the EntitySearchModel
      Returns:
      the EntitySearchModel associated with the foreignKey, if no search model has been initialized for the given foreign key, a new one is created, associated with the foreign key and returned.
    • postEditEvents

      is.codion.common.state.State postEditEvents()
      Returns:
      a state controlling whether this edit model posts insert, update and delete events on the EntityEditEvents event bus.
      See Also:
    • insert

      is.codion.framework.domain.entity.Entity insert()
      Note: This method must be called on the UI thread in case a panel has been based on this model. Performs an insert on the active entity, sets the primary key values of the active entity according to the primary key of the inserted entity
      Returns:
      the inserted entity
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
      IllegalStateException - in case inserting is not enabled
      See Also:
      • EntityValidator.validate(Entity)
    • insert

      Collection<is.codion.framework.domain.entity.Entity> insert(Collection<is.codion.framework.domain.entity.Entity> entities)
      Note: This method must be called on the UI thread in case a panel has been based on this model. Performs an insert on the given entities.
      Parameters:
      entities - the entities to insert
      Returns:
      a list containing the inserted entities
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
      IllegalStateException - in case inserting is not enabled
      See Also:
    • update

      is.codion.framework.domain.entity.Entity update()
      Note: This method must be called on the UI thread in case a panel has been based on this model. Performs an update on the active entity
      Returns:
      the updated entity
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      is.codion.common.db.exception.RecordModifiedException - in case the entity has been modified since it was loaded
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
      IllegalStateException - in case updating is not enabled
      is.codion.common.db.exception.UpdateException - in case the active entity is not modified
      See Also:
      • EntityValidator.validate(Entity)
    • update

      Collection<is.codion.framework.domain.entity.Entity> update(Collection<is.codion.framework.domain.entity.Entity> entities)
      Note: This method must be called on the UI thread in case a panel has been based on this model. Updates the given entities.
      Parameters:
      entities - the entities to update
      Returns:
      the updated entities
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      is.codion.common.db.exception.RecordModifiedException - in case an entity has been modified since it was loaded
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
      IllegalStateException - in case updating is not enabled
      See Also:
    • delete

      is.codion.framework.domain.entity.Entity delete()
      Note: This method must be called on the UI thread in case a panel has been based on this model.
      Returns:
      the deleted entity
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      IllegalStateException - in case deleting is not enabled
      See Also:
    • delete

      Collection<is.codion.framework.domain.entity.Entity> delete(Collection<is.codion.framework.domain.entity.Entity> entities)
      Note: This method must be called on the UI thread in case a panel has been based on this model.
      Parameters:
      entities - the entities to delete
      Returns:
      the deleted entities
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      IllegalStateException - in case deleting is not enabled
      See Also:
    • createInsert

      EntityEditModel.Insert createInsert()
      Creates a new EntityEditModel.Insert instance for inserting the active entity.
      Returns:
      a new EntityEditModel.Insert instance
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
    • createInsert

      EntityEditModel.Insert createInsert(Collection<is.codion.framework.domain.entity.Entity> entities)
      Creates a new EntityEditModel.Insert instance for inserting the given entities.
      Parameters:
      entities - the entities to insert
      Returns:
      a new EntityEditModel.Insert instance
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
    • createUpdate

      EntityEditModel.Update createUpdate()
      Creates a new EntityEditModel.Update instance for updating the active entity.
      Returns:
      a new EntityEditModel.Update instance
      Throws:
      IllegalArgumentException - in case the active entity is unmodified
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
    • createUpdate

      EntityEditModel.Update createUpdate(Collection<is.codion.framework.domain.entity.Entity> entities)
      Creates a new EntityEditModel.Update instance for updating the given entities.
      Parameters:
      entities - the entities to update
      Returns:
      a new EntityEditModel.Update instance
      Throws:
      IllegalArgumentException - in case any of the given entities are unmodified
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
    • createDelete

      EntityEditModel.Delete createDelete()
      Creates a new EntityEditModel.Delete instance for deleting the active entity.
      Returns:
      a new EntityEditModel.Delete instance
    • createDelete

      EntityEditModel.Delete createDelete(Collection<is.codion.framework.domain.entity.Entity> entities)
      Creates a new EntityEditModel.Delete instance for deleting the given entities.
      Parameters:
      entities - the entities to delete
      Returns:
      a new EntityEditModel.Delete instance
    • add

      void add(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities)
      Adds the given entities to all foreign key models based on that entity type
      Parameters:
      foreignKey - the foreign key
      entities - the values
    • remove

      void remove(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities)
      Removes the given entities from all foreign key models based on that entity type and clears any foreign key values referencing them.
      Parameters:
      foreignKey - the foreign key
      entities - the values
    • replace

      void replace(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities)
      For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding entity from entities, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.
      Parameters:
      foreignKey - the foreign key
      entities - the foreign key entities
    • validate

      void validate(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Validates the value associated with the given attribute, using the underlying validator.
      Parameters:
      attribute - the attribute the value is associated with
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - if the given value is not valid for the given attribute
    • validate

      void validate(Collection<is.codion.framework.domain.entity.Entity> entities)
      Validates the given entities, using the underlying validator. For entities of a type other than this edit model is based on, their respective validators are used.
      Parameters:
      entities - the entities to validate
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - on finding the first invalid entity
      See Also:
      • EntityDefinition.validator()
    • validate

      void validate(is.codion.framework.domain.entity.Entity entity)
      Validates the given entity, using the underlying validator. For entities of a type other than this edit model is based on, their respective validators are used.
      Parameters:
      entity - the entity to validate
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case the entity is invalid
      NullPointerException - in case the entity is null
    • beforeInsert

      is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>> beforeInsert()
      Returns:
      an observer notified before an insert is performed
    • afterInsert

      is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>> afterInsert()
      Returns:
      an observer notified after an insert is performed
    • beforeUpdate

      is.codion.common.observer.Observer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> beforeUpdate()
      Returns:
      an observer notified before an update is performed
    • afterUpdate

      is.codion.common.observer.Observer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> afterUpdate()
      Returns:
      an observer notified after an update is performed
    • beforeDelete

      is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>> beforeDelete()
      Returns:
      an observer notified before a delete is performed
    • afterDelete

      is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>> afterDelete()
      Returns:
      an observer notified after a delete is performed
    • afterInsertUpdateOrDelete

      is.codion.common.observer.Observer<?> afterInsertUpdateOrDelete()
      Returns:
      an observer notified each time one or more entities have been inserted, updated or deleted via this model