Interface Loader
- All Superinterfaces:
Iterable<Object>
,QueryExecute<Object>
,QueryResultIterable<Object>
,SimpleQuery<Object>
The top element in the command chain for retrieving entities from the datastore.
At this point you can enable load groups with group()
, start all-kinds
queries by calling query-related methods (see SimpleQuery), load entities by key or ref,
or narrow your interest to a specific kind by calling type()
.
All command objects are immutable.
- Author:
- Jeff Schnitzer invalid input: '<'[email protected]>
-
Method Summary
Modifier and TypeMethodDescriptionentities
(E... entities) A convenient substitute for entities(Iterable)Load multiple entities from the datastore in a batch.<E> LoadResult<E>
entity
(E entity) Load a single entity which has the same id/parent as the specified entity.<T> T
fromEntity
(com.google.cloud.datastore.Entity entity) Convert a native datastore Entity into a typed POJO.Enables one or more fetch groups.<E> LoadResult<E>
Load a single entity by key.A convenient substitute for keys(Iterable)Load multiple entities by key from the datastore in a batch.<E> LoadType<E>
Restricts the find operation to entities of a particular kind.<E> E
Get the entity for a key immediately.option
(com.google.cloud.datastore.ReadOption... option) Enable the specified read option for this load.<E> LoadResult<E>
Load a single entity ref.A convenient substitute for refs(Iterable)Load multiple refs in a batch operation.<E> LoadType<E>
Restricts the find operation to entities of a particular type.<E> LoadResult<E>
Load a single entity given any of a variety of acceptable key-like structures.Fetch multiple entities from the datastore in a batch.A convenient substitute for values(Iterable)Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface com.googlecode.objectify.cmd.QueryExecute
first, iterable, list, stream
Methods inherited from interface com.googlecode.objectify.cmd.QueryResultIterable
iterator
-
Method Details
-
group
Enables one or more fetch groups. This will cause any entity fields (or Ref fields) which are annotated with @Load(XYZGroup.class) to be fetched along with your entities. The class definition can be any arbitrary class, but inheritance is respected - if you have a
class Foo extends Bar
, thengroup(Foo.class)
will cause loading of all@Load(Bar.class)
properties.Calling this method multiple times is the same as passing all the groups into one call.
All command objects are immutable; this method returns a new object instead of modifying the current command object.
- Parameters:
groups
- are one or more load groups to enable. They can be any arbitrary class.- Returns:
- a continuation of the immutable command pattern, enabled for fetching this group.
-
option
Enable the specified read option for this load.- Parameters:
option
- is defined by the Google Cloud SDK.- Returns:
- a continuation of the immutable command pattern, with the specified option enabled
-
type
Restricts the find operation to entities of a particular type. The type may be the base of a polymorphic class hierarchy. This is optional.
All command objects are immutable; this method returns a new object instead of modifying the current command object.
- Parameters:
type
- is the type of entity (or entities) to retrieve, possibly a base class for a polymorphic hierarchy- Returns:
- the next step in the immutable command chain, which allows you to start a query or define keys for a batch get.
-
kind
Restricts the find operation to entities of a particular kind. This is similar to type() but lets you specify any arbitrary kind string. You'll typically only use this if you are also working with the low level api directly.
All command objects are immutable; this method returns a new object instead of modifying the current command object.
- Parameters:
kind
- is the kind of entity (or entities) to retrieve- Returns:
- the next step in the immutable command chain, which allows you to start a query or define keys for a batch get.
-
ref
Load a single entity ref. This starts an asynchronous fetch operation.
Since fetching is asynchronous, datastore exceptions (
DatastoreTimeoutException
,ConcurrentModificationException
,DatastoreFailureException
) can be thrown fromResult
operations.- Parameters:
ref
- holds the key to fetch and will receive the asynchronous result.- Returns:
- a result which can materialize the entity.
-
refs
Load multiple refs in a batch operation. This starts an asynchronous fetch.
Since fetching is asynchronous, datastore exceptions (
DatastoreTimeoutException
,ConcurrentModificationException
,DatastoreFailureException
) can be thrown from the map operations.- Parameters:
refs
- provide the keys to fetch and will receive the asynchronous result.- Returns:
- as an alternative to accessing the Refs directly, a Map of the asynchronous result.
-
refs
A convenient substitute for refs(Iterable)
-
key
Load a single entity by key. This starts an asynchronous fetch.
Since fetching is asynchronous, datastore exceptions (
DatastoreTimeoutException
,ConcurrentModificationException
,DatastoreFailureException
) can be thrown fromResult
operations.- Parameters:
key
- defines the entity to fetch- Returns:
- a result which can materialize the entity
-
keys
Load multiple entities by key from the datastore in a batch. This starts an asynchronous fetch.
Since fetching is asynchronous, datastore exceptions (
DatastoreTimeoutException
,ConcurrentModificationException
,DatastoreFailureException
) will be thrown when the Map is accessed.- Parameters:
keys
- are the keys to fetch- Returns:
- a Map of the asynchronous result. The fetch will be completed when the Map is first accessed.
-
keys
A convenient substitute for keys(Iterable)
-
entity
Load a single entity which has the same id/parent as the specified entity. This starts an asynchronous fetch.
This is a shortcut for
key(Key.create(entity))
.Since fetching is asynchronous, datastore exceptions (
DatastoreTimeoutException
,ConcurrentModificationException
,DatastoreFailureException
) may be thrown fromResult
operations.- Parameters:
entity
- defines the entity to fetch; it must be of a registered entity type and have valid id/parent fields.- Returns:
- a result which can materialize the entity
-
entities
Load multiple entities from the datastore in a batch. This starts an asynchronous fetch.
Since fetching is asynchronous, datastore exceptions (
DatastoreTimeoutException
,ConcurrentModificationException
,DatastoreFailureException
) may be thrown when the Map is accessed.- Parameters:
entities
- must be a list of objects which belong to registered entity types, and must have id invalid input: '&' parent fields properly set.- Returns:
- a Map of the asynchronous result. The fetch will be completed when the Map is first accessed.
-
entities
A convenient substitute for entities(Iterable)
-
value
Load a single entity given any of a variety of acceptable key-like structures. This starts an asynchronous fetch.
The parameter can be any key-like structure, including:
- Standard Objectify Keyinvalid input: '<'?> objects.
- Native datastore Key objects.
- Refinvalid input: '<'?> objects.
- Registered entity instances which have id and parent fields populated.
Since fetching is asynchronous, datastore exceptions (
DatastoreTimeoutException
,ConcurrentModificationException
,DatastoreFailureException
) may be thrown fromResult
operations.- Parameters:
key
- defines the entity to fetch; can be anything that represents a key structure- Returns:
- a Refinvalid input: '<'?> which holds the asynchronous result
-
values
Fetch multiple entities from the datastore in a batch. This starts an asynchronous fetch.
The parameters can be any mix of key-like structures, including:
- Standard Objectify Keyinvalid input: '<'?> objects.
- Native datastore Key objects.
- Refinvalid input: '<'?> objects.
- Registered entity instances which have id and parent fields populated.
Since fetching is asynchronous, datastore exceptions (
DatastoreTimeoutException
,ConcurrentModificationException
,DatastoreFailureException
) may be thrown when the Map is accessed.- Parameters:
keysOrEntities
- defines a possibly heterogeneous mixture of Keyinvalid input: '<'?>, Refinvalid input: '<'?>, native datastore Key, or registered entity instances with valid id/parent fields.- Returns:
- a Map of the asynchronous result. The fetch will be completed when the Map is first accessed.
-
values
A convenient substitute for values(Iterable)
-
getObjectify
Objectify getObjectify()- Returns:
- the parent Objectify instance
-
getLoadGroups
- Returns:
- the currently enabled load groups in an unmodifiable list
-
fromEntity
<T> T fromEntity(com.google.cloud.datastore.Entity entity) Convert a native datastore Entity into a typed POJO. This is like a load() operation except that you start with the native datastore type instead of fetching it from the datastore. However, note that because of @Load annotations, it is possible that datastore operations will be executed during the translation.- Parameters:
entity
- is a native datastore entity which has an appropriate kind registered in the ObjectifyFactory.- Returns:
- the POJO equivalent, just as if you had loaded the entity directly from Objectify.
-
now
Get the entity for a key immediately. You rarely, if ever, should want to use this; it exists to support Refinvalid input: '<'?> behavior. Value will be loaded from the session if available, but will go to the datastore if necessary. It is synchronous.
-