Class KeyFactory.Builder (2.0.0)

public static final class KeyFactory.Builder

Helper class that aids in the construction of Keys with ancestors. Initialize the Builder with the topmost ancestor in your key path and then add children using the #addChild overload that best suits your needs. When finished adding children, call #getKey() to retrieve your Key or #getString() to retrieve your Key encoded as a websafe String.

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();
 

Inheritance

java.lang.Object > KeyFactory.Builder

Constructors

Builder(Key key)

public Builder(Key key)

Create a Builder, establishing the provided Key as the topmost ancestor.

Parameter
NameDescription
keyKey

the topmost ancestor

Builder(String kind, String name)

public Builder(String kind, String name)

Create a Builder, establishing a Key constructed from the provided kind and name as the topmost ancestor.

Parameters
NameDescription
kindString

the kind of the topmost ancestor

nameString

the name of the topmost ancestor in kind, as an arbitrary string unique across root entities of this kind

Builder(String kind, long id)

public Builder(String kind, long id)

Create a Builder, establishing a Key constructed from the provided kind and id as the topmost ancestor.

Parameters
NameDescription
kindString

the kind of the topmost ancestor

idlong

the numeric identifier of the topmost ancestor in kind, unique across root entities of this kind, must not be zero

Methods

addChild(String kind, String name)

public KeyFactory.Builder addChild(String kind, String name)

Add a Key constructed from the provided kind and name as the child of the Key most recently added to the Builder.

Parameters
NameDescription
kindString

the kind of the child

nameString

the name of the child in kind, as an arbitrary string unique across entities of this kind with the same parent

Returns
TypeDescription
KeyFactory.Builder

this

addChild(String kind, long id)

public KeyFactory.Builder addChild(String kind, long id)

Add a Key constructed from the provided kind and id as the child of the Key most recently added to the Builder.

Parameters
NameDescription
kindString

the kind of the child

idlong

the numeric identifier of the child in kind, unique across entities of this kind with the same parent, must not be zero

Returns
TypeDescription
KeyFactory.Builder

this

getKey()

public Key getKey()

Returns the most recently added Key.

Returns
TypeDescription
Key

getString()

public String getString()

Returns the most recently added Key, encoded as a websafe String.

Returns
TypeDescription
String