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 |
---|
Type | Description |
String | |
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 |
---|
Type | Description |
String | |
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 |
---|
Type | Description |
String | |
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 |
---|
Type | Description |
String | |
SCATTER_PROPERTY_NAME
public static final String SCATTER_PROPERTY_NAME
The property used in the Datastore to give us a random distribution. *
Field Value |
---|
Type | Description |
String | |
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 |
---|
Type | Description |
String | |
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()
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()
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.
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).
getQuerySplitter()
public static QuerySplitter getQuerySplitter()
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
|
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
|
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
|
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
|
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[]
|
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.
makeDelete(Key key)
public static Mutation.Builder makeDelete(Key key)
Parameter |
---|
Name | Description |
key | Key
the key of the entity to delete
|
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.
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.
makeInsert(Entity entity)
public static Mutation.Builder makeInsert(Entity entity)
Parameter |
---|
Name | Description |
entity | Entity
the entity to insert
|
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[]
|
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.
makePropertyReference(String propertyName)
public static PropertyReference.Builder makePropertyReference(String propertyName)
Make a property reference for use in a query.
Parameter |
---|
Name | Description |
propertyName | String
|
makeUpdate(Entity entity)
public static Mutation.Builder makeUpdate(Entity entity)
Parameter |
---|
Name | Description |
entity | Entity
the entity to update
|
makeUpsert(Entity entity)
public static Mutation.Builder makeUpsert(Entity entity)
Parameter |
---|
Name | Description |
entity | Entity
the entity to upsert
|
makeValue(boolean value)
public static Value.Builder makeValue(boolean value)
Parameter |
---|
Name | Description |
value | boolean
|
makeValue(Entity entity)
public static Value.Builder makeValue(Entity entity)
Parameter |
---|
Name | Description |
entity | Entity
|
makeValue(Entity.Builder entity)
public static Value.Builder makeValue(Entity.Builder entity)
makeValue(Key key)
public static Value.Builder makeValue(Key key)
Parameter |
---|
Name | Description |
key | Key
|
makeValue(Key.Builder key)
public static Value.Builder makeValue(Key.Builder key)
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.
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.
makeValue(ByteString blob)
public static Value.Builder makeValue(ByteString blob)
makeValue(LatLng value)
public static Value.Builder makeValue(LatLng value)
Parameter |
---|
Name | Description |
value | com.google.type.LatLng
|
makeValue(LatLng.Builder value)
public static Value.Builder makeValue(LatLng.Builder value)
Parameter |
---|
Name | Description |
value | com.google.type.LatLng.Builder
|
makeValue(double value)
public static Value.Builder makeValue(double value)
Make a floating point value.
Parameter |
---|
Name | Description |
value | double
|
makeValue(Iterable<Value> values)
public static Value.Builder makeValue(Iterable<Value> values)
Make an array value containing the specified values.
makeValue(String value)
public static Value.Builder makeValue(String value)
Parameter |
---|
Name | Description |
value | String
|
makeValue(Date date)
public static Value.Builder makeValue(Date date)
Make a timestamp value given a date.
Parameter |
---|
Name | Description |
date | Date
|
makeValue(long key)
public static Value.Builder makeValue(long key)
Parameter |
---|
Name | Description |
key | long
|
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 |
---|
Type | Description |
Date | the resulting Date
|