- All Known Implementing Classes:
AbstractEntityEditModel
,SwingEntityEditModel
public interface EntityEditModel
Specifies a class for editing
Entity
instances.
The underlying attribute values are available via value(Attribute)
.-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Represents a task for deleting entities.static interface
Provides access to the active entity being edited.static interface
Provides access the anAttribute
value in the entity being edited.static interface
Represents a task for inserting entities, split up for use with a background thread.static interface
Represents a task for updating entities. -
Field Summary
Modifier and TypeFieldDescriptionstatic final PropertyValue<Boolean>
Specifies whether foreign key values should persist by default when defaults are set Value type: Boolean Default value: truestatic final PropertyValue<Boolean>
Specifies whether edit models post their insert, update and delete events toEntityEditEvents
Value type: Boolean Default value: true -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(ForeignKey foreignKey, Collection<Entity> entities) Adds the given entities to all foreign key models based on that entity typeObserver<?>
Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.Creates a newEntityEditModel.Delete
instance for deleting the active entity.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.Creates a newEntityEditModel.Insert
instance for inserting the active entity.createInsert
(Collection<Entity> entities) Creates a newEntityEditModel.Insert
instance for inserting the given entities.Creates a newEntityEditModel.Update
instance for updating the active entity.createUpdate
(Collection<Entity> entities) Creates a newEntityEditModel.Update
instance for updating the given entities.delete()
Note: This method must be called on the UI thread in case a panel has been based on this model.delete
(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.Disabling delete causes an exception being thrown when deleting.entities()
entity()
Returns aEntityEditModel.EditableEntity
wrapping the entity being edited.foreignKeySearchModel
(ForeignKey foreignKey) insert()
Note: This method must be called on the UI thread in case a panel has been based on this model.insert
(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.Disabling insert causes an exception being thrown when inserting.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.void
remove
(ForeignKey foreignKey, Collection<Entity> entities) Removes the given entities from all foreign key models based on that entity type and clears any foreign key values referencing them.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.update()
Note: This method must be called on the UI thread in case a panel has been based on this model.update
(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.Disabling update causes an exception being thrown when updating.Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.void
Validates the value associated with the given attribute, using the underlying validator.void
Validates the given entity, using the underlying validator.void
validate
(Collection<Entity> entities) Validates the given entities, using the underlying validator.Returns theEntityEditModel.EditableValue
instance representingattribute
in 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
EntityType entityType()- Returns:
- the type of the entity this edit model is based on
-
connectionProvider
EntityConnectionProvider connectionProvider()- Returns:
- the connection provider used by this edit model
-
connection
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.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 viavalue(Attribute)
.- Returns:
- the
EntityEditModel.EditableEntity
wrapping theEntity
instance being edited - See Also:
-
value
Returns theEntityEditModel.EditableValue
instance representingattribute
in this edit model.- Type Parameters:
T
- the value type- Parameters:
attribute
- the attribute- Returns:
- the
EntityEditModel.EditableValue
representing the given attribute
-
entities
Entities entities()- Returns:
- the underlying domain entities
-
entityDefinition
EntityDefinition entityDefinition()- Returns:
- the definition of the underlying entity
-
readOnly
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
State
controlling whether this model is read only
-
insertEnabled
State insertEnabled()Disabling insert causes an exception being thrown when inserting.- Returns:
- the
State
controlling whether inserting is enabled via this edit model
-
updateEnabled
State updateEnabled()Disabling update causes an exception being thrown when updating.- Returns:
- the
State
controlling whether updating is enabled via this edit model
-
updateMultipleEnabled
State updateMultipleEnabled()Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.- Returns:
- the
State
controlling whether updating multiple entities is enabled
-
deleteEnabled
State deleteEnabled()Disabling delete causes an exception being thrown when deleting.- Returns:
- the
State
controlling whether deleting is enabled via this edit model
-
createForeignKeySearchModel
Creates aEntitySearchModel
for 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
EntitySearchModel
for 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
- 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.
-
postEditEvents
State postEditEvents()- Returns:
- a state controlling whether this edit model posts insert, update and delete events
on the
EntityEditEvents
event bus. - See Also:
-
insert
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:
DatabaseException
- in case of a database exceptionValidationException
- in case validation failsIllegalStateException
- in case inserting is not enabled- See Also:
-
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 given entities.- Parameters:
entities
- the entities to insert- Returns:
- a list containing the inserted entities
- Throws:
DatabaseException
- in case of a database exceptionValidationException
- in case validation failsIllegalStateException
- in case inserting is not enabled- See Also:
-
update
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:
DatabaseException
- in case of a database exceptionRecordModifiedException
- in case the entity has been modified since it was loadedValidationException
- in case validation failsIllegalStateException
- in case updating is not enabledUpdateException
- in case the active entity is not modified- See Also:
-
update
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:
DatabaseException
- in case of a database exceptionRecordModifiedException
- in case an entity has been modified since it was loadedValidationException
- in case validation failsIllegalStateException
- in case updating is not enabled- See Also:
-
delete
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:
DatabaseException
- in case of a database exceptionIllegalStateException
- in case deleting is not enabled- See Also:
-
delete
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:
DatabaseException
- in case of a database exceptionIllegalStateException
- in case deleting is not enabled- See Also:
-
createInsert
EntityEditModel.Insert createInsert()Creates a newEntityEditModel.Insert
instance for inserting the active entity.- Returns:
- a new
EntityEditModel.Insert
instance - Throws:
ValidationException
- in case validation fails
-
createInsert
Creates a newEntityEditModel.Insert
instance for inserting the given entities.- Parameters:
entities
- the entities to insert- Returns:
- a new
EntityEditModel.Insert
instance - Throws:
ValidationException
- in case validation fails
-
createUpdate
EntityEditModel.Update createUpdate()Creates a newEntityEditModel.Update
instance for updating the active entity.- Returns:
- a new
EntityEditModel.Update
instance - Throws:
IllegalArgumentException
- in case the active entity is unmodifiedValidationException
- in case validation fails
-
createUpdate
Creates a newEntityEditModel.Update
instance for updating the given entities.- Parameters:
entities
- the entities to update- Returns:
- a new
EntityEditModel.Update
instance - Throws:
IllegalArgumentException
- in case any of the given entities are unmodifiedValidationException
- in case validation fails
-
createDelete
EntityEditModel.Delete createDelete()Creates a newEntityEditModel.Delete
instance for deleting the active entity.- Returns:
- a new
EntityEditModel.Delete
instance
-
createDelete
Creates a newEntityEditModel.Delete
instance for deleting the given entities.- Parameters:
entities
- the entities to delete- Returns:
- a new
EntityEditModel.Delete
instance
-
add
Adds the given entities to all foreign key models based on that entity type- Parameters:
foreignKey
- the foreign keyentities
- the values
-
remove
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
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
Validates the value associated with the given attribute, using the underlying validator.- Parameters:
attribute
- the attribute the value is associated with- Throws:
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:
ValidationException
- on finding the first invalid entity- See Also:
-
validate
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:
ValidationException
- in case the entity is invalidNullPointerException
- in case the entity is null
-
beforeInsert
Observer<Collection<Entity>> beforeInsert()- Returns:
- an observer notified before an insert is performed
-
afterInsert
Observer<Collection<Entity>> afterInsert()- Returns:
- an observer notified after an insert is performed
-
beforeUpdate
Observer<Map<Entity.Key,Entity>> beforeUpdate()- Returns:
- an observer notified before an update is performed
-
afterUpdate
Observer<Map<Entity.Key,Entity>> afterUpdate()- Returns:
- an observer notified after an update is performed
-
beforeDelete
Observer<Collection<Entity>> beforeDelete()- Returns:
- an observer notified before a delete is performed
-
afterDelete
Observer<Collection<Entity>> afterDelete()- Returns:
- an observer notified after a delete is performed
-
afterInsertUpdateOrDelete
Observer<?> afterInsertUpdateOrDelete()- Returns:
- an observer notified each time one or more entities have been inserted, updated or deleted via this model
-