- All Known Implementing Classes:
AbstractEntityEditModel
public interface EntityEditModel
Specifies a class for editing
Entity instances.
The underlying attribute values are available via value(Attribute).-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents a task for deleting entities.static interfaceProvides access to the active entity being edited.static interfaceProvides access the anAttributevalue in the entity being edited.static interfaceRepresents a task for inserting entities, split up for use with a background thread.static interfaceRepresents a task for updating entities. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final is.codion.common.property.PropertyValue<Boolean>Specifies whether foreign key values should persist by default when defaults are set Value type: Boolean Default value: truestatic final is.codion.common.property.PropertyValue<Boolean>Specifies whether edit models post their insert, update and delete events toEntityEditEventsValue type: Boolean Default value: true -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities) Adds the given entities to all foreign key models based on that entity typeis.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>is.codion.common.observer.Observer<?>is.codion.common.observer.Observer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>>is.codion.common.observer.Observer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> is.codion.framework.db.EntityConnectionDo not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.is.codion.framework.db.EntityConnectionProviderCreates a newEntityEditModel.Deleteinstance for deleting the active entity.createDelete(Collection<is.codion.framework.domain.entity.Entity> entities) Creates a newEntityEditModel.Deleteinstance for deleting the given entities.createForeignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey) Creates aEntitySearchModelfor looking up entities referenced by the given foreign key, using the search attributes defined for that entity type.Creates a newEntityEditModel.Insertinstance for inserting the active entity.createInsert(Collection<is.codion.framework.domain.entity.Entity> entities) Creates a newEntityEditModel.Insertinstance for inserting the given entities.Creates a newEntityEditModel.Updateinstance for updating the active entity.createUpdate(Collection<is.codion.framework.domain.entity.Entity> entities) Creates a newEntityEditModel.Updateinstance for updating the given entities.is.codion.framework.domain.entity.Entitydelete()Note: This method must be called on the UI thread in case a panel has been based on this model.Collection<is.codion.framework.domain.entity.Entity>delete(Collection<is.codion.framework.domain.entity.Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.is.codion.common.state.StateDisabling delete causes an exception being thrown when deleting.is.codion.framework.domain.entity.Entitiesentities()entity()Returns aEntityEditModel.EditableEntitywrapping the entity being edited.is.codion.framework.domain.entity.EntityDefinitionis.codion.framework.domain.entity.EntityTypeforeignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey) is.codion.framework.domain.entity.Entityinsert()Note: This method must be called on the UI thread in case a panel has been based on this model.Collection<is.codion.framework.domain.entity.Entity>insert(Collection<is.codion.framework.domain.entity.Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.is.codion.common.state.StateDisabling insert causes an exception being thrown when inserting.is.codion.common.state.Stateis.codion.common.state.StatereadOnly()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.voidremove(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities) Removes the given entities from all foreign key models based on that entity type and clears any foreign key values referencing them.voidreplace(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 fromentities, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.is.codion.framework.domain.entity.Entityupdate()Note: This method must be called on the UI thread in case a panel has been based on this model.Collection<is.codion.framework.domain.entity.Entity>update(Collection<is.codion.framework.domain.entity.Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.is.codion.common.state.StateDisabling update causes an exception being thrown when updating.is.codion.common.state.StateDisabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.voidvalidate(is.codion.framework.domain.entity.attribute.Attribute<?> attribute) Validates the value associated with the given attribute, using the underlying validator.voidvalidate(is.codion.framework.domain.entity.Entity entity) Validates the given entity, using the underlying validator.voidvalidate(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 theEntityEditModel.EditableValueinstance representingattributein this edit model.
-
Field Details
-
PERSIST_FOREIGN_KEYS
Specifies whether foreign key values should persist by default when defaults are set- Value type: Boolean
- Default value: true
-
POST_EDIT_EVENTS
Specifies whether edit models post their insert, update and delete events toEntityEditEvents- Value type: Boolean
- Default value: true
-
-
Method Details
-
entityType
is.codion.framework.domain.entity.EntityType entityType()- Returns:
- the type of the entity this edit model is based on
-
connectionProvider
is.codion.framework.db.EntityConnectionProvider connectionProvider()- Returns:
- the connection provider used by this edit model
-
connection
is.codion.framework.db.EntityConnection connection()Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.- Returns:
- the connection used by this edit model
-
entity
EntityEditModel.EditableEntity entity()Returns aEntityEditModel.EditableEntitywrapping the entity being edited.Observable.get()returns an immutable copy of theEntityinstance being edited, whileMutable.set(Object)copies the values from the givenEntityinto the underlyingEntity. Note that value changes must go through theEntityEditModel.EditableValueaccessible viavalue(Attribute).- Returns:
- the
EntityEditModel.EditableEntitywrapping theEntityinstance being edited - See Also:
-
Entity.immutable()
-
value
<T> EntityEditModel.EditableValue<T> value(is.codion.framework.domain.entity.attribute.Attribute<T> attribute) Returns theEntityEditModel.EditableValueinstance representingattributein this edit model.- Type Parameters:
T- the value type- Parameters:
attribute- the attribute- Returns:
- the
EntityEditModel.EditableValuerepresenting the given attribute
-
entities
is.codion.framework.domain.entity.Entities entities()- Returns:
- the underlying domain entities
-
entityDefinition
is.codion.framework.domain.entity.EntityDefinition entityDefinition()- Returns:
- the definition of the underlying entity
-
readOnly
is.codion.common.state.State readOnly()Making this edit model read-only prevents any changes from being persisted to the database, trying to insert, update or delete will cause an exception being thrown, it does not prevent editing. UseinsertEnabled(),updateEnabled()anddeleteEnabled()to configure the enabled state of those specific actions.- Returns:
- the
Statecontrolling whether this model is read only
-
insertEnabled
is.codion.common.state.State insertEnabled()Disabling insert causes an exception being thrown when inserting.- Returns:
- the
Statecontrolling whether inserting is enabled via this edit model
-
updateEnabled
is.codion.common.state.State updateEnabled()Disabling update causes an exception being thrown when updating.- Returns:
- the
Statecontrolling whether updating is enabled via this edit model
-
updateMultipleEnabled
is.codion.common.state.State updateMultipleEnabled()Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.- Returns:
- the
Statecontrolling whether updating multiple entities is enabled
-
deleteEnabled
is.codion.common.state.State deleteEnabled()Disabling delete causes an exception being thrown when deleting.- Returns:
- the
Statecontrolling whether deleting is enabled via this edit model
-
createForeignKeySearchModel
EntitySearchModel createForeignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey) Creates aEntitySearchModelfor looking up entities referenced by the given foreign key, using the search attributes defined for that entity type.- Parameters:
foreignKey- the foreign key for which to create aEntitySearchModel- Returns:
- a
EntitySearchModelfor looking up entities of the type referenced by the given foreign key attribute, - Throws:
IllegalStateException- in case no searchable attributes can be found for the entity type referenced by the given foreign key
-
foreignKeySearchModel
EntitySearchModel foreignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey) - Parameters:
foreignKey- the foreign key for which to retrieve theEntitySearchModel- Returns:
- the
EntitySearchModelassociated with theforeignKey, if no search model has been initialized for the given foreign key, a new one is created, associated with the foreign key and returned.
-
postEditEvents
is.codion.common.state.State postEditEvents()- Returns:
- a state controlling whether this edit model posts insert, update and delete events
on the
EntityEditEventsevent bus. - See Also:
-
insert
is.codion.framework.domain.entity.Entity insert()Note: This method must be called on the UI thread in case a panel has been based on this model. Performs an insert on the active entity, sets the primary key values of the active entity according to the primary key of the inserted entity- Returns:
- the inserted entity
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionis.codion.framework.domain.entity.exception.ValidationException- in case validation failsIllegalStateException- in case inserting is not enabled- See Also:
-
EntityValidator.validate(Entity)
-
insert
Collection<is.codion.framework.domain.entity.Entity> insert(Collection<is.codion.framework.domain.entity.Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model. Performs an insert on the given entities.- Parameters:
entities- the entities to insert- Returns:
- a list containing the inserted entities
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionis.codion.framework.domain.entity.exception.ValidationException- in case validation failsIllegalStateException- in case inserting is not enabled- See Also:
-
beforeInsert()afterInsert()EntityValidator.validate(Entity)
-
update
is.codion.framework.domain.entity.Entity update()Note: This method must be called on the UI thread in case a panel has been based on this model. Performs an update on the active entity- Returns:
- the updated entity
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionis.codion.common.db.exception.RecordModifiedException- in case the entity has been modified since it was loadedis.codion.framework.domain.entity.exception.ValidationException- in case validation failsIllegalStateException- in case updating is not enabledis.codion.common.db.exception.UpdateException- in case the active entity is not modified- See Also:
-
EntityValidator.validate(Entity)
-
update
Collection<is.codion.framework.domain.entity.Entity> update(Collection<is.codion.framework.domain.entity.Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model. Updates the given entities.- Parameters:
entities- the entities to update- Returns:
- the updated entities
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionis.codion.common.db.exception.RecordModifiedException- in case an entity has been modified since it was loadedis.codion.framework.domain.entity.exception.ValidationException- in case validation failsIllegalStateException- in case updating is not enabled- See Also:
-
beforeUpdate()afterUpdate()EntityValidator.validate(Entity)
-
delete
is.codion.framework.domain.entity.Entity delete()Note: This method must be called on the UI thread in case a panel has been based on this model.- Returns:
- the deleted entity
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionIllegalStateException- in case deleting is not enabled- See Also:
-
delete
Collection<is.codion.framework.domain.entity.Entity> delete(Collection<is.codion.framework.domain.entity.Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.- Parameters:
entities- the entities to delete- Returns:
- the deleted entities
- Throws:
is.codion.common.db.exception.DatabaseException- in case of a database exceptionIllegalStateException- in case deleting is not enabled- See Also:
-
createInsert
EntityEditModel.Insert createInsert()Creates a newEntityEditModel.Insertinstance for inserting the active entity.- Returns:
- a new
EntityEditModel.Insertinstance - Throws:
is.codion.framework.domain.entity.exception.ValidationException- in case validation fails
-
createInsert
Creates a newEntityEditModel.Insertinstance for inserting the given entities.- Parameters:
entities- the entities to insert- Returns:
- a new
EntityEditModel.Insertinstance - Throws:
is.codion.framework.domain.entity.exception.ValidationException- in case validation fails
-
createUpdate
EntityEditModel.Update createUpdate()Creates a newEntityEditModel.Updateinstance for updating the active entity.- Returns:
- a new
EntityEditModel.Updateinstance - Throws:
IllegalArgumentException- in case the active entity is unmodifiedis.codion.framework.domain.entity.exception.ValidationException- in case validation fails
-
createUpdate
Creates a newEntityEditModel.Updateinstance for updating the given entities.- Parameters:
entities- the entities to update- Returns:
- a new
EntityEditModel.Updateinstance - Throws:
IllegalArgumentException- in case any of the given entities are unmodifiedis.codion.framework.domain.entity.exception.ValidationException- in case validation fails
-
createDelete
EntityEditModel.Delete createDelete()Creates a newEntityEditModel.Deleteinstance for deleting the active entity.- Returns:
- a new
EntityEditModel.Deleteinstance
-
createDelete
Creates a newEntityEditModel.Deleteinstance for deleting the given entities.- Parameters:
entities- the entities to delete- Returns:
- a new
EntityEditModel.Deleteinstance
-
add
void add(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities) Adds the given entities to all foreign key models based on that entity type- Parameters:
foreignKey- the foreign keyentities- the values
-
remove
void remove(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities) Removes the given entities from all foreign key models based on that entity type and clears any foreign key values referencing them.- Parameters:
foreignKey- the foreign keyentities- the values
-
replace
void replace(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> entities) For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding entity fromentities, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.- Parameters:
foreignKey- the foreign keyentities- the foreign key entities
-
validate
void validate(is.codion.framework.domain.entity.attribute.Attribute<?> attribute) Validates the value associated with the given attribute, using the underlying validator.- Parameters:
attribute- the attribute the value is associated with- Throws:
is.codion.framework.domain.entity.exception.ValidationException- if the given value is not valid for the given attribute
-
validate
Validates the given entities, using the underlying validator. For entities of a type other than this edit model is based on, their respective validators are used.- Parameters:
entities- the entities to validate- Throws:
is.codion.framework.domain.entity.exception.ValidationException- on finding the first invalid entity- See Also:
-
EntityDefinition.validator()
-
validate
void validate(is.codion.framework.domain.entity.Entity entity) Validates the given entity, using the underlying validator. For entities of a type other than this edit model is based on, their respective validators are used.- Parameters:
entity- the entity to validate- Throws:
is.codion.framework.domain.entity.exception.ValidationException- in case the entity is invalidNullPointerException- in case the entity is null
-
beforeInsert
is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>> beforeInsert()- Returns:
- an observer notified before an insert is performed
-
afterInsert
is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>> afterInsert()- Returns:
- an observer notified after an insert is performed
-
beforeUpdate
is.codion.common.observer.Observer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> beforeUpdate()- Returns:
- an observer notified before an update is performed
-
afterUpdate
is.codion.common.observer.Observer<Map<is.codion.framework.domain.entity.Entity.Key,is.codion.framework.domain.entity.Entity>> afterUpdate()- Returns:
- an observer notified after an update is performed
-
beforeDelete
is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>> beforeDelete()- Returns:
- an observer notified before a delete is performed
-
afterDelete
is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>> afterDelete()- Returns:
- an observer notified after a delete is performed
-
afterInsertUpdateOrDelete
is.codion.common.observer.Observer<?> afterInsertUpdateOrDelete()- Returns:
- an observer notified each time one or more entities have been inserted, updated or deleted via this model
-