java.lang.Object
is.codion.framework.model.AbstractEntityEditModel
- All Implemented Interfaces:
EntityEditModel
- Direct Known Subclasses:
SwingEntityEditModel
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
ModifierConstructorDescriptionprotected
AbstractEntityEditModel
(EntityType entityType, EntityConnectionProvider connectionProvider) Instantiates a newAbstractEntityEditModel
based on the given entity type. -
Method Summary
Modifier and TypeMethodDescriptionfinal Observer<Collection<Entity>>
final Observer<Collection<Entity>>
final Observer<?>
final Observer<Map<Entity.Key,
Entity>> final Observer<Collection<Entity>>
final Observer<Collection<Entity>>
final Observer<Map<Entity.Key,
Entity>> final 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 EntityConnectionProvider
final EntityEditModel.Delete
Creates a newEntityEditModel.Delete
instance for deleting the active entity.final EntityEditModel.Delete
createDelete
(Collection<Entity> entities) Creates a newEntityEditModel.Delete
instance for deleting the given entities.createForeignKeySearchModel
(ForeignKey foreignKey) Creates aEntitySearchModel
for looking up entities referenced by the given foreign key, using the search attributes defined for that entity type.final EntityEditModel.Insert
Creates a newEntityEditModel.Insert
instance for inserting the active entity.final EntityEditModel.Insert
createInsert
(Collection<Entity> entities) Creates a newEntityEditModel.Insert
instance for inserting the given entities.final EntityEditModel.Update
Creates a newEntityEditModel.Update
instance for updating the active entity.final EntityEditModel.Update
createUpdate
(Collection<Entity> entities) Creates a newEntityEditModel.Update
instance for updating the given entities.final Entity
delete()
Note: This method must be called on the UI thread in case a panel has been based on this model.final Collection<Entity>
delete
(Collection<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<Entity> entities, EntityConnection connection) Deletes the given entities from the database using the given connectionfinal State
Disabling delete causes an exception being thrown when deleting.final Entities
entities()
entity()
Returns aEntityEditModel.EditableEntity
wrapping the entity being edited.final EntityDefinition
final EntityType
final EntitySearchModel
foreignKeySearchModel
(ForeignKey foreignKey) final Entity
insert()
Note: This method must be called on the UI thread in case a panel has been based on this model.final Collection<Entity>
insert
(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.protected Collection<Entity>
insert
(Collection<Entity> entities, EntityConnection connection) Inserts the given entities into the database using the given connectionfinal State
Disabling insert causes an exception being thrown when inserting.protected final void
notifyAfterDelete
(Collection<Entity> deletedEntities) Notifies that delete has been performedprotected final void
notifyAfterInsert
(Collection<Entity> insertedEntities) Notifies that insert has been performedprotected final void
notifyAfterUpdate
(Map<Entity.Key, Entity> updatedEntities) Notifies that update has been performedprotected final void
notifyBeforeDelete
(Collection<Entity> entitiesToDelete) Notifies that delete is about to be performedprotected final void
notifyBeforeInsert
(Collection<Entity> entitiesToInsert) Notifies that insert is about to be performedprotected final void
notifyBeforeUpdate
(Map<Entity.Key, Entity> entitiesToUpdate) Notifies that update is about to be performedfinal State
final 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.final void
replace
(ForeignKey foreignKey, Collection<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 void
replaceForeignKey
(ForeignKey foreignKey, Collection<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 String
toString()
final Entity
update()
Note: This method must be called on the UI thread in case a panel has been based on this model.final Collection<Entity>
update
(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.protected Collection<Entity>
update
(Collection<Entity> entities, EntityConnection connection) Updates the given entities in the database using the given connectionfinal State
Disabling update causes an exception being thrown when updating.final State
Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.final void
Validates the value associated with the given attribute, using the underlying validator.final void
Validates the given entity, using the underlying validator.final void
validate
(Collection<Entity> entities) Validates the given entities, using the underlying validator.final <T> EntityEditModel.EditableValue<T>
Returns theEntityEditModel.EditableValue
instance representingattribute
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(EntityType entityType, EntityConnectionProvider connectionProvider) Instantiates a newAbstractEntityEditModel
based on the given entity type.- Parameters:
entityType
- the type of the entity to base thisAbstractEntityEditModel
onconnectionProvider
- theEntityConnectionProvider
instance
-
-
Method Details
-
entities
- Specified by:
entities
in interfaceEntityEditModel
- Returns:
- the underlying domain entities
-
entityDefinition
- Specified by:
entityDefinition
in interfaceEntityEditModel
- Returns:
- the definition of the underlying entity
-
toString
-
postEditEvents
- Specified by:
postEditEvents
in interfaceEntityEditModel
- Returns:
- a state controlling whether this edit model posts insert, update and delete events
on the
EntityEditEvents
event bus. - See Also:
-
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. UseEntityEditModel.insertEnabled()
,EntityEditModel.updateEnabled()
andEntityEditModel.deleteEnabled()
to configure the enabled state of those specific actions.- Specified by:
readOnly
in interfaceEntityEditModel
- Returns:
- the
State
controlling whether this model is read only
-
insertEnabled
Description copied from interface:EntityEditModel
Disabling insert causes an exception being thrown when inserting.- Specified by:
insertEnabled
in interfaceEntityEditModel
- Returns:
- the
State
controlling whether inserting is enabled via this edit model
-
updateEnabled
Description copied from interface:EntityEditModel
Disabling update causes an exception being thrown when updating.- Specified by:
updateEnabled
in interfaceEntityEditModel
- Returns:
- the
State
controlling whether updating is enabled via this edit model
-
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 interfaceEntityEditModel
- Returns:
- the
State
controlling whether updating multiple entities is enabled
-
deleteEnabled
Description copied from interface:EntityEditModel
Disabling delete causes an exception being thrown when deleting.- Specified by:
deleteEnabled
in interfaceEntityEditModel
- Returns:
- the
State
controlling whether deleting is enabled via this edit model
-
entityType
- Specified by:
entityType
in interfaceEntityEditModel
- Returns:
- the type of the entity this edit model is based on
-
connectionProvider
- Specified by:
connectionProvider
in interfaceEntityEditModel
- Returns:
- the connection provider used by this edit model
-
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 interfaceEntityEditModel
- Returns:
- the connection used by this edit model
-
replace
Description copied from interface:EntityEditModel
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.- Specified by:
replace
in interfaceEntityEditModel
- Parameters:
foreignKey
- the foreign keyentities
- the foreign key entities
-
entity
Description copied from interface:EntityEditModel
Returns aEntityEditModel.EditableEntity
wrapping the entity being edited.Observable.get()
returns an immutable copy of theEntity
instance being edited, whileMutable.set(Object)
copies the values from the givenEntity
into the underlyingEntity
. Note that value changes must go through theEntityEditModel.EditableValue
accessible viaEntityEditModel.value(Attribute)
.- Specified by:
entity
in interfaceEntityEditModel
- Returns:
- the
EntityEditModel.EditableEntity
wrapping theEntity
instance being edited - See Also:
-
value
Description copied from interface:EntityEditModel
Returns theEntityEditModel.EditableValue
instance representingattribute
in this edit model.- Specified by:
value
in interfaceEntityEditModel
- Type Parameters:
T
- the value type- Parameters:
attribute
- the attribute- Returns:
- the
EntityEditModel.EditableValue
representing the given attribute
-
validate
Description copied from interface:EntityEditModel
Validates the value associated with the given attribute, using the underlying validator.- Specified by:
validate
in interfaceEntityEditModel
- Parameters:
attribute
- the attribute the value is associated with- Throws:
ValidationException
- if the given value is not valid for the given attribute
-
validate
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 interfaceEntityEditModel
- Parameters:
entities
- the entities to validate- Throws:
ValidationException
- on finding the first invalid entity- See Also:
-
validate
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 interfaceEntityEditModel
- Parameters:
entity
- the entity to validate- Throws:
ValidationException
- in case the entity is invalid
-
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 interfaceEntityEditModel
- Returns:
- the inserted entity
- Throws:
DatabaseException
- in case of a database exceptionValidationException
- in case validation fails- See Also:
-
insert
public final Collection<Entity> insert(Collection<Entity> entities) throws DatabaseException, 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 interfaceEntityEditModel
- Parameters:
entities
- the entities to insert- Returns:
- a list containing the inserted entities
- Throws:
DatabaseException
- in case of a database exceptionValidationException
- in case validation fails- See Also:
-
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 interfaceEntityEditModel
- Returns:
- the updated entity
- Throws:
DatabaseException
- in case of a database exceptionRecordModifiedException
- in case the entity has been modified since it was loadedUpdateException
- in case the active entity is not modifiedValidationException
- in case validation fails- See Also:
-
update
public final Collection<Entity> update(Collection<Entity> entities) throws DatabaseException, 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 interfaceEntityEditModel
- Parameters:
entities
- the entities to update- Returns:
- the updated entities
- Throws:
DatabaseException
- in case of a database exceptionRecordModifiedException
- in case an entity has been modified since it was loadedValidationException
- in case validation fails- See Also:
-
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 interfaceEntityEditModel
- Returns:
- the deleted entity
- Throws:
DatabaseException
- in case of a database exception- See Also:
-
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 interfaceEntityEditModel
- Parameters:
entities
- the entities to delete- Returns:
- the deleted entities
- Throws:
DatabaseException
- in case of a database exception- See Also:
-
createInsert
Description copied from interface:EntityEditModel
Creates a newEntityEditModel.Insert
instance for inserting the active entity.- Specified by:
createInsert
in interfaceEntityEditModel
- Returns:
- a new
EntityEditModel.Insert
instance - Throws:
ValidationException
- in case validation fails
-
createInsert
public final EntityEditModel.Insert createInsert(Collection<Entity> entities) throws ValidationException Description copied from interface:EntityEditModel
Creates a newEntityEditModel.Insert
instance for inserting the given entities.- Specified by:
createInsert
in interfaceEntityEditModel
- Parameters:
entities
- the entities to insert- Returns:
- a new
EntityEditModel.Insert
instance - Throws:
ValidationException
- in case validation fails
-
createUpdate
Description copied from interface:EntityEditModel
Creates a newEntityEditModel.Update
instance for updating the active entity.- Specified by:
createUpdate
in interfaceEntityEditModel
- Returns:
- a new
EntityEditModel.Update
instance - Throws:
ValidationException
- in case validation fails
-
createUpdate
public final EntityEditModel.Update createUpdate(Collection<Entity> entities) throws ValidationException Description copied from interface:EntityEditModel
Creates a newEntityEditModel.Update
instance for updating the given entities.- Specified by:
createUpdate
in interfaceEntityEditModel
- Parameters:
entities
- the entities to update- Returns:
- a new
EntityEditModel.Update
instance - Throws:
ValidationException
- in case validation fails
-
createDelete
Description copied from interface:EntityEditModel
Creates a newEntityEditModel.Delete
instance for deleting the active entity.- Specified by:
createDelete
in interfaceEntityEditModel
- Returns:
- a new
EntityEditModel.Delete
instance
-
createDelete
Description copied from interface:EntityEditModel
Creates a newEntityEditModel.Delete
instance for deleting the given entities.- Specified by:
createDelete
in interfaceEntityEditModel
- Parameters:
entities
- the entities to delete- Returns:
- a new
EntityEditModel.Delete
instance
-
createForeignKeySearchModel
Description copied from interface:EntityEditModel
Creates aEntitySearchModel
for looking up entities referenced by the given foreign key, using the search attributes defined for that entity type.- Specified by:
createForeignKeySearchModel
in interfaceEntityEditModel
- Parameters:
foreignKey
- the foreign key for which to create aEntitySearchModel
- Returns:
- a
EntitySearchModel
for looking up entities of the type referenced by the given foreign key attribute,
-
foreignKeySearchModel
- Specified by:
foreignKeySearchModel
in interfaceEntityEditModel
- Parameters:
foreignKey
- the foreign key for which to retrieve theEntitySearchModel
- Returns:
- the
EntitySearchModel
associated 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
- Specified by:
beforeInsert
in interfaceEntityEditModel
- Returns:
- an observer notified before an insert is performed
-
afterInsert
- Specified by:
afterInsert
in interfaceEntityEditModel
- Returns:
- an observer notified after an insert is performed
-
beforeUpdate
- Specified by:
beforeUpdate
in interfaceEntityEditModel
- Returns:
- an observer notified before an update is performed
-
afterUpdate
- Specified by:
afterUpdate
in interfaceEntityEditModel
- Returns:
- an observer notified after an update is performed
-
beforeDelete
- Specified by:
beforeDelete
in interfaceEntityEditModel
- Returns:
- an observer notified before a delete is performed
-
afterDelete
- Specified by:
afterDelete
in interfaceEntityEditModel
- Returns:
- an observer notified after a delete is performed
-
afterInsertUpdateOrDelete
- Specified by:
afterInsertUpdateOrDelete
in interfaceEntityEditModel
- Returns:
- an observer notified each time one or more entities have been inserted, updated or deleted via this model
-
insert
protected Collection<Entity> insert(Collection<Entity> entities, EntityConnection connection) throws DatabaseException 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:
DatabaseException
- in case of a database exception
-
update
protected Collection<Entity> update(Collection<Entity> entities, EntityConnection connection) throws DatabaseException 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:
DatabaseException
- in case of a database exception
-
delete
protected void delete(Collection<Entity> entities, EntityConnection connection) throws DatabaseException Deletes the given entities from the database using the given connection- Parameters:
entities
- the entities to deleteconnection
- the connection to use- Throws:
DatabaseException
- in case of a database exception
-
replaceForeignKey
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
Notifies that insert is about to be performed- Parameters:
entitiesToInsert
- the entities about to be inserted- See Also:
-
notifyAfterInsert
Notifies that insert has been performed- Parameters:
insertedEntities
- the inserted entities- See Also:
-
notifyBeforeUpdate
Notifies that update is about to be performed- Parameters:
entitiesToUpdate
- the entities about to be updated- See Also:
-
notifyAfterUpdate
Notifies that update has been performed- Parameters:
updatedEntities
- the updated entities- See Also:
-
notifyBeforeDelete
Notifies that delete is about to be performed- Parameters:
entitiesToDelete
- the entities about to be deleted- See Also:
-
notifyAfterDelete
Notifies that delete has been performed- Parameters:
deletedEntities
- the deleted entities- See Also:
-