com.google.appengine.api.datastore
Class KeyFactory
- java.lang.Object
-
- com.google.appengine.api.datastore.KeyFactory
-
public class KeyFactory extends java.lang.ObjectThis class enables direct creation ofKeyobjects, 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. SeeEntity.Entity(String, String)for details.This class also has methods for encoding and decoding
Keyobjects 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classKeyFactory.BuilderHelper class that aids in the construction ofKeyswith ancestors.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static KeycreateKey(Key parent, java.lang.String kind, long id)Creates a newKeywith the provided parent from its kind and ID.static KeycreateKey(Key parent, java.lang.String kind, java.lang.String name)Creates a newKeywith the provided parent from its kind and name.static KeycreateKey(java.lang.String kind, long id)Creates a newKeyhaving no parent from its kind and ID.static KeycreateKey(java.lang.String kind, java.lang.String name)Creates a newKeyhaving no parent from its kind and name.static java.lang.StringcreateKeyString(Key parent, java.lang.String kind, long id)Shorthand for invokingkeyToString(Key)on the result ofcreateKey(Key, String, long)static java.lang.StringcreateKeyString(Key parent, java.lang.String kind, java.lang.String name)Shorthand for invokingkeyToString(Key)on the result ofcreateKey(Key, String, String)static java.lang.StringcreateKeyString(java.lang.String kind, long id)Shorthand for invokingkeyToString(Key)on the result ofcreateKey(String, long)static java.lang.StringcreateKeyString(java.lang.String kind, java.lang.String name)Shorthand for invokingkeyToString(Key)on the result ofcreateKey(String, String)static java.lang.StringkeyToString(Key key)Converts aKeyinto a websafe string.static KeystringToKey(java.lang.String encoded)Converts aString-representation of aKeyinto theKeyinstance it represents.
-
-
-
Method Detail
-
createKey
public static Key createKey(java.lang.String kind, long id)
Creates a newKeyhaving no parent from its kind and ID.- Parameters:
kind- the kind of the key to createid- the numeric identifier of the key inkind, unique across all root entities of this kind, must not be zero
-
createKey
public static Key createKey(Key parent, java.lang.String kind, long id)
Creates a newKeywith the provided parent from its kind and ID.- Parameters:
parent- the parent of the key to create, can benullkind- the kind of the key to createid- the numeric identifier of the key inkind, unique across all entities of this kind with the same parent, must not be zero
-
createKey
public static Key createKey(java.lang.String kind, java.lang.String name)
Creates a newKeyhaving no parent from its kind and name.- Parameters:
kind- the kind of the key to createname- the name of the key inkind, as an arbitrary string unique across all root entities of thiskind
-
createKey
public static Key createKey(Key parent, java.lang.String kind, java.lang.String name)
Creates a newKeywith the provided parent from its kind and name.- Parameters:
parent- the parent of the key to create, can benullkind- the kind of the key to createname- the name of the key inkind, as an arbitrary string unique across all entities of thiskindwith the same parent
-
createKeyString
public static java.lang.String createKeyString(java.lang.String kind, long id)Shorthand for invokingkeyToString(Key)on the result ofcreateKey(String, long)- Parameters:
kind- the kind of the key to createid- the numeric identifier of the key inkind, unique across all root entities of this kind, must not be zero- Returns:
- A websafe
Stringrepresentation of theKeythat was created
-
createKeyString
public static java.lang.String createKeyString(Key parent, java.lang.String kind, long id)
Shorthand for invokingkeyToString(Key)on the result ofcreateKey(Key, String, long)- Parameters:
parent- the parent of the key to create, can benull.kind- the kind of the key to createid- the numeric identifier of the key inkind, unique across entities of this kind with the same parent, must not be zero- Returns:
- A websafe
Stringrepresentation of theKeythat was created
-
createKeyString
public static java.lang.String createKeyString(java.lang.String kind, java.lang.String name)Shorthand for invokingkeyToString(Key)on the result ofcreateKey(String, String)- Parameters:
kind- the kind of the key to createname- the name of the key inkind, as an arbitrary string unique across root entities of thiskind- Returns:
- A websafe
Stringrepresentation of theKeythat was created
-
createKeyString
public static java.lang.String createKeyString(Key parent, java.lang.String kind, java.lang.String name)
Shorthand for invokingkeyToString(Key)on the result ofcreateKey(Key, String, String)- Parameters:
parent- the parent of the key to create, can benull.kind- the kind of the key to createname- the name of the key inkind, as an arbitrary string unique across entities of thiskindwith the same parent- Returns:
- A websafe
Stringrepresentation of theKeythat was created
-
keyToString
public static java.lang.String keyToString(Key key)
Converts aKeyinto a websafe string. For example, this string can safely be used as an URL parameter embedded in a HTML document. Note thatkey.equals(KeyFactory.stringToKey(KeyFactory.keyToString(key))should evaluate totrue.- Parameters:
key- TheKeyto convert to aString.- Returns:
- A websafe
Stringrepresentation of the providedString. - Throws:
java.lang.IllegalArgumentException- If the specifiedKeyis incomplete.
-
stringToKey
public static Key stringToKey(java.lang.String encoded)
Converts aString-representation of aKeyinto theKeyinstance it represents. Note thatstr.equals(KeyFactory.keyToString(KeyFactory.stringToKey(str))should evaluate totruefor all strings returned bykeyToString(com.google.appengine.api.datastore.Key).- Parameters:
encoded- TheStringrepresentation of aKey.- Returns:
- The
Keythat the givenStringrepresents. - Throws:
java.lang.IllegalArgumentException- If the string cannot be parsed.
-
-