Class DatastoreHelper (2.7.0)

public final class DatastoreHelper

Helper methods for Datastore.

Inheritance

java.lang.Object > 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
TypeDescription
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
TypeDescription
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
TypeDescription
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
TypeDescription
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
TypeDescription
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
TypeDescription
String

Static Methods

getBoolean(Value value)

public static boolean getBoolean(Value value)
Parameter
NameDescription
valueValue
Returns
TypeDescription
boolean

the boolean contained in value

getByteString(Value value)

public static ByteString getByteString(Value value)
Parameter
NameDescription
valueValue
Returns
TypeDescription
ByteString

the blob contained in value

getDatastoreFromEnv()

public static Datastore getDatastoreFromEnv()
Returns
TypeDescription
Datastore
Exceptions
TypeDescription
GeneralSecurityException
IOException

getDouble(Value value)

public static double getDouble(Value value)
Parameter
NameDescription
valueValue
Returns
TypeDescription
double

the double contained in value

getEntity(Value value)

public static Entity getEntity(Value value)
Parameter
NameDescription
valueValue
Returns
TypeDescription
Entity

the entity contained in value

getKey(Value value)

public static Key getKey(Value value)
Parameter
NameDescription
valueValue
Returns
TypeDescription
Key

the key contained in value

getKeyComparator()

public static Comparator<Key> getKeyComparator()
Returns
TypeDescription
Comparator<Key>

getList(Value value)

public static List<Value> getList(Value value)
Parameter
NameDescription
valueValue
Returns
TypeDescription
List<Value>

the array contained in value as a list.

getLong(Value value)

public static long getLong(Value value)
Parameter
NameDescription
valueValue
Returns
TypeDescription
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:

  1. No credentials (if the DATASTORE_EMULATOR_HOST environment variable is set)
  2. Service Account specified by the DATASTORE_SERVICE_ACCOUNT and DATASTORE_PRIVATE_KEY_FILE environment variables
  3. Google Application Default as described here.
Returns
TypeDescription
DatastoreOptions.Builder
Exceptions
TypeDescription
GeneralSecurityException
IOException

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
TypeDescription
String

getQuerySplitter()

public static QuerySplitter getQuerySplitter()

Gets a QuerySplitter.

The returned QuerySplitter#getSplits cannot accept a query that contains inequality filters, a sort filter, or a missing kind.

Returns
TypeDescription
QuerySplitter

getServiceAccountCredential(String serviceAccountId, String privateKeyFile)

public static Credential getServiceAccountCredential(String serviceAccountId, String privateKeyFile)

Constructs credentials for the given account and key.

Parameters
NameDescription
serviceAccountIdString

service account ID (typically an e-mail address).

privateKeyFileString

the file name from which to get the private key.

Returns
TypeDescription
com.google.api.client.auth.oauth2.Credential

valid credentials or null

Exceptions
TypeDescription
GeneralSecurityException
IOException

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
NameDescription
serviceAccountIdString

service account ID (typically an e-mail address).

privateKeyFileString

the file name from which to get the private key.

serviceAccountScopesCollection<String>

Collection of OAuth scopes to use with the the service account flow or null if not.

Returns
TypeDescription
com.google.api.client.auth.oauth2.Credential

valid credentials or null

Exceptions
TypeDescription
GeneralSecurityException
IOException

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
NameDescription
serviceAccountIdString

service account ID (typically an e-mail address).

privateKeyPrivateKey

the private key for the given account.

serviceAccountScopesCollection<String>

Collection of OAuth scopes to use with the the service account flow or null if not.

Returns
TypeDescription
com.google.api.client.auth.oauth2.Credential

valid credentials or null

Exceptions
TypeDescription
GeneralSecurityException
IOException

getString(Value value)

public static String getString(Value value)
Parameter
NameDescription
valueValue
Returns
TypeDescription
String

the string contained in value

getTimestamp(Value value)

public static long getTimestamp(Value value)
Parameter
NameDescription
valueValue
Returns
TypeDescription
long

the timestamp in microseconds contained in value

makeAncestorFilter(Key ancestor)

public static Filter.Builder makeAncestorFilter(Key ancestor)

Makes an ancestor filter.

Parameter
NameDescription
ancestorKey
Returns
TypeDescription
Filter.Builder

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
NameDescription
subfiltersFilter[]
Returns
TypeDescription
Filter.Builder

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
NameDescription
subfiltersIterable<Filter>
Returns
TypeDescription
Filter.Builder

makeDelete(Key key)

public static Mutation.Builder makeDelete(Key key)
Parameter
NameDescription
keyKey

