|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.appengine.api.datastore.Key
public final class Key
The primary key for a datastore entity.
A datastore GUID. A Key instance uniquely identifies an entity
across all apps, and includes all information necessary to fetch
the entity from the datastore with DatastoreService.get(Key)
.
You can create Key
objects directly by using KeyFactory.createKey(java.lang.String, long)
or getChild(java.lang.String, long)
.
You can also retrieve the Key
automatically created when you
create a new Entity
, or serialize Key
objects, or
use KeyFactory
to convert them to and from websafe String
values.
KeyFactory
,
Serialized FormMethod Summary | |
---|---|
int |
compareTo(Key other)
Compares two Key objects. |
boolean |
equals(java.lang.Object object)
Compares two Key objects by comparing ids, kinds, parent
and appIdNamespace. |
Key |
getChild(java.lang.String kind,
long id)
Creates a new key having this as parent and the given numeric
identifier. |
Key |
getChild(java.lang.String kind,
java.lang.String name)
Creates a new key having this as parent and the given name. |
long |
getId()
Returns the numeric identifier of this Key . |
java.lang.String |
getKind()
Returns the kind of the Entity represented by this Key . |
java.lang.String |
getName()
|
java.lang.String |
getNamespace()
Returns the namespace for this Key . |
Key |
getParent()
If this Key has a parent, return a Key that
represents it. |
int |
hashCode()
|
boolean |
isComplete()
Returns true if this Key has a name specified or has been assigned an identifier. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public java.lang.String getKind()
Entity
represented by this Key
.
public Key getParent()
Key
has a parent, return a Key
that
represents it. If not, simply return null.
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object object)
Key
objects by comparing ids, kinds, parent
and appIdNamespace.
If both keys are assigned names rather than ids, compares names instead
of ids. If neither key has an id or a name, the keys are only equal if
they reference the same object.
equals
in class java.lang.Object
public java.lang.String getNamespace()
Key
.
public long getId()
Key
.
public java.lang.String getName()
public Key getChild(java.lang.String kind, long id)
this
as parent and the given numeric
identifier. The parent key must be complete.
kind
- the kind of the child key to createid
- the numeric identifier of the key in kind
, unique
for this parentpublic Key getChild(java.lang.String kind, java.lang.String name)
this
as parent and the given name. The
parent key must be complete.
kind
- the kind of the child key to createname
- the name of the key in kind
, as an arbitrary string
unique for this parentpublic boolean isComplete()
public int compareTo(Key other)
Key
objects. The algorithm proceeds as follows:
Turn each Key
into an iterator where the first element returned
is the top-most ancestor, the next element is the child
of the previous element, and so on. The last element will
be the Key
we started with. Once we have assembled these two
iterators (one for 'this' and one for the Key
we're comparing to),
consume them in parallel, comparing the next element from each iterator.
If at any point the comparison of these two elements yields a non-zero
result, return that as the result of the overall comparison. If we
exhaust the iterator built from 'this' before we exhaust
the iterator built from the other Key
, we return less than. An
example:
app1.type1.4.app1.type2.9 < app1.type1.4.app1.type2.9.app1.type3.2
If we exhaust the iterator built from the other Key
before we
exhaust the iterator built from 'this', we return greater than. An
example:
app1.type1.4.app1.type2.9.app1.type3.2 > app1.type1.4.app1.type2.9
The relationship between individual Key Keys
is performed
by comparing app followed by kind followed by id. If both keys are
assigned names rather than ids, compares names instead of ids. If neither
key has an id or a name we return an arbitrary but consistent result.
Assuming all other components are equal, all ids are less than all names.
compareTo
in interface java.lang.Comparable<Key>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |