Class EntityItem
- java.lang.Object
-
- com.priint.pubserver.plugin.entitydata.EntityItem
-
- All Implemented Interfaces:
java.io.Serializable
public class EntityItem extends java.lang.Object implements java.io.SerializableSerialization class for all types of entity data for insert, update or removal.An item is described by an entityClass, entityIdentifier and identifier like "Bucket#product#0815".
An operation for the item is defined as a
ConnectorPersistRemote.PushCommandwith 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEntityItem.StatusResulting status of an operation.
-
Constructor Summary
Constructors Constructor Description EntityItem()Empty default constructor for JAXB
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.Map<java.lang.String,java.lang.Object>createPatch(EntityData item1, EntityData item2)Create a map of all fields where values differ between item 1 and item 2.ConnectorPersistRemote.PushCommandgetCommand()Operation that should be executed on this item.ConnectorEntitygetConnectorEntity()Get connector entity for this item.ContextgetContext()Entity.DataClassgetDataClass()Data class value for this item.java.lang.Class<? extends EntityData>getEntityClass()EntityData class of this itemjava.lang.StringgetEntityIdentifier()Identifier of the entity type in its entityModel.java.lang.StringgetIdentifier()Identifier of the entity item in its data source.java.lang.StringgetMessage()java.util.Map<java.lang.String,java.lang.Object>getPatch()Retrieve a map of patch values for an update.EntityItem.StatusgetStatus()EntityDatagetValue()Retrieve EntityData value for the item.static EntityIteminstanceForDelete(Entity.DataClass dataClass, java.lang.String entityIdentifier, java.lang.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(java.lang.Class<? extends EntityData> entityClass, java.lang.String entityIdentifier, java.lang.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, java.lang.String entityIdentifier, java.lang.String identifier, java.util.Map<java.lang.String,java.lang.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(java.lang.Class<? extends EntityData> entityClass, java.lang.String entityIdentifier, java.lang.String identifier, java.util.Map<java.lang.String,java.lang.Object> patch, Context context)Create a new instance to update an entity item.voidsetConnectorEntity(ConnectorEntity connectorEntity)Set connector entity for this item.voidsetMessage(java.lang.String message)voidsetStatus(EntityItem.Status status)voidsetValue(EntityData value)Set EntityData value for the item.java.lang.StringtoString()
-
-
-
Method Detail
-
createPatch
public static java.util.Map<java.lang.String,java.lang.Object> createPatch(EntityData item1, EntityData item2)
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:
java.lang.IllegalArgumentException- if a property cannot be read in item1 or item2.
-
instanceForDelete
public static EntityItem instanceForDelete(java.lang.Class<? extends EntityData> entityClass, java.lang.String entityIdentifier, java.lang.String identifier, Context context)
Create a new instance to delete an entity item.- Parameters:
entityClass-entityIdentifier-identifier-context-- Returns:
- EntityItem
- Throws:
java.lang.IllegalArgumentException- if any of the arguments is null.
-
instanceForDelete
public static EntityItem instanceForDelete(Entity.DataClass dataClass, java.lang.String entityIdentifier, java.lang.String identifier, Context context)
Create a new instance to delete an entity item.- Parameters:
dataClass-entityIdentifier-identifier-context-- Returns:
- EntityItem
- Throws:
java.lang.IllegalArgumentException- if any of the arguments is null.
-
instanceForDelete
public static EntityItem instanceForDelete(EntityData value)
Create a new instance to delete an entity item.- Parameters:
value-- Returns:
- EntityItem
- Throws:
java.lang.IllegalArgumentException- if the value argument or its entityIdentifier or identifier is null.
-
instanceForInsert
public static EntityItem instanceForInsert(EntityData value)
Create a new instance to insert an entity item.- Parameters:
value- Bucket, text, etc. to be inserted.- Returns:
- new EntityItem for INSERT
- Throws:
java.lang.IllegalArgumentException- if value or type is not supported for this operation.
-
instanceForUpdate
public static EntityItem instanceForUpdate(java.lang.Class<? extends EntityData> entityClass, java.lang.String entityIdentifier, java.lang.String identifier, java.util.Map<java.lang.String,java.lang.Object> patch, Context context)
Create a new instance to update an entity item.- Parameters:
entityClass-entityIdentifier-identifier-patch-context-- Returns:
- EntityItem
- Throws:
java.lang.IllegalArgumentException- if any of the arguments is null.
-
instanceForUpdate
public static EntityItem instanceForUpdate(Entity.DataClass dataClass, java.lang.String entityIdentifier, java.lang.String identifier, java.util.Map<java.lang.String,java.lang.Object> patch, Context context)
Create a new instance to update an entity item.- Parameters:
dataClass-entityIdentifier-identifier-patch-context-- Returns:
- EntityItem
- Throws:
java.lang.IllegalArgumentException- if any of the arguments is null.
-
instanceForUpdate
public static EntityItem instanceForUpdate(EntityData oldValue, EntityData newValue)
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:
java.lang.IllegalArgumentException- if oldValue or newValue are empty of types do not match.
-
getCommand
public ConnectorPersistRemote.PushCommand getCommand()
Operation that should be executed on this item.- Returns:
- command
-
getConnectorEntity
public ConnectorEntity 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
public Entity.DataClass getDataClass()
Data class value for this item. It is preferred to use thegetEntityClass()instead.- Returns:
- dataClass
-
getEntityClass
public java.lang.Class<? extends EntityData> getEntityClass()
EntityData class of this item- Returns:
- class
-
getEntityIdentifier
public java.lang.String getEntityIdentifier()
Identifier of the entity type in its entityModel.Should never be null.
- Returns:
- entityIdentifier
-
getIdentifier
public java.lang.String getIdentifier()
Identifier of the entity item in its data source.Should never be null.
- Returns:
- identifier
-
getMessage
public java.lang.String getMessage()
- Returns:
- status message of the operation defined in
getCommand(). This may contain reasons in case of failure or exception.
-
getPatch
public java.util.Map<java.lang.String,java.lang.Object> 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
public EntityItem.Status getStatus()
- Returns:
- status value of the operation defined in
getCommand().
-
getValue
public EntityData 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
public Context getContext()
- Returns:
- The context of the entity
-
setConnectorEntity
public void setConnectorEntity(ConnectorEntity connectorEntity)
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
public void setMessage(java.lang.String message)
- Parameters:
message-- See Also:
getMessage()
-
setStatus
public void setStatus(EntityItem.Status status)
- Parameters:
status-- See Also:
getStatus()
-
setValue
public void setValue(EntityData value)
Set EntityData value for the item.- Parameters:
value-
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-