the key of the entity to delete

Returns
TypeDescription
Mutation.Builder

a mutation that will delete an entity

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
NameDescription
propertyString
operatorPropertyFilter.Operator
valueValue
Returns
TypeDescription
Filter.Builder

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
NameDescription
propertyString
operatorPropertyFilter.Operator
valueValue.Builder
Returns
TypeDescription
Filter.Builder

makeInsert(Entity entity)

public static Mutation.Builder makeInsert(Entity entity)
Parameter
NameDescription
entityEntity

the entity to insert

Returns
TypeDescription
Mutation.Builder

a mutation that will insert an entity

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
NameDescription
elementsObject[]
Returns
TypeDescription
Key.Builder

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
NameDescription
propertyString
directionPropertyOrder.Direction
Returns
TypeDescription
PropertyOrder.Builder

makePropertyReference(String propertyName)

public static PropertyReference.Builder makePropertyReference(String propertyName)

Make a property reference for use in a query.

Parameter
NameDescription
propertyNameString
Returns
TypeDescription
PropertyReference.Builder

makeUpdate(Entity entity)

public static Mutation.Builder makeUpdate(Entity entity)
Parameter
NameDescription
entityEntity

the entity to update

Returns
TypeDescription
Mutation.Builder

a mutation that will update an entity

makeUpsert(Entity entity)

public static Mutation.Builder makeUpsert(Entity entity)
Parameter
NameDescription
entityEntity

the entity to upsert

Returns
TypeDescription
Mutation.Builder

a mutation that will upsert an entity

makeValue(boolean value)

public static Value.Builder makeValue(boolean value)

Make a boolean value.

Parameter
NameDescription
valueboolean
Returns
TypeDescription
Value.Builder

makeValue(Entity entity)

public static Value.Builder makeValue(Entity entity)

Make an entity value.

Parameter
NameDescription
entityEntity
Returns
TypeDescription
Value.Builder

makeValue(Entity.Builder entity)

public static Value.Builder makeValue(Entity.Builder entity)

Make a entity value.

Parameter
NameDescription
entityEntity.Builder
Returns
TypeDescription
Value.Builder

makeValue(Key key)

public static Value.Builder makeValue(Key key)

Make a key value.

Parameter
NameDescription
keyKey
Returns
TypeDescription
Value.Builder

makeValue(Key.Builder key)

public static Value.Builder makeValue(Key.Builder key)

Make a key value.

Parameter
NameDescription
keyKey.Builder
Returns
TypeDescription
Value.Builder

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
NameDescription
value1Value
value2Value
restValue[]
Returns
TypeDescription
Value.Builder

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
NameDescription
value1Value.Builder
value2Value.Builder
restBuilder[]
Returns
TypeDescription
Value.Builder

makeValue(ByteString blob)

public static Value.Builder makeValue(ByteString blob)

Make a ByteString value.

Parameter
NameDescription
blobByteString
Returns
TypeDescription
Value.Builder

makeValue(LatLng value)

public static Value.Builder makeValue(LatLng value)

Makes a GeoPoint value.

Parameter
NameDescription
valuecom.google.type.LatLng
Returns
TypeDescription
Value.Builder

makeValue(LatLng.Builder value)

public static Value.Builder makeValue(LatLng.Builder value)

Makes a GeoPoint value.

Parameter
NameDescription
valuecom.google.type.LatLng.Builder
Returns
TypeDescription
Value.Builder

makeValue(double value)

public static Value.Builder makeValue(double value)

Make a floating point value.

Parameter
NameDescription
valuedouble
Returns
TypeDescription
Value.Builder

makeValue(Iterable<Value> values)

public static Value.Builder makeValue(Iterable<Value> values)

Make an array value containing the specified values.

Parameter
NameDescription
valuesIterable<Value>
Returns
TypeDescription
Value.Builder

makeValue(String value)

public static Value.Builder makeValue(String value)

Make a string value.

Parameter
NameDescription
valueString
Returns
TypeDescription
Value.Builder

makeValue(Date date)

public static Value.Builder makeValue(Date date)

Make a timestamp value given a date.

Parameter
NameDescription
dateDate
Returns
TypeDescription
Value.Builder

makeValue(long key)

public static Value.Builder makeValue(long key)

Make an integer value.

Parameter
NameDescription
keylong
Returns
TypeDescription
Value.Builder

toDate(Value value)

public static Date toDate(Value value)

Convert a timestamp value into a Date clipping off the microseconds.

Parameter
NameDescription
valueValue

a timestamp value to convert

Returns
TypeDescription
Date

the resulting Date