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
  • Field Summary

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

    EDIT_EVENTS, PERSIST_FOREIGN_KEYS, WARN_ABOUT_UNSAVED_DATA
  • 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 void
    addAfterDeleteListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
     
    final void
    addAfterInsertListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
     
    final void
    addAfterUpdateListener(Consumer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> listener)
     
    final void
    addBeforeDeleteListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
     
    final void
    addBeforeInsertListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
     
    final void
    addBeforeUpdateListener(Consumer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> listener)
     
    final void
    addConfirmOverwriteListener(Consumer<is.codion.common.state.State> listener)
     
    final <T> void
    addEditListener(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, Consumer<T> listener)
    Adds a listener 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 void
    addEntityListener(Consumer<is.codion.framework.domain.entity.Entity> listener)
    Notified each time the entity is set via EntityEditModel.set(Entity) or EntityEditModel.setDefaults().
    final void
     
    final void
    addValueChangeListener(Consumer<is.codion.framework.domain.entity.attribute.Attribute<?>> listener)
     
    final <T> void
    addValueListener(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, Consumer<T> listener)
    Adds a listener notified each time the value associated with the given attribute changes, either via editing or when the active entity is set.
    final is.codion.framework.db.EntityConnectionProvider
     
    final boolean
    containsSearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
    Returns true if this edit model contains a EntitySearchModel for the given foreign key
    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.
    final void
    Note: This method must be called on the UI thread in case a panel has been based on this model.
    final void
    delete(Collection<? extends 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<? extends 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 is.codion.common.state.State
     
    final is.codion.framework.domain.entity.Entities
     
    final is.codion.framework.domain.entity.Entity
     
    final is.codion.framework.domain.entity.EntityDefinition
     
    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<? extends 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<? extends 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.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
     
    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.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 is.codion.framework.domain.entity.Entity
    referencedEntity(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
    Returns the value associated with the given foreign key.
    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
    removeAfterDeleteListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
    Removes the given listener.
    final void
    removeAfterInsertListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
    Removes the given listener.
    final void
    removeAfterUpdateListener(Consumer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> listener)
    Removes the given listener.
    final void
    removeBeforeDeleteListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
    Removes the given listener.
    final void
    removeBeforeInsertListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
    Removes the given listener.
    final void
    removeBeforeUpdateListener(Consumer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> listener)
    Removes the given listener.
    final void
    removeConfirmOverwriteListener(Consumer<is.codion.common.state.State> listener)
    Removes the given listener.
    final <T> void
    removeEditListener(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, Consumer<T> listener)
    Removes the given listener.
    final void
    removeEntityListener(Consumer<is.codion.framework.domain.entity.Entity> listener)
    Removes the given listener.
    final void
    Removes the given listener.
    final void
    removeValueChangeListener(Consumer<is.codion.framework.domain.entity.attribute.Attribute<?>> listener)
     
    final <T> void
    removeValueListener(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, Consumer<T> listener)
    Removes the given listener.
    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
    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 <T> void
    setDefault(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, Supplier<T> defaultValue)
    Sets the default value supplier for the given attribute.
    final void
    Populates this edit model with default values.
    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<? extends 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<? extends 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<? extends 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.

    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
    • setDefault

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

      public final is.codion.common.state.State overwriteWarning()
      Specified by:
      overwriteWarning in interface EntityEditModel
      Returns:
      a state controlling whether this edit model triggers a warning before overwriting unsaved data
      See Also:
    • editEvents

      public final is.codion.common.state.State editEvents()
      Specified by:
      editEvents 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
    • 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.setDefaults().
      Specified by:
      set in interface EntityEditModel
      Parameters:
      entity - the entity
      See Also:
    • setDefaults

      public final void setDefaults()
      Description copied from interface: EntityEditModel
      Populates this edit model with default values.
      Specified by:
      setDefaults 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
    • 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()
    • referencedEntity

      public final is.codion.framework.domain.entity.Entity referencedEntity(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
      Description copied from interface: EntityEditModel
      Returns the value associated with the given foreign key.
      Specified by:
      referencedEntity in interface EntityEditModel
      Parameters:
      foreignKey - the foreign key
      Returns:
      the foreign key value
    • 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
    • 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<? extends 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<? extends 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<? extends 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 void 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
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      See Also:
    • delete

      public final void delete(Collection<? extends 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
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      See Also:
    • refreshEntity

      public final void refreshEntity()
      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:
      refreshEntity in interface EntityEditModel
    • containsSearchModel

      public final boolean containsSearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
      Description copied from interface: EntityEditModel
      Returns true if this edit model contains a EntitySearchModel for the given foreign key
      Specified by:
      containsSearchModel in interface EntityEditModel
      Parameters:
      foreignKey - the foreign key
      Returns:
      true if a EntitySearchModel has been initialized for the given foreign key
    • 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
    • removeEditListener

      public final <T> void removeEditListener(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, Consumer<T> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeEditListener in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      listener - the listener to remove
    • addEditListener

      public final <T> void addEditListener(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, Consumer<T> listener)
      Description copied from interface: EntityEditModel
      Adds a listener 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:
      addEditListener in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute for which to monitor value edits
      listener - a listener notified each time the value of the given attribute is edited via this model
    • removeValueListener

      public final <T> void removeValueListener(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, Consumer<T> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeValueListener in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute for which to remove the listener
      listener - the listener to remove
    • addValueListener

      public final <T> void addValueListener(is.codion.framework.domain.entity.attribute.Attribute<T> attribute, Consumer<T> listener)
      Description copied from interface: EntityEditModel
      Adds a listener notified each time the value associated with the given attribute changes, either via editing or when the active entity is set.
      Specified by:
      addValueListener in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute for which to monitor value changes
      listener - a listener notified each time the value of the attribute changes
      See Also:
    • removeValueChangeListener

      public final void removeValueChangeListener(Consumer<is.codion.framework.domain.entity.attribute.Attribute<?>> listener)
      Specified by:
      removeValueChangeListener in interface EntityEditModel
      Parameters:
      listener - the listener to remove
    • addValueChangeListener

      public final void addValueChangeListener(Consumer<is.codion.framework.domain.entity.attribute.Attribute<?>> listener)
      Specified by:
      addValueChangeListener in interface EntityEditModel
      Parameters:
      listener - a listener notified each time a value changes, providing the attribute
    • removeEntityListener

      public final void removeEntityListener(Consumer<is.codion.framework.domain.entity.Entity> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeEntityListener in interface EntityEditModel
      Parameters:
      listener - the listener to remove
    • addEntityListener

      public final void addEntityListener(Consumer<is.codion.framework.domain.entity.Entity> listener)
      Description copied from interface: EntityEditModel
      Notified each time the entity is set via EntityEditModel.set(Entity) or EntityEditModel.setDefaults().
      Specified by:
      addEntityListener in interface EntityEditModel
      Parameters:
      listener - a listener notified each time the entity is set, possibly to null
      See Also:
    • removeBeforeInsertListener

      public final void removeBeforeInsertListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeBeforeInsertListener in interface EntityEditModel
      Parameters:
      listener - a listener to remove
    • addBeforeInsertListener

      public final void addBeforeInsertListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
      Specified by:
      addBeforeInsertListener in interface EntityEditModel
      Parameters:
      listener - a listener to be notified before an insert is performed
    • removeAfterInsertListener

      public final void removeAfterInsertListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeAfterInsertListener in interface EntityEditModel
      Parameters:
      listener - a listener to remove
    • addAfterInsertListener

      public final void addAfterInsertListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
      Specified by:
      addAfterInsertListener in interface EntityEditModel
      Parameters:
      listener - a listener to be notified each time insert has been performed
    • removeBeforeUpdateListener

      public final void removeBeforeUpdateListener(Consumer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeBeforeUpdateListener in interface EntityEditModel
      Parameters:
      listener - a listener to remove
    • addBeforeUpdateListener

      public final void addBeforeUpdateListener(Consumer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> listener)
      Specified by:
      addBeforeUpdateListener in interface EntityEditModel
      Parameters:
      listener - a listener to be notified before an update is performed
    • removeAfterUpdateListener

      public final void removeAfterUpdateListener(Consumer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeAfterUpdateListener in interface EntityEditModel
      Parameters:
      listener - a listener to remove
    • addAfterUpdateListener

      public final void addAfterUpdateListener(Consumer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> listener)
      Specified by:
      addAfterUpdateListener in interface EntityEditModel
      Parameters:
      listener - a listener to be notified each time an update has been performed, with the updated entities, mapped to their respective original primary keys, that is, the primary keys before the update was performed
    • addBeforeDeleteListener

      public final void addBeforeDeleteListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
      Specified by:
      addBeforeDeleteListener in interface EntityEditModel
      Parameters:
      listener - a listener to be notified before a delete is performed
    • removeBeforeDeleteListener

      public final void removeBeforeDeleteListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeBeforeDeleteListener in interface EntityEditModel
      Parameters:
      listener - a listener to remove
    • removeAfterDeleteListener

      public final void removeAfterDeleteListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeAfterDeleteListener in interface EntityEditModel
      Parameters:
      listener - a listener to remove
    • addAfterDeleteListener

      public final void addAfterDeleteListener(Consumer<Collection<is.codion.framework.domain.entity.Entity>> listener)
      Specified by:
      addAfterDeleteListener in interface EntityEditModel
      Parameters:
      listener - a listener to be notified each time delete has been performed
    • removeInsertUpdateOrDeleteListener

      public final void removeInsertUpdateOrDeleteListener(Runnable listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeInsertUpdateOrDeleteListener in interface EntityEditModel
      Parameters:
      listener - a listener to remove
    • addInsertUpdateOrDeleteListener

      public final void addInsertUpdateOrDeleteListener(Runnable listener)
      Specified by:
      addInsertUpdateOrDeleteListener in interface EntityEditModel
      Parameters:
      listener - a listener notified each time one or more entities are updated, inserted or deleted via this model
    • addConfirmOverwriteListener

      public final void addConfirmOverwriteListener(Consumer<is.codion.common.state.State> listener)
      Specified by:
      addConfirmOverwriteListener in interface EntityEditModel
      Parameters:
      listener - a listener notified each time the active entity is about to be set
    • removeConfirmOverwriteListener

      public final void removeConfirmOverwriteListener(Consumer<is.codion.common.state.State> listener)
      Description copied from interface: EntityEditModel
      Removes the given listener.
      Specified by:
      removeConfirmOverwriteListener in interface EntityEditModel
      Parameters:
      listener - a listener to remove
    • insert

      protected Collection<is.codion.framework.domain.entity.Entity> insert(Collection<? extends 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<? extends 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<? extends 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: