Class EntityItem
- All Implemented Interfaces:
Serializable
An item is described by an entityClass, entityIdentifier and identifier like "Bucket#product#0815".
An operation for the item is defined as a ConnectorPersistRemote.PushCommand with field values meaning "insert", "update", "upsert", "delete", etc..
Data can be attached as full item, e.g. a Bucket or a TableData object (for insert).
Data can be attached as patch (or "diff") (for update). A patch is actually a hash map of field values.
The result of an operation can be provided as a EntityItem.Status (like "processing", "updated", "failed", etc.). The status can be detailed
by a textual message.
Create EntityItems through one of the provided factory methods.
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreatePatch(EntityData item1, EntityData item2) Create a map of all fields where values differ between item 1 and item 2.Operation that should be executed on this item.Get connector entity for this item.Data class value for this item.Class<? extends EntityData>EntityData class of this itemIdentifier of the entity type in its entityModel.Identifier of the entity item in its data source.getPatch()Retrieve a map of patch values for an update.getValue()Retrieve EntityData value for the item.static EntityIteminstanceForDelete(Entity.DataClass dataClass, String entityIdentifier, String identifier, Context context) Create a new instance to delete an entity item.static EntityIteminstanceForDelete(EntityData value) Create a new instance to delete an entity item.static EntityIteminstanceForDelete(Class<? extends EntityData> entityClass, String entityIdentifier, String identifier, Context context) Create a new instance to delete an entity item.static EntityIteminstanceForInsert(EntityData value) Create a new instance to insert an entity item.static EntityIteminstanceForUpdate(Entity.DataClass dataClass, String entityIdentifier, String identifier, Map<String, Object> patch, Context context) Create a new instance to update an entity item.static EntityIteminstanceForUpdate(EntityData oldValue, EntityData newValue) Create a new instance to update an entity item.static EntityIteminstanceForUpdate(Class<? extends EntityData> entityClass, String entityIdentifier, String identifier, Map<String, Object> patch, Context context) Create a new instance to update an entity item.voidsetConnectorEntity(ConnectorEntity connectorEntity) Set connector entity for this item.voidsetMessage(String message) voidsetStatus(EntityItem.Status status) voidsetValue(EntityData value) Set EntityData value for the item.toString()
-
Constructor Details
-
EntityItem
public EntityItem()Empty default constructor for JAXB
-
-
Method Details
-
createPatch
Create a map of all fields where values differ between item 1 and item 2.This compares only fields that are listed in the @XmlType propOrder attribute of the class.
- Parameters:
item1-item2-- Returns:
- Map of differences or empty map.
- Throws:
IllegalArgumentException- if a property cannot be read in item1 or item2.
-
instanceForDelete
public static EntityItem instanceForDelete(Class<? extends EntityData> entityClass, String entityIdentifier, String identifier, Context context) Create a new instance to delete an entity item.- Parameters:
entityClass-entityIdentifier-identifier-context-- Returns:
- EntityItem
- Throws:
IllegalArgumentException- if any of the arguments is null.
-
instanceForDelete
public static EntityItem instanceForDelete(Entity.DataClass dataClass, String entityIdentifier, String identifier, Context context) Create a new instance to delete an entity item.- Parameters:
dataClass-entityIdentifier-identifier-context-- Returns:
- EntityItem
- Throws:
IllegalArgumentException- if any of the arguments is null.
-
instanceForDelete
Create a new instance to delete an entity item.- Parameters:
value-- Returns:
- EntityItem
- Throws:
IllegalArgumentException- if the value argument or its entityIdentifier or identifier is null.
-
instanceForInsert
Create a new instance to insert an entity item.- Parameters:
value- Bucket, text, etc. to be inserted.- Returns:
- new EntityItem for INSERT
- Throws:
IllegalArgumentException- if value or type is not supported for this operation.
-
instanceForUpdate
public static EntityItem instanceForUpdate(Class<? extends EntityData> entityClass, String entityIdentifier, String identifier, Map<String, Object> patch, Context context) Create a new instance to update an entity item.- Parameters:
entityClass-entityIdentifier-identifier-patch-context-- Returns:
- EntityItem
- Throws:
IllegalArgumentException- if any of the arguments is null.
-
instanceForUpdate
public static EntityItem instanceForUpdate(Entity.DataClass dataClass, String entityIdentifier, String identifier, Map<String, Object> patch, Context context) Create a new instance to update an entity item.- Parameters:
dataClass-entityIdentifier-identifier-patch-context-- Returns:
- EntityItem
- Throws:
IllegalArgumentException- if any of the arguments is null.
-
instanceForUpdate
Create a new instance to update an entity item.OldValue and newValue will be compared to create a patch.
- Parameters:
oldValue-newValue-- Returns:
- EntityItem
- Throws:
IllegalArgumentException- if oldValue or newValue are empty of types do not match.
-
getCommand
Operation that should be executed on this item.- Returns:
- command
-
getConnectorEntity
Get connector entity for this item.This will NOT read the connector entity from the embedded value in INSERT operations.
Normally, connectorEntity will be automatically handled by the entity manager.
Use this method only if you are directly dealing with a connector.
- Returns:
- connectorEntity
-
getDataClass
Data class value for this item. It is preferred to use thegetEntityClass()instead.- Returns:
- dataClass
-
getEntityClass
EntityData class of this item- Returns:
- class
-
getEntityIdentifier
Identifier of the entity type in its entityModel.Should never be null.
- Returns:
- entityIdentifier
-
getIdentifier
Identifier of the entity item in its data source.Should never be null.
- Returns:
- identifier
-
getMessage
- Returns:
- status message of the operation defined in
getCommand(). This may contain reasons in case of failure or exception.
-
getPatch
Retrieve a map of patch values for an update. A field patch is defined as an entry with key=fieldName and value=someObject. This makes-up a DIFF between old and new values for the item.Values can be of any object type here. But during real update process the type must match the actual type of the target field. Otherwise an exception will be raised or the field is silently skipped. Please read the documentation of the update method you are calling.
- Returns:
- patch
-
getStatus
- Returns:
- status value of the operation defined in
getCommand().
-
getValue
Retrieve EntityData value for the item. This MUST be set for INSERT operations. It will normally be null for UPDATE and DELETE.- Returns:
- value
-
getContext
- Returns:
- The context of the entity
-
setConnectorEntity
Set connector entity for this item.This is only needed for update actions, where ConnectorEntity cannot be attached to the item itself.
Normally, connectorEntity will be automatically handled by the entity manager.
Use this method only if you are directly dealing with a connector.
- Parameters:
connectorEntity-
-
setMessage
- Parameters:
message-- See Also:
-
setStatus
- Parameters:
status-- See Also:
-
setValue
Set EntityData value for the item.- Parameters:
value-
-
toString
-