public class KeyFactory
This class enables direct creation of Key
objects, both in the root entity group (no
parent) and as the child of a given parent. Keys can also be created indirectly by putting named
Entities into the datastore, which will allocate a new key. See Entity#Entity(String,
String) for details.
This class also has methods for encoding and decoding Key
objects to and from strings.
Clients should not make any assumptions about the encoding format, except that it is a websafe
string that does not need to be quoted when used in HTML or in URLs.
See Also: Entity
Static Methods
createKey(@Nullable Key parent, String kind, String name)
public static Key createKey(@Nullable Key parent, String kind, String name)
Creates a new Key
with the provided parent from its kind and name.
Parameters | |
---|---|
Name | Description |
parent |
@org.checkerframework.checker.nullness.qual.Nullable com.google.appengine.api.datastore.Key the parent of the key to create, can be |
kind |
String the kind of the key to create |
name |
String the name of the key in |
Returns | |
---|---|
Type | Description |
Key |
createKey(@Nullable Key parent, String kind, long id)
public static Key createKey(@Nullable Key parent, String kind, long id)
Creates a new Key
with the provided parent from its kind and ID.
Parameters | |
---|---|
Name | Description |
parent |
@org.checkerframework.checker.nullness.qual.Nullable com.google.appengine.api.datastore.Key the parent of the key to create, can be |
kind |
String the kind of the key to create |
id |
long the numeric identifier of the key in |
Returns | |
---|---|
Type | Description |
Key |
createKey(String kind, String name)
public static Key createKey(String kind, String name)
Creates a new Key
having no parent from its kind and name.
Parameters | |
---|---|
Name | Description |
kind |
String the kind of the key to create |
name |
String the name of the key in |
Returns | |
---|---|
Type | Description |
Key |
createKey(String kind, long id)
public static Key createKey(String kind, long id)
Creates a new Key
having no parent from its kind and ID.
Parameters | |
---|---|
Name | Description |
kind |
String the kind of the key to create |
id |
long the numeric identifier of the key in |
Returns | |
---|---|
Type | Description |
Key |
createKeyString(@Nullable Key parent, String kind, String name)
public static String createKeyString(@Nullable Key parent, String kind, String name)
Shorthand for invoking #keyToString(Key) on the result of #createKey(Key, String, String)
Parameters | |
---|---|
Name | Description |
parent |
@org.checkerframework.checker.nullness.qual.Nullable com.google.appengine.api.datastore.Key the parent of the key to create, can be |
kind |
String the kind of the key to create |
name |
String the name of the key in |
Returns | |
---|---|
Type | Description |
String |
A websafe |
createKeyString(@Nullable Key parent, String kind, long id)
public static String createKeyString(@Nullable Key parent, String kind, long id)
Shorthand for invoking #keyToString(Key) on the result of #createKey(Key, String, long)
Parameters | |
---|---|
Name | Description |
parent |
@org.checkerframework.checker.nullness.qual.Nullable com.google.appengine.api.datastore.Key the parent of the key to create, can be |
kind |
String the kind of the key to create |
id |
long the numeric identifier of the key in |
Returns | |
---|---|
Type | Description |
String |
A websafe |
createKeyString(String kind, String name)
public static String createKeyString(String kind, String name)
Shorthand for invoking #keyToString(Key) on the result of #createKey(String, String)
Parameters | |
---|---|
Name | Description |
kind |
String the kind of the key to create |
name |
String the name of the key in |
Returns | |
---|---|
Type | Description |
String |
A websafe |
createKeyString(String kind, long id)
public static String createKeyString(String kind, long id)
Shorthand for invoking #keyToString(Key) on the result of #createKey(String, long)
Parameters | |
---|---|
Name | Description |
kind |
String the kind of the key to create |
id |
long the numeric identifier of the key in |
Returns | |
---|---|
Type | Description |
String |
A websafe |
keyToString(Key key)
public static String keyToString(Key key)
Converts a Key
into a websafe string. For example, this string can safely be used as an
URL parameter embedded in a HTML document. Note that
key.equals(KeyFactory.stringToKey(KeyFactory.keyToString(key))
should evaluate to true
.
Parameter | |
---|---|
Name | Description |
key |
Key The |
Returns | |
---|---|
Type | Description |
String |
A websafe |
stringToKey(String encoded)
public static Key stringToKey(String encoded)
Converts a String
-representation of a Key
into the Key
instance it
represents. Note that
str.equals(KeyFactory.keyToString(KeyFactory.stringToKey(str))
should evaluate to true
for all strings returned by KeyFactory#keyToString.
Parameter | |
---|---|
Name | Description |
encoded |
String The |
Returns | |
---|---|
Type | Description |
Key |
The |