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

  • 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.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.observer.Observer<?>
     
    final is.codion.common.observer.Observer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>
     
    final is.codion.common.observer.Observer<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 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 is.codion.framework.domain.entity.Entities
     
    Returns a EntityEditModel.EditableEntity wrapping the entity being edited.
    final is.codion.framework.domain.entity.EntityDefinition
     
    final is.codion.framework.domain.entity.EntityType
     
    foreignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
     
    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.
    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 is.codion.common.state.State
     
    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
    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 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.
    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 void
    validate(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
    Validates the value associated with the given attribute, using the underlying validator.
    final 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.
    value(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Returns the EntityEditModel.EditableValue instance representing attribute in this edit model.

    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
    • 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:
    • 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
    • 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 EntityEditModel.EditableEntity entity()
      Description copied from interface: EntityEditModel
      Returns a EntityEditModel.EditableEntity wrapping the entity being edited. Observable.get() returns an immutable copy of the Entity instance being edited, while Mutable.set(Object) copies the values from the given Entity into the underlying Entity. Note that value changes must go through the EntityEditModel.EditableValue accessible via EntityEditModel.value(Attribute).
      Specified by:
      entity in interface EntityEditModel
      Returns:
      the EntityEditModel.EditableEntity wrapping the Entity instance being edited
      See Also:
      • Entity.immutable()
    • value

      public final <T> EntityEditModel.EditableValue<T> value(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Description copied from interface: EntityEditModel
      Returns the EntityEditModel.EditableValue instance representing attribute in this edit model.
      Specified by:
      value in interface EntityEditModel
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the EntityEditModel.EditableValue representing the given attribute
    • validate

      public final void validate(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      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
    • validate

      public final void validate(Collection<is.codion.framework.domain.entity.Entity> entities)
      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
      See Also:
      • EntityDefinition.validator()
    • validate

      public final void validate(is.codion.framework.domain.entity.Entity entity)
      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
    • insert

      public final is.codion.framework.domain.entity.Entity insert()
      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
      See Also:
      • EntityValidator.validate(Entity)
    • insert

      public final Collection<is.codion.framework.domain.entity.Entity> insert(Collection<is.codion.framework.domain.entity.Entity> entities)
      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
      See Also:
    • update

      public final is.codion.framework.domain.entity.Entity update()
      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
      See Also:
      • EntityValidator.validate(Entity)
    • update

      public final Collection<is.codion.framework.domain.entity.Entity> update(Collection<is.codion.framework.domain.entity.Entity> entities)
      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
      See Also:
    • delete

      public final is.codion.framework.domain.entity.Entity delete()
      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
      See Also:
    • delete

      public final Collection<is.codion.framework.domain.entity.Entity> delete(Collection<is.codion.framework.domain.entity.Entity> entities)
      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
      See Also:
    • createInsert

      public final EntityEditModel.Insert createInsert()
      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
    • createInsert

      public final EntityEditModel.Insert createInsert(Collection<is.codion.framework.domain.entity.Entity> entities)
      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
    • createUpdate

      public final EntityEditModel.Update createUpdate()
      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
    • createUpdate

      public final EntityEditModel.Update createUpdate(Collection<is.codion.framework.domain.entity.Entity> entities)
      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
    • 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
    • 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.
    • beforeInsert

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

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

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

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

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

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

      public final is.codion.common.observer.Observer<?> afterInsertUpdateOrDelete()
      Specified by:
      afterInsertUpdateOrDelete in interface EntityEditModel
      Returns:
      an observer notified each time one or more entities have been inserted, updated 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)
      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)
      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)
      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
    • 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: