public final class DatastoreHelper
Static Fields
KEY_PROPERTY_NAME
public static final String KEY_PROPERTY_NAME
The property used in the Datastore to get the key of the entity. *
Field Value
LOCAL_HOST_ENV_VAR
public static final String LOCAL_HOST_ENV_VAR
Name of the environment variable used to set the local host.
Field Value
PRIVATE_KEY_FILE_ENV_VAR
public static final String PRIVATE_KEY_FILE_ENV_VAR
Name of the environment variable used to set the private key file.
Field Value
PROJECT_ID_ENV_VAR
public static final String PROJECT_ID_ENV_VAR
Name of the environment variable used to set the project ID.
Field Value
SCATTER_PROPERTY_NAME
public static final String SCATTER_PROPERTY_NAME
The property used in the Datastore to give us a random distribution. *
Field Value
SERVICE_ACCOUNT_ENV_VAR
public static final String SERVICE_ACCOUNT_ENV_VAR
Name of the environment variable used to set the service account.
Field Value
Static Methods
getBoolean(Value value)
public static boolean getBoolean(Value value)
Parameter
Name | Description |
value | Value
|
Returns
Type | Description |
boolean | the boolean contained in value
|
getByteString(Value value)
public static ByteString getByteString(Value value)
Parameter
Name | Description |
value | Value
|
Returns
Type | Description |
ByteString | the blob contained in value
|
getDatastoreFromEnv()
public static Datastore getDatastoreFromEnv()
Returns
Exceptions
getDouble(Value value)
public static double getDouble(Value value)
Parameter
Name | Description |
value | Value
|
Returns
Type | Description |
double | the double contained in value
|
getEntity(Value value)
public static Entity getEntity(Value value)
Parameter
Name | Description |
value | Value
|
Returns
Type | Description |
Entity | the entity contained in value
|
getKey(Value value)
public static Key getKey(Value value)
Parameter
Name | Description |
value | Value
|
Returns
Type | Description |
Key | the key contained in value
|
getKeyComparator()
public static Comparator<Key> getKeyComparator()
Returns
getList(Value value)
public static List<Value> getList(Value value)
Parameter
Name | Description |
value | Value
|
Returns
Type | Description |
List<Value> | the array contained in value as a list.
|
getLong(Value value)
public static long getLong(Value value)
Parameter
Name | Description |
value | Value
|
Returns
Type | Description |
long | the long contained in value
|
getOptionsFromEnv()
public static DatastoreOptions.Builder getOptionsFromEnv()
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.
Returns
Exceptions
getProjectIdFromComputeEngine()
public static String getProjectIdFromComputeEngine()
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
getQuerySplitter()
public static QuerySplitter getQuerySplitter()
Returns
getServiceAccountCredential(String serviceAccountId, String privateKeyFile)
public static Credential getServiceAccountCredential(String serviceAccountId, String privateKeyFile)
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
|
Exceptions
getServiceAccountCredential(String serviceAccountId, String privateKeyFile, Collection<String> serviceAccountScopes)
public static Credential getServiceAccountCredential(String serviceAccountId, String privateKeyFile, 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
|
Exceptions
getServiceAccountCredential(String serviceAccountId, PrivateKey privateKey, Collection<String> serviceAccountScopes)
public static Credential getServiceAccountCredential(String serviceAccountId, PrivateKey privateKey, 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
|
Exceptions
getString(Value value)
public static String getString(Value value)
Parameter
Name | Description |
value | Value
|
Returns
Type | Description |
String | the string contained in value
|
getTimestamp(Value value)
public static long getTimestamp(Value value)
Parameter
Name | Description |
value | Value
|
Returns
Type | Description |
long | the timestamp in microseconds contained in value
|
makeAncestorFilter(Key ancestor)
public static Filter.Builder makeAncestorFilter(Key ancestor)
Makes an ancestor filter.
Parameter
Name | Description |
ancestor | Key
|
Returns
makeAndFilter(Filter[] subfilters)
public static Filter.Builder makeAndFilter(Filter[] subfilters)
Make a composite filter from the given sub-filters using AND to combine filters.
Parameter
Name | Description |
subfilters | Filter[]
|
Returns
makeAndFilter(Iterable<Filter> subfilters)
public static Filter.Builder makeAndFilter(Iterable<Filter> subfilters)
Make a composite filter from the given sub-filters using AND to combine filters.
Parameter
Returns
makeDelete(Key key)
public static Mutation.Builder makeDelete(Key key)
Parameter
Name | Description |
key | Key
the key of the entity to delete
|
Returns
makeFilter(String property, PropertyFilter.Operator operator, Value value)
public static Filter.Builder makeFilter(String property, PropertyFilter.Operator operator, Value value)
Make a filter on a property for use in a query.
Parameters
Returns
makeFilter(String property, PropertyFilter.Operator operator, Value.Builder value)
public static Filter.Builder makeFilter(String property, PropertyFilter.Operator operator, Value.Builder value)
Make a filter on a property for use in a query.
Parameters
Returns
makeInsert(Entity entity)
public static Mutation.Builder makeInsert(Entity entity)
Parameter
Name | Description |
entity | Entity
the entity to insert
|
Returns
makeKey(Object[] elements)
public static Key.Builder makeKey(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[]
|
Returns
makeOrder(String property, PropertyOrder.Direction direction)
public static PropertyOrder.Builder makeOrder(String property, PropertyOrder.Direction direction)
Make a sort order for use in a query.
Parameters
Returns
makePropertyReference(String propertyName)
public static PropertyReference.Builder makePropertyReference(String propertyName)
Make a property reference for use in a query.
Parameter
Name | Description |
propertyName | String
|
Returns
makeUpdate(Entity entity)
public static Mutation.Builder makeUpdate(Entity entity)
Parameter
Name | Description |
entity | Entity
the entity to update
|
Returns
makeUpsert(Entity entity)
public static Mutation.Builder makeUpsert(Entity entity)
Parameter
Name | Description |
entity | Entity
the entity to upsert
|
Returns
makeValue(boolean value)
public static Value.Builder makeValue(boolean value)
Parameter
Returns
makeValue(Entity entity)
public static Value.Builder makeValue(Entity entity)
Parameter
Returns
makeValue(Entity.Builder entity)
public static Value.Builder makeValue(Entity.Builder entity)
Parameter
Returns
makeValue(Key key)
public static Value.Builder makeValue(Key key)
Parameter
Returns
makeValue(Key.Builder key)
public static Value.Builder makeValue(Key.Builder key)
Parameter
Returns
makeValue(Value value1, Value value2, Value[] rest)
public static Value.Builder makeValue(Value value1, Value value2, Value[] rest)
Make a list value containing the specified values.
Parameters
Returns
makeValue(Value.Builder value1, Value.Builder value2, Value.Builder[] rest)
public static Value.Builder makeValue(Value.Builder value1, Value.Builder value2, Value.Builder[] rest)
Make an array value containing the specified values.
Parameters
Returns
makeValue(ByteString blob)
public static Value.Builder makeValue(ByteString blob)
Parameter
Returns
makeValue(LatLng value)
public static Value.Builder makeValue(LatLng value)
Parameter
Name | Description |
value | com.google.type.LatLng
|
Returns
makeValue(LatLng.Builder value)
public static Value.Builder makeValue(LatLng.Builder value)
Parameter
Name | Description |
value | com.google.type.LatLng.Builder
|
Returns
makeValue(double value)
public static Value.Builder makeValue(double value)
Make a floating point value.
Parameter
Returns
makeValue(Iterable<Value> values)
public static Value.Builder makeValue(Iterable<Value> values)
Make an array value containing the specified values.
Parameter
Returns
makeValue(String value)
public static Value.Builder makeValue(String value)
Parameter
Returns
makeValue(Date date)
public static Value.Builder makeValue(Date date)
Make a timestamp value given a date.
Parameter
Returns
makeValue(long key)
public static Value.Builder makeValue(long key)
Parameter
Returns
toDate(Value value)
public static Date toDate(Value value)
Convert a timestamp value into a Date clipping off the microseconds.
Parameter
Name | Description |
value | Value
a timestamp value to convert
|
Returns