Package com.google.cloud.datastore
Class Key
- java.lang.Object
-
- com.google.cloud.datastore.BaseKey
-
- com.google.cloud.datastore.IncompleteKey
-
- com.google.cloud.datastore.Key
-
- All Implemented Interfaces:
Serializable
public final class Key extends IncompleteKey
A key that is guaranteed to be complete and could be used to reference a Google Cloud DatastoreEntity
. This class is immutable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Key.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Key
fromUrlSafe(String urlSafe)
Create aKey
given its URL safe encoded form.Long
getId()
Returns the key's id ornull
if it has a name instead.String
getName()
Returns the key's name ornull
if it has an id instead.Object
getNameOrId()
boolean
hasId()
boolean
hasName()
static Key.Builder
newBuilder(IncompleteKey copyFrom, long id)
static Key.Builder
newBuilder(IncompleteKey copyFrom, String name)
static Key.Builder
newBuilder(Key copyFrom)
static Key.Builder
newBuilder(Key parent, String kind, long id)
static Key.Builder
newBuilder(Key parent, String kind, String name)
static Key.Builder
newBuilder(String projectId, String kind, long id)
static Key.Builder
newBuilder(String projectId, String kind, long id, String databaseId)
static Key.Builder
newBuilder(String projectId, String kind, String name)
static Key.Builder
newBuilder(String projectId, String kind, String name, String databaseId)
String
toUrlSafe()
Returns the key in an encoded form that can be used as part of a URL.-
Methods inherited from class com.google.cloud.datastore.IncompleteKey
getParent, newBuilder, newBuilder, newBuilder, newBuilderWithDatabaseId
-
Methods inherited from class com.google.cloud.datastore.BaseKey
equals, getAncestors, getDatabaseId, getKind, getNamespace, getProjectId, hashCode, toString
-
-
-
-
Method Detail
-
hasId
public boolean hasId()
-
getId
public Long getId()
Returns the key's id ornull
if it has a name instead.
-
hasName
public boolean hasName()
-
getName
public String getName()
Returns the key's name ornull
if it has an id instead.
-
getNameOrId
public Object getNameOrId()
-
toUrlSafe
public String toUrlSafe()
Returns the key in an encoded form that can be used as part of a URL.
-
fromUrlSafe
public static Key fromUrlSafe(String urlSafe)
Create aKey
given its URL safe encoded form.- Throws:
IllegalArgumentException
- when decoding fails
-
newBuilder
public static Key.Builder newBuilder(String projectId, String kind, String name)
-
newBuilder
@BetaApi public static Key.Builder newBuilder(String projectId, String kind, String name, String databaseId)
-
newBuilder
public static Key.Builder newBuilder(String projectId, String kind, long id)
-
newBuilder
@BetaApi public static Key.Builder newBuilder(String projectId, String kind, long id, String databaseId)
-
newBuilder
public static Key.Builder newBuilder(Key copyFrom)
-
newBuilder
public static Key.Builder newBuilder(IncompleteKey copyFrom, String name)
-
newBuilder
public static Key.Builder newBuilder(IncompleteKey copyFrom, long id)
-
newBuilder
public static Key.Builder newBuilder(Key parent, String kind, String name)
-
newBuilder
public static Key.Builder newBuilder(Key parent, String kind, long id)
-
-