java.lang.Object
is.codion.framework.model.AbstractEntityEditModel
- All Implemented Interfaces:
EntityEditModel
A default
EntityEditModel implementation-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.framework.model.EntityEditModel
EntityEditModel.Delete, EntityEditModel.EditableEntity, EntityEditModel.EditableValue<T>, EntityEditModel.Insert, EntityEditModel.Update -
Field Summary
Fields inherited from interface is.codion.framework.model.EntityEditModel
PERSIST_FOREIGN_KEYS, POST_EDIT_EVENTS -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractEntityEditModel(is.codion.framework.domain.entity.EntityType entityType, is.codion.framework.db.EntityConnectionProvider connectionProvider) Instantiates a newAbstractEntityEditModelbased on the given entity type. -
Method Summary
Modifier and TypeMethodDescriptionfinal 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.EntityConnectionDo 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.EntityConnectionProviderfinal EntityEditModel.DeleteCreates a newEntityEditModel.Deleteinstance for deleting the active entity.final EntityEditModel.DeletecreateDelete(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.final EntityEditModel.InsertCreates a newEntityEditModel.Insertinstance for inserting the active entity.final EntityEditModel.InsertcreateInsert(Collection<is.codion.framework.domain.entity.Entity> entities) Creates a newEntityEditModel.Insertinstance for inserting the given entities.final EntityEditModel.UpdateCreates a newEntityEditModel.Updateinstance for updating the active entity.final EntityEditModel.UpdatecreateUpdate(Collection<is.codion.framework.domain.entity.Entity> entities) Creates a newEntityEditModel.Updateinstance for updating the given entities.final 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.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 voiddelete(Collection<is.codion.framework.domain.entity.Entity> entities, is.codion.framework.db.EntityConnection connection) Deletes the given entities from the database using the given connectionfinal is.codion.common.state.StateDisabling delete causes an exception being thrown when deleting.final is.codion.framework.domain.entity.Entitiesentities()entity()Returns aEntityEditModel.EditableEntitywrapping the entity being edited.final is.codion.framework.domain.entity.EntityDefinitionfinal is.codion.framework.domain.entity.EntityTypefinal EntitySearchModelforeignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey) final 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.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 connectionfinal is.codion.common.state.StateDisabling insert causes an exception being thrown when inserting.protected final voidnotifyAfterDelete(Collection<is.codion.framework.domain.entity.Entity> deletedEntities) Notifies that delete has been performedprotected final voidnotifyAfterInsert(Collection<is.codion.framework.domain.entity.Entity> insertedEntities) Notifies that insert has been performedprotected final voidnotifyAfterUpdate(Map<is.codion.framework.domain.entity.Entity.Key, is.codion.framework.domain.entity.Entity> updatedEntities) Notifies that update has been performedprotected final voidnotifyBeforeDelete(Collection<is.codion.framework.domain.entity.Entity> entitiesToDelete) Notifies that delete is about to be performedprotected final voidnotifyBeforeInsert(Collection<is.codion.framework.domain.entity.Entity> entitiesToInsert) Notifies that insert is about to be performedprotected final voidnotifyBeforeUpdate(Map<is.codion.framework.domain.entity.Entity.Key, is.codion.framework.domain.entity.Entity> entitiesToUpdate) Notifies that update is about to be performedfinal is.codion.common.state.Statefinal is.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.final 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.protected voidreplaceForeignKey(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 fromvalues, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.final StringtoString()final 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.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 connectionfinal is.codion.common.state.StateDisabling update causes an exception being thrown when updating.final is.codion.common.state.StateDisabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.final voidvalidate(is.codion.framework.domain.entity.attribute.Attribute<?> attribute) Validates the value associated with the given attribute, using the underlying validator.final voidvalidate(is.codion.framework.domain.entity.Entity entity) Validates the given entity, using the underlying validator.final voidvalidate(Collection<is.codion.framework.domain.entity.Entity> entities) Validates the given entities, using the underlying validator.final <T> EntityEditModel.EditableValue<T>value(is.codion.framework.domain.entity.attribute.Attribute<T> attribute) Returns theEntityEditModel.EditableValueinstance representingattributein this edit model.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 newAbstractEntityEditModelbased on the given entity type.- Parameters:
entityType- the type of the entity to base thisAbstractEntityEditModelonconnectionProvider- theEntityConnectionProviderinstance
-
-
Method Details
-
entities
public final is.codion.framework.domain.entity.Entities entities()- Specified by:
entitiesin interfaceEntityEditModel- Returns:
- the underlying domain entities
-
entityDefinition
public final is.codion.framework.domain.entity.EntityDefinition entityDefinition()- Specified by:
entityDefinitionin interfaceEntityEditModel- Returns:
- the definition of the underlying entity
-
toString
-
postEditEvents
public final is.codion.common.state.State postEditEvents()- Specified by:
postEditEventsin interfaceEntityEditModel- Returns:
- a state controlling whether this edit model posts insert, update and delete events
on the
EntityEditEventsevent bus. - See Also:
-
readOnly
public final is.codion.common.state.State readOnly()Description copied from interface:EntityEditModelMaking 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. UseEntityEditModel.insertEnabled(),EntityEditModel.updateEnabled()andEntityEditModel.deleteEnabled()to configure the enabled state of those specific actions.- Specified by:
readOnlyin interfaceEntityEditModel- Returns:
- the
Statecontrolling whether this model is read only
-
insertEnabled
public final is.codion.common.state.State insertEnabled()Description copied from interface:EntityEditModelDisabling insert causes an exception being thrown when inserting.- Specified by:
insertEnabledin interfaceEntityEditModel- Returns:
- the
Statecontrolling whether inserting is enabled via this edit model
-
updateEnabled
public final is.codion.common.state.State updateEnabled()Description copied from interface:EntityEditModelDisabling update causes an exception being thrown when updating.- Specified by:
updateEnabledin interfaceEntityEditModel- Returns:
- the
Statecontrolling whether updating is enabled via this edit model
-
updateMultipleEnabled
public final is.codion.common.state.State updateMultipleEnabled()Description copied from interface:EntityEditModelDisabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.- Specified by:
updateMultipleEnabledin interfaceEntityEditModel- Returns:
- the
Statecontrolling whether updating multiple entities is enabled
-
deleteEnabled
public final is.codion.common.state.State deleteEnabled()Description copied from interface:EntityEditModelDisabling delete causes an exception being thrown when deleting.- Specified by:
deleteEnabledin interfaceEntityEditModel- Returns:
- the
Statecontrolling whether deleting is enabled via this edit model
-
entityType
public final is.codion.framework.domain.entity.EntityType entityType()- Specified by:
entityTypein interfaceEntityEditModel- Returns:
- the type of the entity this edit model is based on
-
connectionProvider
public final is.codion.framework.db.EntityConnectionProvider connectionProvider()- Specified by:
connectionProviderin interfaceEntityEditModel- Returns:
- the connection provider used by this edit model
-
connection
public final is.codion.framework.db.EntityConnection connection()Description copied from interface:EntityEditModelDo 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:
connectionin interfaceEntityEditModel- 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:EntityEditModelFor 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.- Specified by:
replacein interfaceEntityEditModel- Parameters:
foreignKey- the foreign keyentities- the foreign key entities
-
entity
Description copied from interface:EntityEditModelReturns 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 viaEntityEditModel.value(Attribute).- Specified by:
entityin interfaceEntityEditModel- Returns:
- the
EntityEditModel.EditableEntitywrapping theEntityinstance 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:EntityEditModelReturns theEntityEditModel.EditableValueinstance representingattributein this edit model.- Specified by:
valuein interfaceEntityEditModel- Type Parameters:
T- the value type- Parameters:
attribute- the attribute- Returns:
- the
EntityEditModel.EditableValuerepresenting the given attribute
-
validate
public final void validate(is.codion.framework.domain.entity.attribute.Attribute<?> attribute) Description copied from interface:EntityEditModelValidates the value associated with the given attribute, using the underlying validator.- Specified by:
validatein interfaceEntityEditModel- Parameters:
attribute- the attribute the value is associated with
-
validate
Description copied from interface:EntityEditModelValidates 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:
validatein interfaceEntityEditModel- 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:EntityEditModelValidates 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:
validatein interfaceEntityEditModel- Parameters:
entity- the entity to validate
-
insert
public final is.codion.framework.domain.entity.Entity insert()Description copied from interface:EntityEditModelNote: 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:
insertin interfaceEntityEditModel- 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:EntityEditModelNote: 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:
insertin interfaceEntityEditModel- Parameters:
entities- the entities to insert- Returns:
- a list containing the inserted entities
- See Also:
-
EntityEditModel.beforeInsert()EntityEditModel.afterInsert()EntityValidator.validate(Entity)
-
update
public final is.codion.framework.domain.entity.Entity update()Description copied from interface:EntityEditModelNote: 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:
updatein interfaceEntityEditModel- 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:EntityEditModelNote: 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:
updatein interfaceEntityEditModel- Parameters:
entities- the entities to update- Returns:
- the updated entities
- See Also:
-
EntityEditModel.beforeUpdate()EntityEditModel.afterUpdate()EntityValidator.validate(Entity)
-
delete
public final is.codion.framework.domain.entity.Entity delete()Description copied from interface:EntityEditModelNote: This method must be called on the UI thread in case a panel has been based on this model.- Specified by:
deletein interfaceEntityEditModel- 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:EntityEditModelNote: This method must be called on the UI thread in case a panel has been based on this model.- Specified by:
deletein interfaceEntityEditModel- Parameters:
entities- the entities to delete- Returns:
- the deleted entities
- See Also:
-
createInsert
Description copied from interface:EntityEditModelCreates a newEntityEditModel.Insertinstance for inserting the active entity.- Specified by:
createInsertin interfaceEntityEditModel- Returns:
- a new
EntityEditModel.Insertinstance
-
createInsert
public final EntityEditModel.Insert createInsert(Collection<is.codion.framework.domain.entity.Entity> entities) Description copied from interface:EntityEditModelCreates a newEntityEditModel.Insertinstance for inserting the given entities.- Specified by:
createInsertin interfaceEntityEditModel- Parameters:
entities- the entities to insert- Returns:
- a new
EntityEditModel.Insertinstance
-
createUpdate
Description copied from interface:EntityEditModelCreates a newEntityEditModel.Updateinstance for updating the active entity.- Specified by:
createUpdatein interfaceEntityEditModel- Returns:
- a new
EntityEditModel.Updateinstance
-
createUpdate
public final EntityEditModel.Update createUpdate(Collection<is.codion.framework.domain.entity.Entity> entities) Description copied from interface:EntityEditModelCreates a newEntityEditModel.Updateinstance for updating the given entities.- Specified by:
createUpdatein interfaceEntityEditModel- Parameters:
entities- the entities to update- Returns:
- a new
EntityEditModel.Updateinstance
-
createDelete
Description copied from interface:EntityEditModelCreates a newEntityEditModel.Deleteinstance for deleting the active entity.- Specified by:
createDeletein interfaceEntityEditModel- Returns:
- a new
EntityEditModel.Deleteinstance
-
createDelete
public final EntityEditModel.Delete createDelete(Collection<is.codion.framework.domain.entity.Entity> entities) Description copied from interface:EntityEditModelCreates a newEntityEditModel.Deleteinstance for deleting the given entities.- Specified by:
createDeletein interfaceEntityEditModel- Parameters:
entities- the entities to delete- Returns:
- a new
EntityEditModel.Deleteinstance
-
createForeignKeySearchModel
public EntitySearchModel createForeignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey) Description copied from interface:EntityEditModelCreates aEntitySearchModelfor looking up entities referenced by the given foreign key, using the search attributes defined for that entity type.- Specified by:
createForeignKeySearchModelin interfaceEntityEditModel- 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,
-
foreignKeySearchModel
public final EntitySearchModel foreignKeySearchModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey) - Specified by:
foreignKeySearchModelin interfaceEntityEditModel- 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.
-
beforeInsert
public final is.codion.common.observer.Observer<Collection<is.codion.framework.domain.entity.Entity>> beforeInsert()- Specified by:
beforeInsertin interfaceEntityEditModel- 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:
afterInsertin interfaceEntityEditModel- 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:
beforeUpdatein interfaceEntityEditModel- 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:
afterUpdatein interfaceEntityEditModel- 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:
beforeDeletein interfaceEntityEditModel- 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:
afterDeletein interfaceEntityEditModel- Returns:
- an observer notified after a delete is performed
-
afterInsertUpdateOrDelete
public final is.codion.common.observer.Observer<?> afterInsertUpdateOrDelete()- Specified by:
afterInsertUpdateOrDeletein interfaceEntityEditModel- 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 insertconnection- 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 updateconnection- 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 deleteconnection- 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 fromvalues, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.- Parameters:
foreignKey- the foreign key attributevalues- 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:
-