public final class Entity extends PropertyContainer implements Cloneable
Entity
is the fundamental unit of data storage. It has an immutable identifier (contained
in the Key) object, a reference to an optional parent Entity
, a kind (represented
as an arbitrary string), and a set of zero or more typed properties.
Implements
CloneableStatic Fields
KEY_RESERVED_PROPERTY
public static final String KEY_RESERVED_PROPERTY
A reserved property name used to refer to the key of the entity. This string can be used for filtering and sorting by the entity key itself.
Field Value | |
---|---|
Type | Description |
String |
SCATTER_RESERVED_PROPERTY
public static final String SCATTER_RESERVED_PROPERTY
A reserved property name used to refer to the scatter property of the entity. Used for finding split points (e.g. for mapping over a kind).
Field Value | |
---|---|
Type | Description |
String |
VERSION_RESERVED_PROPERTY
public static final String VERSION_RESERVED_PROPERTY
A reserved property name used to report an entity group's version.
Field Value | |
---|---|
Type | Description |
String |
Constructors
Entity(Key key)
public Entity(Key key)
Create a new Entity
uniquely identified by the provided Key. Creating an entity
for the purpose of insertion (as opposed to update) with a key that has its id
field
set is strongly discouraged unless the key was returned by a KeyRange.
See Also: KeyRange
Parameter | |
---|---|
Name | Description |
key |
Key |
Entity(String kind)
public Entity(String kind)
Create a new Entity
with the specified kind and no parent Entity
. The
instantiated Entity
will have an incomplete Key when this constructor returns.
The Key will remain incomplete until you put the Entity
, after which time the
Key will have its id
set.
Parameter | |
---|---|
Name | Description |
kind |
String |
Entity(String kind, @Nullable Key parent)
public Entity(String kind, @Nullable Key parent)
Create a new Entity
with the specified kind and parent Entity
. The instantiated
Entity
will have an incomplete Key when this constructor returns. The Key will remain incomplete until you put the Entity
, after which time the Key
will have its id
set.
Parameters | |
---|---|
Name | Description |
kind |
String |
parent |
@org.checkerframework.checker.nullness.qual.Nullable com.google.appengine.api.datastore.Key |
Entity(String kind, String keyName)
public Entity(String kind, String keyName)
Create a new Entity
with the specified kind and key name and no parent Entity
.
The instantiated Entity
will have a complete Key when this constructor returns.
The Key's name
field will be set to the value of keyName
.
This constructor is syntactic sugar for new Entity(KeyFactory.createKey(kind,
keyName))
.
Parameters | |
---|---|
Name | Description |
kind |
String |
keyName |
String |
Entity(String kind, String keyName, Key parent)
public Entity(String kind, String keyName, Key parent)
Create a new Entity
with the specified kind, key name, and parent Entity
. The
instantiated Entity
will have a complete Key when this constructor returns. The
Key's name
field will be set to the value of keyName
.
This constructor is syntactic sugar for new Entity(KeyFactory.createKey(parent, kind,
keyName))
.
Parameters | |
---|---|
Name | Description |
kind |
String |
keyName |
String |
parent |
Key |
Entity(String kind, long id)
public Entity(String kind, long id)
Create a new Entity
with the specified kind and ID and no parent Entity
. The
instantiated Entity
will have a complete Key when this constructor returns. The
Key's id
field will be set to the value of id
.
Creating an entity for the purpose of insertion (as opposed to update) with this constructor is discouraged unless the id was obtained from a key returned by a KeyRange obtained from AsyncDatastoreService#allocateIds(String, long) or DatastoreService#allocateIds(String, long) for the same kind.
This constructor is syntactic sugar for new Entity(KeyFactory.createKey(kind, id))
.
Parameters | |
---|---|
Name | Description |
kind |
String |
id |
long |
Entity(String kind, long id, Key parent)
public Entity(String kind, long id, Key parent)
Create a new Entity
with the specified kind and ID and parent Entity
. The
instantiated Entity
will have a complete Key when this constructor returns. The
Key's id
field will be set to the value of id
.
Creating an entity for the purpose of insertion (as opposed to update) with this constructor is discouraged unless the id was obtained from a key returned by a KeyRange obtained from AsyncDatastoreService#allocateIds(Key, String, long) or DatastoreService#allocateIds(Key, String, long) for the same parent and kind.
This constructor is syntactic sugar for new Entity(KeyFactory.createKey(parent, kind,
id))
.
Parameters | |
---|---|
Name | Description |
kind |
String |
id |
long |
parent |
Key |
Methods
clone()
public Entity clone()
Returns a shallow copy of this Entity
instance. Collection
properties are
cloned as an ArrayList
, the type returned from the datastore. Instances of mutable
datastore types are cloned as well. Instances of all other types are reused.
Returns | |
---|---|
Type | Description |
Entity |
a shallow copy of this |
equals(@Nullable Object object)
public boolean equals(@Nullable Object object)
Two Entity
objects are considered equal if they refer to the same entity (i.e. their
Key
objects match).
Parameter | |
---|---|
Name | Description |
object |
@org.checkerframework.checker.nullness.qual.Nullable java.lang.Object |
Returns | |
---|---|
Type | Description |
boolean |
getAppId()
public String getAppId()
Returns the identifier of the application that owns this Entity
. This is simply a
convenience method that forwards to the Key
for this Entity
.
Returns | |
---|---|
Type | Description |
String |
getKey()
public Key getKey()
Returns the Key
that represents this Entity
. If the entity has not yet been
saved (e.g. via DatastoreService.put
), this Key
will not be fully specified and
cannot be used for certain operations (like DatastoreService.get
). Once the
Entity
has been saved, its Key
will be updated to be fully specified.
Returns | |
---|---|
Type | Description |
Key |
getKind()
public String getKind()
Returns a logical type that is associated with this Entity
. This is simply a
convenience method that forwards to the Key
for this Entity
.
Returns | |
---|---|
Type | Description |
String |
getNamespace()
public String getNamespace()
Returns the namespace of the application/namespace that owns this Entity
. This is
simply a convenience method that forwards to the Key
for this Entity
.
Returns | |
---|---|
Type | Description |
String |
getParent()
public @Nullable Key getParent()
Get a Key
that corresponds to this the parent Entity
of this Entity
.
This is simply a convenience method that forwards to the Key
for this Entity
.
Returns | |
---|---|
Type | Description |
@org.checkerframework.checker.nullness.qual.Nullable com.google.appengine.api.datastore.Key |
hashCode()
public int hashCode()
Returns | |
---|---|
Type | Description |
int |
setPropertiesFrom(Entity src)
public void setPropertiesFrom(Entity src)
Parameter | |
---|---|
Name | Description |
src |
Entity |
toString()
public String toString()
Returns | |
---|---|
Type | Description |
String |