Class AbstractEntityEditModel

java.lang.Object
is.codion.framework.model.AbstractEntityEditModel
All Implemented Interfaces:
EntityEditModel

public abstract class AbstractEntityEditModel extends Object implements EntityEditModel
A default EntityEditModel implementation
  • Nested Class Summary

    Nested classes/interfaces inherited from interface is.codion.framework.model.EntityEditModel

    EntityEditModel.Delete, EntityEditModel.Insert, EntityEditModel.Update
  • Field Summary

    Fields inherited from interface is.codion.framework.model.EntityEditModel

    PERSIST_FOREIGN_KEYS, POST_EDIT_EVENTS
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractEntityEditModel(is.codion.framework.domain.entity.EntityType entityType, is.codion.framework.db.EntityConnectionProvider connectionProvider)
    Instantiates a new AbstractEntityEditModel based on the given entity type.
  • Method Summary

    Modifier and Type
    Method
    Description
    final is.codion.common.event.EventObserver<Collection<is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.event.EventObserver<Collection<is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.event.EventObserver<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.event.EventObserver<Collection<is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.event.EventObserver<is.codion.framework.domain.entity.Entity>
     
    final is.codion.common.event.EventObserver<Collection<is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.event.EventObserver<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>>
     
    final 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.
    final 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.
    final void
    Populates this edit model with default values for all attributes.
    final <S extends Supplier<T>, T>
    is.codion.common.value.Value<S>
    defaultValue(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Returns the Value instance controlling the default value supplier for the given attribute.
    final 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.
    final 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.
    protected void
    delete(Collection<is.codion.framework.domain.entity.Entity> entities, is.codion.framework.db.EntityConnection connection)
    Deletes the given entities from the database using the given connection
    final is.codion.common.state.State
    Disabling delete causes an exception being thrown when deleting.
    final <T> is.codion.common.event.EventObserver<T>
    editEvent(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Returns an observer notified each time the value associated with the given attribute is edited via EntityEditModel.put(Attribute, Object) or EntityEditModel.remove(Attribute), note that this event is only fired if the value actually changes.
    final is.codion.common.state.StateObserver
     
    final is.codion.framework.domain.entity.Entities
     
    final is.codion.framework.domain.entity.Entity
     
    final is.codion.framework.domain.entity.EntityDefinition
     
    final is.codion.common.event.EventObserver<is.codion.framework.domain.entity.Entity>
     
    final is.codion.framework.domain.entity.EntityType
     
    final is.codion.common.state.StateObserver
     
    protected final is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>>
    Controls the 'exists' predicate for this edit model, which is responsible for providing the exists state of the underlying entity.
    foreignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
     
    final <T> T
    get(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Returns the value associated with the given attribute
    final 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.
    final 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.
    protected Collection<is.codion.framework.domain.entity.Entity>
    insert(Collection<is.codion.framework.domain.entity.Entity> entities, is.codion.framework.db.EntityConnection connection)
    Inserts the given entities into the database using the given connection
    final is.codion.common.state.State
    Disabling insert causes an exception being thrown when inserting.
    final is.codion.common.event.EventObserver<?>
     
    final is.codion.common.state.StateObserver
    isNotNull(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
     
    final is.codion.common.state.StateObserver
    isNull(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
     
    final is.codion.common.state.StateObserver
    Returns a StateObserver indicating when and if any values in the underlying Entity have been modified.
    final is.codion.common.state.StateObserver
    modified(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
    Returns a StateObserver instance indicating whether the value of the given attribute has been modified.
    protected final is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>>
    Controls the 'modified' predicate for this edit model, which is responsible for providing the modified state of the underlying entity.
    protected final void
    notifyAfterDelete(Collection<is.codion.framework.domain.entity.Entity> deletedEntities)
    Notifies that delete has been performed
    protected final void
    notifyAfterInsert(Collection<is.codion.framework.domain.entity.Entity> insertedEntities)
    Notifies that insert has been performed
    protected final void
    notifyAfterUpdate(Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity> updatedEntities)
    Notifies that update has been performed
    protected final void
    notifyBeforeDelete(Collection<is.codion.framework.domain.entity.Entity> entitiesToDelete)
    Notifies that delete is about to be performed
    protected final void
    notifyBeforeInsert(Collection<is.codion.framework.domain.entity.Entity> entitiesToInsert)
    Notifies that insert is about to be performed
    protected final void
    notifyBeforeUpdate(Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity> entitiesToUpdate)
    Notifies that update is about to be performed
    final boolean
    nullable(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
     
    final <T> Optional<T>
    optional(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Returns the value associated with the given attribute
    final is.codion.common.state.State
    persist(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
    Returns a State controlling whether the last used value for this attribute should persist when the model is cleared.
    final is.codion.common.state.State
     
    final is.codion.common.state.StateObserver
     
    final <T> T
    put(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, T value)
    Sets the given value in the underlying Entity
    final 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.
    final void
    Refreshes the active Entity from the database, discarding all changes.
    final <T> T
    remove(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Removes the given value from the underlying Entity
    final 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.
    protected void
    replaceForeignKey(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> values)
    For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding entity from values, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.
    final void
    Reverts all attribute value changes.
    final <T> void
    revert(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
     
    final void
    set(is.codion.framework.domain.entity.Entity entity)
    Copies the values from the given Entity into the underlying Entity being edited by this edit model.
    final String
     
    final 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.
    final 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.
    protected Collection<is.codion.framework.domain.entity.Entity>
    update(Collection<is.codion.framework.domain.entity.Entity> entities, is.codion.framework.db.EntityConnection connection)
    Updates the given entities in the database using the given connection
    final is.codion.common.state.State
    Disabling update causes an exception being thrown when updating.
    protected final void
    Updates the modified state.
    final is.codion.common.state.State
    Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.
    final is.codion.common.state.StateObserver
     
    final is.codion.common.state.StateObserver
    valid(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
     
    final void
    Validates the current state of the entity
    final 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.
    final void
    validate(Collection<is.codion.framework.domain.entity.Entity> entities)
    Validates the given entities, using the underlying validator.
    protected final is.codion.common.value.Value<is.codion.framework.domain.entity.EntityValidator>
    Controls the validator used by this edit model.
    final <T> is.codion.common.value.Value<T>
    value(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Returns a Value based on attribute in this edit model, note that subsequent calls for the same attribute return the same value instance.
    final is.codion.common.event.EventObserver<is.codion.framework.domain.entity.attribute.Attribute<?>>
     
    final <T> is.codion.common.event.EventObserver<T>
    valueEvent(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Returns an observer notified each time the value associated with the given attribute changes, either via editing or when the active entity is set.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface is.codion.framework.model.EntityEditModel

    add, remove
  • Constructor Details

    • AbstractEntityEditModel

      protected AbstractEntityEditModel(is.codion.framework.domain.entity.EntityType entityType, is.codion.framework.db.EntityConnectionProvider connectionProvider)
      Instantiates a new AbstractEntityEditModel based on the given entity type.
      Parameters:
      entityType - the type of the entity to base this AbstractEntityEditModel on
      connectionProvider - the EntityConnectionProvider instance
  • Method Details

    • entities

      public final is.codion.framework.domain.entity.Entities entities()
      Specified by:
      entities in interface EntityEditModel
      Returns:
      the underlying domain entities
    • entityDefinition

      public final is.codion.framework.domain.entity.EntityDefinition entityDefinition()
      Specified by:
      entityDefinition in interface EntityEditModel
      Returns:
      the definition of the underlying entity
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • defaultValue

      public final <S extends Supplier<T>, T> is.codion.common.value.Value<S> defaultValue(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Description copied from interface: EntityEditModel
      Returns the Value instance controlling the default value supplier for the given attribute. Used when the underlying value is not persistent. Use EntityEditModel.defaults() or EntityEditModel.set(Entity) with a null parameter to populate the model with the default values.
      Specified by:
      defaultValue in interface EntityEditModel
      Type Parameters:
      S - the value supplier type
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the Value instance controlling the default value supplier
      See Also:
    • postEditEvents

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

      public final is.codion.common.state.State persist(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Description copied from interface: EntityEditModel
      Returns a State controlling whether the last used value for this attribute should persist when the model is cleared.
      Specified by:
      persist in interface EntityEditModel
      Parameters:
      attribute - the attribute
      Returns:
      a State controlling whether the given attribute value should persist when the model is cleared
      See Also:
    • readOnly

      public final is.codion.common.state.State readOnly()
      Description copied from interface: EntityEditModel
      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 EntityEditModel.insertEnabled(), EntityEditModel.updateEnabled() and EntityEditModel.deleteEnabled() to configure the enabled state of those specific actions.
      Specified by:
      readOnly in interface EntityEditModel
      Returns:
      the State controlling whether this model is read only
    • insertEnabled

      public final is.codion.common.state.State insertEnabled()
      Description copied from interface: EntityEditModel
      Disabling insert causes an exception being thrown when inserting.
      Specified by:
      insertEnabled in interface EntityEditModel
      Returns:
      the state controlling whether inserting is enabled via this edit model
    • updateEnabled

      public final is.codion.common.state.State updateEnabled()
      Description copied from interface: EntityEditModel
      Disabling update causes an exception being thrown when updating.
      Specified by:
      updateEnabled in interface EntityEditModel
      Returns:
      the state controlling whether updating is enabled via this edit model
    • updateMultipleEnabled

      public final is.codion.common.state.State updateMultipleEnabled()
      Description copied from interface: EntityEditModel
      Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.
      Specified by:
      updateMultipleEnabled in interface EntityEditModel
      Returns:
      the state controlling whether updating multiple entities is enabled
    • deleteEnabled

      public final is.codion.common.state.State deleteEnabled()
      Description copied from interface: EntityEditModel
      Disabling delete causes an exception being thrown when deleting.
      Specified by:
      deleteEnabled in interface EntityEditModel
      Returns:
      the state controlling whether deleting is enabled via this edit model
    • exists

      public final is.codion.common.state.StateObserver exists()
      Specified by:
      exists in interface EntityEditModel
      Returns:
      a StateObserver indicating whether the active entity exists in the database
    • editing

      public final is.codion.common.state.StateObserver editing()
      Specified by:
      editing in interface EntityEditModel
      Returns:
      a StateObserver indicating whether the active entity exists and is modified
      See Also:
    • primaryKeyNull

      public final is.codion.common.state.StateObserver primaryKeyNull()
      Specified by:
      primaryKeyNull in interface EntityEditModel
      Returns:
      a StateObserver indicating whether the primary key of the active entity is null
    • set

      public final void set(is.codion.framework.domain.entity.Entity entity)
      Description copied from interface: EntityEditModel
      Copies the values from the given Entity into the underlying Entity being edited by this edit model. If entity is null the effect is the same as calling EntityEditModel.defaults().
      Specified by:
      set in interface EntityEditModel
      Parameters:
      entity - the entity
      See Also:
    • defaults

      public final void defaults()
      Description copied from interface: EntityEditModel
      Populates this edit model with default values for all attributes.
      Specified by:
      defaults in interface EntityEditModel
      See Also:
    • entityType

      public final is.codion.framework.domain.entity.EntityType entityType()
      Specified by:
      entityType in interface EntityEditModel
      Returns:
      the type of the entity this edit model is based on
    • connectionProvider

      public final is.codion.framework.db.EntityConnectionProvider connectionProvider()
      Specified by:
      connectionProvider in interface EntityEditModel
      Returns:
      the connection provider used by this edit model
    • connection

      public final is.codion.framework.db.EntityConnection connection()
      Description copied from interface: EntityEditModel
      Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.
      Specified by:
      connection in interface EntityEditModel
      Returns:
      the connection used by this edit model
    • replace

      public final void replace(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities)
      Description copied from interface: EntityEditModel
      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.
      Specified by:
      replace in interface EntityEditModel
      Parameters:
      foreignKey - the foreign key
      entities - the foreign key entities
    • entity

      public final is.codion.framework.domain.entity.Entity entity()
      Specified by:
      entity in interface EntityEditModel
      Returns:
      an immutable version of the Entity instance being edited
      See Also:
      • Entity.immutable()
    • modified

      public final is.codion.common.state.StateObserver modified()
      Description copied from interface: EntityEditModel
      Returns a StateObserver indicating when and if any values in the underlying Entity have been modified.
      Specified by:
      modified in interface EntityEditModel
      Returns:
      a StateObserver indicating the modified state of this edit model
    • modified

      public final is.codion.common.state.StateObserver modified(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Description copied from interface: EntityEditModel
      Returns a StateObserver instance indicating whether the value of the given attribute has been modified.
      Specified by:
      modified in interface EntityEditModel
      Parameters:
      attribute - the attribute
      Returns:
      a StateObserver indicating the modified state of the value of the given attribute
      See Also:
    • get

      public final <T> T get(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Description copied from interface: EntityEditModel
      Returns the value associated with the given attribute
      Specified by:
      get in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the value associated with the given attribute
    • optional

      public final <T> Optional<T> optional(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Description copied from interface: EntityEditModel
      Returns the value associated with the given attribute
      Specified by:
      optional in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the value associated with the given attribute, an empty Optional in case it is null
    • put

      public final <T> T put(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, T value)
      Description copied from interface: EntityEditModel
      Sets the given value in the underlying Entity
      Specified by:
      put in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute to associate the given value with
      value - the value to associate with the given attribute
      Returns:
      the previous value, if any
    • remove

      public final <T> T remove(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Description copied from interface: EntityEditModel
      Removes the given value from the underlying Entity
      Specified by:
      remove in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the value, if any
    • revert

      public final void revert()
      Description copied from interface: EntityEditModel
      Reverts all attribute value changes.
      Specified by:
      revert in interface EntityEditModel
    • revert

      public final <T> void revert(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Specified by:
      revert in interface EntityEditModel
      Parameters:
      attribute - the attribute to revert
    • nullable

      public final boolean nullable(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Specified by:
      nullable in interface EntityEditModel
      Parameters:
      attribute - the attribute
      Returns:
      true if this value is allowed to be null in the underlying entity
    • isNull

      public final is.codion.common.state.StateObserver isNull(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Specified by:
      isNull in interface EntityEditModel
      Parameters:
      attribute - the attribute
      Returns:
      a StateObserver indicating whether the value of the given attribute is null
    • isNotNull

      public final is.codion.common.state.StateObserver isNotNull(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Specified by:
      isNotNull in interface EntityEditModel
      Parameters:
      attribute - the attribute
      Returns:
      a StateObserver indicating whether the value of the given attribute is not null
    • valid

      public final is.codion.common.state.StateObserver valid()
      Specified by:
      valid in interface EntityEditModel
      Returns:
      a StateObserver indicating the valid status of the underlying Entity.
      See Also:
    • valid

      public final is.codion.common.state.StateObserver valid(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Specified by:
      valid in interface EntityEditModel
      Parameters:
      attribute - the attribute
      Returns:
      a StateObserver indicating the valid status of the given attribute.
    • validate

      public final void validate(is.codion.framework.domain.entity.attribute.Attribute<?> attribute) throws is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      Validates the value associated with the given attribute, using the underlying validator.
      Specified by:
      validate in interface EntityEditModel
      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

      public final void validate() throws is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      Validates the current state of the entity
      Specified by:
      validate in interface EntityEditModel
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case the entity is invalid
    • validate

      public final void validate(Collection<is.codion.framework.domain.entity.Entity> entities) throws is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      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.
      Specified by:
      validate in interface EntityEditModel
      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

      public void validate(is.codion.framework.domain.entity.Entity entity) throws is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      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.
      Specified by:
      validate in interface EntityEditModel
      Parameters:
      entity - the entity to validate
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case the entity is invalid
    • insert

      public final is.codion.framework.domain.entity.Entity insert() throws is.codion.common.db.exception.DatabaseException, is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      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
      Specified by:
      insert in interface EntityEditModel
      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
      See Also:
      • EntityValidator.validate(Entity)
    • insert

      public final Collection<is.codion.framework.domain.entity.Entity> insert(Collection<is.codion.framework.domain.entity.Entity> entities) throws is.codion.common.db.exception.DatabaseException, is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      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.
      Specified by:
      insert in interface EntityEditModel
      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
      See Also:
    • update

      public final is.codion.framework.domain.entity.Entity update() throws is.codion.common.db.exception.DatabaseException, is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      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
      Specified by:
      update in interface EntityEditModel
      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.common.db.exception.UpdateException - in case the active entity is not modified
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
      See Also:
      • EntityValidator.validate(Entity)
    • update

      public final Collection<is.codion.framework.domain.entity.Entity> update(Collection<is.codion.framework.domain.entity.Entity> entities) throws is.codion.common.db.exception.DatabaseException, is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      Note: This method must be called on the UI thread in case a panel has been based on this model. Updates the given entities.
      Specified by:
      update in interface EntityEditModel
      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
      See Also:
    • delete

      public final is.codion.framework.domain.entity.Entity delete() throws is.codion.common.db.exception.DatabaseException
      Description copied from interface: EntityEditModel
      Note: This method must be called on the UI thread in case a panel has been based on this model.
      Specified by:
      delete in interface EntityEditModel
      Returns:
      the deleted entity
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      See Also:
    • delete

      public final Collection<is.codion.framework.domain.entity.Entity> delete(Collection<is.codion.framework.domain.entity.Entity> entities) throws is.codion.common.db.exception.DatabaseException
      Description copied from interface: EntityEditModel
      Note: This method must be called on the UI thread in case a panel has been based on this model.
      Specified by:
      delete in interface EntityEditModel
      Parameters:
      entities - the entities to delete
      Returns:
      the deleted entities
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      See Also:
    • createInsert

      public final EntityEditModel.Insert createInsert() throws is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      Creates a new EntityEditModel.Insert instance for inserting the active entity.
      Specified by:
      createInsert in interface EntityEditModel
      Returns:
      a new EntityEditModel.Insert instance
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
    • createInsert

      public final EntityEditModel.Insert createInsert(Collection<is.codion.framework.domain.entity.Entity> entities) throws is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      Creates a new EntityEditModel.Insert instance for inserting the given entities.
      Specified by:
      createInsert in interface EntityEditModel
      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

      public final EntityEditModel.Update createUpdate() throws is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      Creates a new EntityEditModel.Update instance for updating the active entity.
      Specified by:
      createUpdate in interface EntityEditModel
      Returns:
      a new EntityEditModel.Update instance
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
    • createUpdate

      public final EntityEditModel.Update createUpdate(Collection<is.codion.framework.domain.entity.Entity> entities) throws is.codion.framework.domain.entity.exception.ValidationException
      Description copied from interface: EntityEditModel
      Creates a new EntityEditModel.Update instance for updating the given entities.
      Specified by:
      createUpdate in interface EntityEditModel
      Parameters:
      entities - the entities to update
      Returns:
      a new EntityEditModel.Update instance
      Throws:
      is.codion.framework.domain.entity.exception.ValidationException - in case validation fails
    • createDelete

      public final EntityEditModel.Delete createDelete()
      Description copied from interface: EntityEditModel
      Creates a new EntityEditModel.Delete instance for deleting the active entity.
      Specified by:
      createDelete in interface EntityEditModel
      Returns:
      a new EntityEditModel.Delete instance
    • createDelete

      public final EntityEditModel.Delete createDelete(Collection<is.codion.framework.domain.entity.Entity> entities)
      Description copied from interface: EntityEditModel
      Creates a new EntityEditModel.Delete instance for deleting the given entities.
      Specified by:
      createDelete in interface EntityEditModel
      Parameters:
      entities - the entities to delete
      Returns:
      a new EntityEditModel.Delete instance
    • refresh

      public final void refresh()
      Description copied from interface: EntityEditModel
      Refreshes the active Entity from the database, discarding all changes. If the active Entity is new then calling this method has no effect.
      Specified by:
      refresh in interface EntityEditModel
    • createForeignKeySearchModel

      public EntitySearchModel createForeignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
      Description copied from interface: EntityEditModel
      Creates a EntitySearchModel for looking up entities referenced by the given foreign key, using the search attributes defined for that entity type.
      Specified by:
      createForeignKeySearchModel in interface EntityEditModel
      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,
    • foreignKeySearchModel

      public final EntitySearchModel foreignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
      Specified by:
      foreignKeySearchModel in interface EntityEditModel
      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.
    • value

      public final <T> is.codion.common.value.Value<T> value(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Description copied from interface: EntityEditModel
      Returns a Value based on attribute in this edit model, note that subsequent calls for the same attribute return the same value instance.
      Specified by:
      value in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      a Value based on the given edit model value
    • editEvent

      public final <T> is.codion.common.event.EventObserver<T> editEvent(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Description copied from interface: EntityEditModel
      Returns an observer notified each time the value associated with the given attribute is edited via EntityEditModel.put(Attribute, Object) or EntityEditModel.remove(Attribute), note that this event is only fired if the value actually changes.
      Specified by:
      editEvent in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute which edit observer to return
      Returns:
      an observer for the given attribute value edits
    • valueEvent

      public final <T> is.codion.common.event.EventObserver<T> valueEvent(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Description copied from interface: EntityEditModel
      Returns an observer notified each time the value associated with the given attribute changes, either via editing or when the active entity is set.
      Specified by:
      valueEvent in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute which value observer to return
      Returns:
      an observer for the given attribute value changes
      See Also:
    • valueEvent

      public final is.codion.common.event.EventObserver<is.codion.framework.domain.entity.attribute.Attribute<?>> valueEvent()
      Specified by:
      valueEvent in interface EntityEditModel
      Returns:
      an observer for attribute value changes
    • entityEvent

      public final is.codion.common.event.EventObserver<is.codion.framework.domain.entity.Entity> entityEvent()
      Specified by:
      entityEvent in interface EntityEditModel
      Returns:
      an observer notified each time the entity is set via EntityEditModel.set(Entity) or EntityEditModel.defaults().
      See Also:
    • beforeEntityEvent

      public final is.codion.common.event.EventObserver<is.codion.framework.domain.entity.Entity> beforeEntityEvent()
      Specified by:
      beforeEntityEvent in interface EntityEditModel
      Returns:
      an observer notified each time the active entity is about to be set
      See Also:
    • beforeInsertEvent

      public final is.codion.common.event.EventObserver<Collection<is.codion.framework.domain.entity.Entity>> beforeInsertEvent()
      Specified by:
      beforeInsertEvent in interface EntityEditModel
      Returns:
      an observer notified before an insert is performed
    • afterInsertEvent

      public final is.codion.common.event.EventObserver<Collection<is.codion.framework.domain.entity.Entity>> afterInsertEvent()
      Specified by:
      afterInsertEvent in interface EntityEditModel
      Returns:
      an observer notified after an insert is performed
    • beforeUpdateEvent

      public final is.codion.common.event.EventObserver<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> beforeUpdateEvent()
      Specified by:
      beforeUpdateEvent in interface EntityEditModel
      Returns:
      an observer notified before an update is performed
    • afterUpdateEvent

      public final is.codion.common.event.EventObserver<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> afterUpdateEvent()
      Specified by:
      afterUpdateEvent in interface EntityEditModel
      Returns:
      an observer notified after an update is performed
    • beforeDeleteEvent

      public final is.codion.common.event.EventObserver<Collection<is.codion.framework.domain.entity.Entity>> beforeDeleteEvent()
      Specified by:
      beforeDeleteEvent in interface EntityEditModel
      Returns:
      an observer notified before a delete is performed
    • afterDeleteEvent

      public final is.codion.common.event.EventObserver<Collection<is.codion.framework.domain.entity.Entity>> afterDeleteEvent()
      Specified by:
      afterDeleteEvent in interface EntityEditModel
      Returns:
      an observer notified after a delete is performed
    • insertUpdateOrDeleteEvent

      public final is.codion.common.event.EventObserver<?> insertUpdateOrDeleteEvent()
      Specified by:
      insertUpdateOrDeleteEvent in interface EntityEditModel
      Returns:
      an observer notified each time one or more entities are updated, inserted or deleted via this model
    • insert

      protected Collection<is.codion.framework.domain.entity.Entity> insert(Collection<is.codion.framework.domain.entity.Entity> entities, is.codion.framework.db.EntityConnection connection) throws is.codion.common.db.exception.DatabaseException
      Inserts the given entities into the database using the given connection
      Parameters:
      entities - the entities to insert
      connection - the connection to use
      Returns:
      the inserted entities
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
    • update

      protected Collection<is.codion.framework.domain.entity.Entity> update(Collection<is.codion.framework.domain.entity.Entity> entities, is.codion.framework.db.EntityConnection connection) throws is.codion.common.db.exception.DatabaseException
      Updates the given entities in the database using the given connection
      Parameters:
      entities - the entities to update
      connection - the connection to use
      Returns:
      the updated entities
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
    • delete

      protected void delete(Collection<is.codion.framework.domain.entity.Entity> entities, is.codion.framework.db.EntityConnection connection) throws is.codion.common.db.exception.DatabaseException
      Deletes the given entities from the database using the given connection
      Parameters:
      entities - the entities to delete
      connection - the connection to use
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
    • replaceForeignKey

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

      protected final is.codion.common.value.Value<is.codion.framework.domain.entity.EntityValidator> validator()
      Controls the validator used by this edit model.
      Returns:
      the value controlling the validator
      See Also:
    • modifiedPredicate

      protected final is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>> modifiedPredicate()
      Controls the 'modified' predicate for this edit model, which is responsible for providing the modified state of the underlying entity.
      Returns:
      the value controlling the predicate used to check if the entity is modified
      See Also:
    • existsPredicate

      protected final is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>> existsPredicate()
      Controls the 'exists' predicate for this edit model, which is responsible for providing the exists state of the underlying entity.
      Returns:
      the value controlling the predicate used to check if the entity exists
      See Also:
      • EntityDefinition.exists()
      • Entity.exists()
    • updateModifiedState

      protected final void updateModifiedState()
      Updates the modified state.
      See Also:
    • notifyBeforeInsert

      protected final void notifyBeforeInsert(Collection<is.codion.framework.domain.entity.Entity> entitiesToInsert)
      Notifies that insert is about to be performed
      Parameters:
      entitiesToInsert - the entities about to be inserted
      See Also:
    • notifyAfterInsert

      protected final void notifyAfterInsert(Collection<is.codion.framework.domain.entity.Entity> insertedEntities)
      Notifies that insert has been performed
      Parameters:
      insertedEntities - the inserted entities
      See Also:
    • notifyBeforeUpdate

      protected final void notifyBeforeUpdate(Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity> entitiesToUpdate)
      Notifies that update is about to be performed
      Parameters:
      entitiesToUpdate - the entities about to be updated
      See Also:
    • notifyAfterUpdate

      protected final void notifyAfterUpdate(Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity> updatedEntities)
      Notifies that update has been performed
      Parameters:
      updatedEntities - the updated entities
      See Also:
    • notifyBeforeDelete

      protected final void notifyBeforeDelete(Collection<is.codion.framework.domain.entity.Entity> entitiesToDelete)
      Notifies that delete is about to be performed
      Parameters:
      entitiesToDelete - the entities about to be deleted
      See Also:
    • notifyAfterDelete

      protected final void notifyAfterDelete(Collection<is.codion.framework.domain.entity.Entity> deletedEntities)
      Notifies that delete has been performed
      Parameters:
      deletedEntities - the deleted entities
      See Also: