publicfinalclass DatastoreHelper
Static Fields
KEY_PROPERTY_NAME
publicstaticfinalStringKEY_PROPERTY_NAME
The property used in the Datastore to get the key of the entity. *
| Field Value |
| Type |
Description |
String |
LOCAL_HOST_ENV_VAR
publicstaticfinalStringLOCAL_HOST_ENV_VAR
Name of the environment variable used to set the local host.
| Field Value |
| Type |
Description |
String |
PRIVATE_KEY_FILE_ENV_VAR
publicstaticfinalStringPRIVATE_KEY_FILE_ENV_VAR
Name of the environment variable used to set the private key file.
| Field Value |
| Type |
Description |
String |
PROJECT_ID_ENV_VAR
publicstaticfinalStringPROJECT_ID_ENV_VAR
Name of the environment variable used to set the project ID.
| Field Value |
| Type |
Description |
String |
SCATTER_PROPERTY_NAME
publicstaticfinalStringSCATTER_PROPERTY_NAME
The property used in the Datastore to give us a random distribution. *
| Field Value |
| Type |
Description |
String |
SERVICE_ACCOUNT_ENV_VAR
publicstaticfinalStringSERVICE_ACCOUNT_ENV_VAR
Name of the environment variable used to set the service account.
| Field Value |
| Type |
Description |
String |
Static Methods
getBoolean(Value value)
publicstaticbooleangetBoolean(Valuevalue)
| Parameter |
| Name |
Description |
value |
Value
|
| Returns |
| Type |
Description |
boolean |
the boolean contained in value
|
getByteString(Value value)
publicstaticByteStringgetByteString(Valuevalue)
| Parameter |
| Name |
Description |
value |
Value
|
| Returns |
| Type |
Description |
ByteString |
the blob contained in value
|
getDatastoreFromEnv()
publicstaticDatastoregetDatastoreFromEnv()
getDouble(Value value)
publicstaticdoublegetDouble(Valuevalue)
| Parameter |
| Name |
Description |
value |
Value
|
| Returns |
| Type |
Description |
double |
the double contained in value
|
getEntity(Value value)
publicstaticEntitygetEntity(Valuevalue)
| Parameter |
| Name |
Description |
value |
Value
|
| Returns |
| Type |
Description |
Entity |
the entity contained in value
|
getKey(Value value)
publicstaticKeygetKey(Valuevalue)
| Parameter |
| Name |
Description |
value |
Value
|
| Returns |
| Type |
Description |
Key |
the key contained in value
|
getKeyComparator()
publicstaticComparator<Key>getKeyComparator()
getList(Value value)
publicstaticList<Value>getList(Valuevalue)
| Parameter |
| Name |
Description |
value |
Value
|
| Returns |
| Type |
Description |
List<Value> |
the array contained in value as a list.
|
getLong(Value value)
publicstaticlonggetLong(Valuevalue)
| Parameter |
| Name |
Description |
value |
Value
|
| Returns |
| Type |
Description |
long |
the long contained in value
|
getOptionsFromEnv()
publicstaticDatastoreOptions.BuildergetOptionsFromEnv()
Constructs a Datastore from environment variables and/or the Compute Engine metadata
server.
The project ID is determined from, in order of preference:
- DATASTORE_PROJECT_ID environment variable
- Compute Engine
Credentials are taken from, in order of preference:
- No credentials (if the DATASTORE_EMULATOR_HOST environment variable is set)
- Service Account specified by the DATASTORE_SERVICE_ACCOUNT and DATASTORE_PRIVATE_KEY_FILE
environment variables
- Google Application Default as described here.
getProjectIdFromComputeEngine()
publicstaticStringgetProjectIdFromComputeEngine()
Gets the project ID from the Compute Engine metadata server. Returns null if the
project ID cannot be determined (because, for instance, the code is not running on Compute
Engine).
| Returns |
| Type |
Description |
String |
getQuerySplitter()
publicstaticQuerySplittergetQuerySplitter()
getServiceAccountCredential(String serviceAccountId, String privateKeyFile)
publicstaticCredentialgetServiceAccountCredential(StringserviceAccountId,StringprivateKeyFile)
Constructs credentials for the given account and key.
| Parameters |
| Name |
Description |
serviceAccountId |
String
service account ID (typically an e-mail address).
|
privateKeyFile |
String
the file name from which to get the private key.
|
| Returns |
| Type |
Description |
com.google.api.client.auth.oauth2.Credential |
valid credentials or null
|
getServiceAccountCredential(String serviceAccountId, String privateKeyFile, Collection<String> serviceAccountScopes)
publicstaticCredentialgetServiceAccountCredential(StringserviceAccountId,StringprivateKeyFile,Collection<String>serviceAccountScopes)
Constructs credentials for the given account and key file.
| Parameters |
| Name |
Description |
serviceAccountId |
String
service account ID (typically an e-mail address).
|
privateKeyFile |
String
the file name from which to get the private key.
|
serviceAccountScopes |
Collection<String>
Collection of OAuth scopes to use with the the service account flow
or null if not.
|
| Returns |
| Type |
Description |
com.google.api.client.auth.oauth2.Credential |
valid credentials or null
|
getServiceAccountCredential(String serviceAccountId, PrivateKey privateKey, Collection<String> serviceAccountScopes)
publicstaticCredentialgetServiceAccountCredential(StringserviceAccountId,PrivateKeyprivateKey,Collection<String>serviceAccountScopes)
Constructs credentials for the given account and key.
| Parameters |
| Name |
Description |
serviceAccountId |
String
service account ID (typically an e-mail address).
|
privateKey |
PrivateKey
the private key for the given account.
|
serviceAccountScopes |
Collection<String>
Collection of OAuth scopes to use with the the service account flow
or null if not.
|
| Returns |
| Type |
Description |
com.google.api.client.auth.oauth2.Credential |
valid credentials or null
|
getString(Value value)
publicstaticStringgetString(Valuevalue)
| Parameter |
| Name |
Description |
value |
Value
|
| Returns |
| Type |
Description |
String |
the string contained in value
|
getTimestamp(Value value)
publicstaticlonggetTimestamp(Valuevalue)
| Parameter |
| Name |
Description |
value |
Value
|
| Returns |
| Type |
Description |
long |
the timestamp in microseconds contained in value
|
makeAncestorFilter(Key ancestor)
publicstaticFilter.BuildermakeAncestorFilter(Keyancestor)
Makes an ancestor filter.
| Parameter |
| Name |
Description |
ancestor |
Key
|
makeAndFilter(Filter[] subfilters)
publicstaticFilter.BuildermakeAndFilter(Filter[]subfilters)
Make a composite filter from the given sub-filters using AND to combine filters.
| Parameter |
| Name |
Description |
subfilters |
Filter[]
|
makeAndFilter(Iterable<Filter> subfilters)
publicstaticFilter.BuildermakeAndFilter(Iterable<Filter>subfilters)
Make a composite filter from the given sub-filters using AND to combine filters.
makeDelete(Key key)
publicstaticMutation.BuildermakeDelete(Keykey)
| Parameter |
| Name |
Description |
key |
Key
the key of the entity to delete
|
makeFilter(String property, PropertyFilter.Operator operator, Value value)
publicstaticFilter.BuildermakeFilter(Stringproperty,PropertyFilter.Operatoroperator,Valuevalue)
Make a filter on a property for use in a query.
makeFilter(String property, PropertyFilter.Operator operator, Value.Builder value)
publicstaticFilter.BuildermakeFilter(Stringproperty,PropertyFilter.Operatoroperator,Value.Buildervalue)
Make a filter on a property for use in a query.
makeInsert(Entity entity)
publicstaticMutation.BuildermakeInsert(Entityentity)
| Parameter |
| Name |
Description |
entity |
Entity
the entity to insert
|
makeKey(Object[] elements)
publicstaticKey.BuildermakeKey(Object[]elements)
Make a key from the specified path of kind/id-or-name pairs and/or Keys.
The id-or-name values must be either String, Long, Integer or Short.
The last id-or-name value may be omitted, in which case an entity without an id is created
(for use with automatic id allocation).
The PartitionIds of all Keys in the path must be equal. The returned Key.Builder will use
this PartitionId.
| Parameter |
| Name |
Description |
elements |
Object[]
|
makeOrder(String property, PropertyOrder.Direction direction)
publicstaticPropertyOrder.BuildermakeOrder(Stringproperty,PropertyOrder.Directiondirection)
Make a sort order for use in a query.
makePropertyReference(String propertyName)
publicstaticPropertyReference.BuildermakePropertyReference(StringpropertyName)
Make a property reference for use in a query.
| Parameter |
| Name |
Description |
propertyName |
String
|
makeUpdate(Entity entity)
publicstaticMutation.BuildermakeUpdate(Entityentity)
| Parameter |
| Name |
Description |
entity |
Entity
the entity to update
|
makeUpsert(Entity entity)
publicstaticMutation.BuildermakeUpsert(Entityentity)
| Parameter |
| Name |
Description |
entity |
Entity
the entity to upsert
|
makeValue(boolean value)
publicstaticValue.BuildermakeValue(booleanvalue)
| Parameter |
| Name |
Description |
value |
boolean
|
makeValue(Entity entity)
publicstaticValue.BuildermakeValue(Entityentity)
| Parameter |
| Name |
Description |
entity |
Entity
|
makeValue(Entity.Builder entity)
publicstaticValue.BuildermakeValue(Entity.Builderentity)
makeValue(Key key)
publicstaticValue.BuildermakeValue(Keykey)
| Parameter |
| Name |
Description |
key |
Key
|
makeValue(Key.Builder key)
publicstaticValue.BuildermakeValue(Key.Builderkey)
makeValue(Value value1, Value value2, Value[] rest)
publicstaticValue.BuildermakeValue(Valuevalue1,Valuevalue2,Value[]rest)
Make a list value containing the specified values.
makeValue(Value.Builder value1, Value.Builder value2, Value.Builder[] rest)
publicstaticValue.BuildermakeValue(Value.Buildervalue1,Value.Buildervalue2,Value.Builder[]rest)
Make an array value containing the specified values.
makeValue(ByteString blob)
publicstaticValue.BuildermakeValue(ByteStringblob)
makeValue(LatLng value)
publicstaticValue.BuildermakeValue(LatLngvalue)
| Parameter |
| Name |
Description |
value |
com.google.type.LatLng
|
makeValue(LatLng.Builder value)
publicstaticValue.BuildermakeValue(LatLng.Buildervalue)
| Parameter |
| Name |
Description |
value |
com.google.type.LatLng.Builder
|
makeValue(double value)
publicstaticValue.BuildermakeValue(doublevalue)
Make a floating point value.
| Parameter |
| Name |
Description |
value |
double
|
makeValue(Iterable<Value> values)
publicstaticValue.BuildermakeValue(Iterable<Value>values)
Make an array value containing the specified values.
makeValue(String value)
publicstaticValue.BuildermakeValue(Stringvalue)
| Parameter |
| Name |
Description |
value |
String
|
makeValue(Date date)
publicstaticValue.BuildermakeValue(Datedate)
Make a timestamp value given a date.
| Parameter |
| Name |
Description |
date |
Date
|
makeValue(long key)
publicstaticValue.BuildermakeValue(longkey)
| Parameter |
| Name |
Description |
key |
long
|
toDate(Value value)
publicstaticDatetoDate(Valuevalue)
Convert a timestamp value into a Date clipping off the microseconds.
| Parameter |
| Name |
Description |
value |
Value
a timestamp value to convert
|
| Returns |
| Type |
Description |
Date |
the resulting Date
|