public interface TableEntity
TableEntity
interface declares getter and setter methods
for the common entity properties, and writeEntity
and readEntity
methods for serialization
and deserialization of all entity properties using a property map. Create classes implementing TableEntity
to
customize property storage, retrieval, serialization and deserialization, and to provide additional custom logic for
a table entity.
The Storage client library includes two implementations of TableEntity
that provide for simple property
access and serialization:
DynamicTableEntity
implements TableEntity
and provides a simple property map to store and retrieve
properties. Use a DynamicTableEntity
for simple access to entity properties when only a subset of properties
are returned (for example, by a select clause in a query), or for when your query can return multiple entity types
with different properties. You can also use this type to perform bulk table updates of heterogeneous entities without
losing property information.
TableServiceEntity
is an implementation of TableEntity
that uses reflection-based serialization and
deserialization behavior in its writeEntity
and readEntity
methods.
TableServiceEntity
-derived classes with methods that follow a convention for types and naming are serialized
and deserialized automatically.
Any class that implements TableEntity
can take advantage of the automatic reflection-based serialization and
deserialization behavior in TableServiceEntity
by invoking the static methods
TableServiceEntity.readEntityWithReflection
in readEntity
and
TableServiceEntity.writeEntityWithReflection
in writeEntity
. The class must provide methods
that follow the type and naming convention to be serialized and deserialized automatically. When both a getter method
and setter method are found for a given property name and data type, then the appropriate method is invoked
automatically to serialize or deserialize the data. The reflection code looks for getter and setter methods in pairs
of the form
public type getPropertyName() { ... }
and
public void setPropertyName(type parameter) { ... }
where PropertyName is a property name for the table entity, and type is a Java type compatible with
the EDM data type of the property. See the table in the class description for TableServiceEntity
for a map of
property types to their Java equivalents. The StoreAs
annotation may be applied with a name
attribute to specify a property name for reflection on getter and setter methods that do not follow the property name
convention. Method names and the name
attribute of StoreAs
annotations are case sensitive for
matching property names with reflection. Use the Ignore
annotation to prevent methods from being used by
reflection for automatic serialization and deserialization. Note that the names "PartitionKey", "RowKey",
"Timestamp", and "Etag" are reserved and will be ignored if set with the StoreAs
annotation in a subclass
that uses the reflection methods.
TableServiceEntity
,
DynamicTableEntity
Modifier and Type | Method and Description |
---|---|
String |
getEtag()
Gets the ETag value to verify for the entity.
|
String |
getPartitionKey()
Gets the PartitionKey value for the entity.
|
String |
getRowKey()
Gets the RowKey value for the entity.
|
Date |
getTimestamp()
Gets the Timestamp for the entity.
|
void |
readEntity(HashMap<String,EntityProperty> properties,
OperationContext opContext)
Populates an instance of the object implementing
TableEntity using the specified properties parameter,
which represents a map of String property names to EntityProperty data typed values. |
void |
setEtag(String etag)
Sets the ETag value to verify for the entity.
|
void |
setPartitionKey(String partitionKey)
Sets the PartitionKey value for the entity.
|
void |
setRowKey(String rowKey)
Sets the RowKey value for the entity.
|
void |
setTimestamp(Date timeStamp)
Sets the Timestamp value for the entity.
|
HashMap<String,EntityProperty> |
writeEntity(OperationContext opContext)
Returns a map of
String property names to EntityProperty data typed values
that represents the serialized content of the table entity instance. |
String getEtag()
String
which represents the ETag for the entity.String getPartitionKey()
String
which represents the PartitionKey value for the entity.String getRowKey()
String
which represents the RowKey value for the entity.Date getTimestamp()
java.util.Date
object which represents the Timestamp value for the entity.void readEntity(HashMap<String,EntityProperty> properties, OperationContext opContext) throws StorageException
TableEntity
using the specified properties parameter,
which represents a map of String
property names to EntityProperty
data typed values.properties
- The java.util.HashMap
of String
to EntityProperty
data typed values
to use to populate the table entity instance.opContext
- An OperationContext
object used to track the execution of the operation.StorageException
- If an error occurs during the operation.void setEtag(String etag)
etag
- A String
which specifies the ETag to set for the entity.void setPartitionKey(String partitionKey)
partitionKey
- A String
which specifies the PartitionKey value to set for the entity.void setRowKey(String rowKey)
rowKey
- A String
which specifies the RowKey value to set for the entity.void setTimestamp(Date timeStamp)
timeStamp
- A java.util.Date
which specifies the Timestamp value to set for the entity.HashMap<String,EntityProperty> writeEntity(OperationContext opContext) throws StorageException
String
property names to EntityProperty
data typed values
that represents the serialized content of the table entity instance.opContext
- An OperationContext
object used to track the execution of the operation.java.util.HashMap
of String
property names to EntityProperty
data
typed values representing the properties of the table entity.StorageException
- If an error occurs during the operation.Copyright © 2019. All rights reserved.