com.google.appengine.api.datastore
Class KeyFactory.Builder
- java.lang.Object
-
- com.google.appengine.api.datastore.KeyFactory.Builder
-
- Enclosing class:
- KeyFactory
public static final class KeyFactory.Builder extends java.lang.Object
Helper class that aids in the construction ofKeys
with ancestors. Initialize theBuilder
with the topmost ancestor in your key path and then add children using theaddChild(java.lang.String, java.lang.String)
overload that best suits your needs. When finished adding children, callgetKey()
to retrieve yourKey
orgetString()
to retrieve yourKey
encoded as a websafeString
.Examples:
import com.google.appengine.api.datastore.KeyFactory.Builder; ... Key key = new Builder("Person", 88).addChild("Address", 24).getKey(); String keyStr = new Builder("Photo Album", "Vacation").addChild("Photo", 1424).getString();
-
-
Constructor Summary
Constructors Constructor and Description Builder(Key key)
Create aBuilder
, establishing the providedKey
as the topmost ancestor.Builder(java.lang.String kind, long id)
Create aBuilder
, establishing aKey
constructed from the provided kind and id as the topmost ancestor.Builder(java.lang.String kind, java.lang.String name)
Create aBuilder
, establishing aKey
constructed from the provided kind and name as the topmost ancestor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description KeyFactory.Builder
addChild(java.lang.String kind, long id)
KeyFactory.Builder
addChild(java.lang.String kind, java.lang.String name)
Key
getKey()
java.lang.String
getString()
-
-
-
Constructor Detail
-
Builder
public Builder(java.lang.String kind, java.lang.String name)
Create aBuilder
, establishing aKey
constructed from the provided kind and name as the topmost ancestor.- Parameters:
kind
- the kind of the topmost ancestorname
- the name of the topmost ancestor inkind
, as an arbitrary string unique across root entities of thiskind
-
Builder
public Builder(java.lang.String kind, long id)
Create aBuilder
, establishing aKey
constructed from the provided kind and id as the topmost ancestor.- Parameters:
kind
- the kind of the topmost ancestorid
- the numeric identifier of the topmost ancestor inkind
, unique across root entities of this kind, must not be zero
-
-
Method Detail
-
addChild
public KeyFactory.Builder addChild(java.lang.String kind, java.lang.String name)
Add aKey
constructed from the provided kind and name as the child of theKey
most recently added to theBuilder
.- Parameters:
kind
- the kind of the childname
- the name of the child inkind
, as an arbitrary string unique across entities of thiskind
with the same parent- Returns:
this
-
addChild
public KeyFactory.Builder addChild(java.lang.String kind, long id)
Add aKey
constructed from the provided kind and id as the child of theKey
most recently added to theBuilder
.- Parameters:
kind
- the kind of the childid
- the numeric identifier of the child inkind
, unique across entities of this kind with the same parent, must not be zero- Returns:
this
-
getString
public java.lang.String getString()
- Returns:
- The most recently added
Key
, encoded as a websafeString
.
-
-