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 classKey.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static KeyfromUrlSafe(String urlSafe)Create aKeygiven its URL safe encoded form.LonggetId()Returns the key's id ornullif it has a name instead.StringgetName()Returns the key's name ornullif it has an id instead.ObjectgetNameOrId()booleanhasId()booleanhasName()static Key.BuildernewBuilder(IncompleteKey copyFrom, long id)static Key.BuildernewBuilder(IncompleteKey copyFrom, String name)static Key.BuildernewBuilder(Key copyFrom)static Key.BuildernewBuilder(Key parent, String kind, long id)static Key.BuildernewBuilder(Key parent, String kind, String name)static Key.BuildernewBuilder(String projectId, String kind, long id)static Key.BuildernewBuilder(String projectId, String kind, long id, String databaseId)static Key.BuildernewBuilder(String projectId, String kind, String name)static Key.BuildernewBuilder(String projectId, String kind, String name, String databaseId)StringtoUrlSafe()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 ornullif it has a name instead.
-
hasName
public boolean hasName()
-
getName
public String getName()
Returns the key's name ornullif 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 aKeygiven 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)
-
-