public class LoaderImpl<L extends Loader> extends SimpleQueryImpl<T> implements Loader, Cloneable
Implementation of the Loader interface. This is also suitable for subclassing; you can return your own subclass by overriding ObjectifyImpl.load().
Modifier and Type | Field and Description |
---|---|
protected LoadArrangement |
loadArrangement |
protected ObjectifyImpl<?> |
ofy |
loader
Constructor and Description |
---|
LoaderImpl(ObjectifyImpl<?> ofy) |
Modifier and Type | Method and Description |
---|---|
protected LoaderImpl<L> |
clone() |
int |
count()
Count the total number of values in the result.
|
<E> Map<Key<E>,E> |
entities(E... entities)
A convenient substitute for entities(Iterable)
|
<E> Map<Key<E>,E> |
entities(Iterable<E> values)
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.
|
LoadResult<T> |
first()
Gets the first entity in the result set.
|
<T> T |
fromEntity(com.google.appengine.api.datastore.Entity entity)
Convert a native datastore Entity into a typed POJO.
|
Set<Class<?>> |
getLoadGroups() |
Objectify |
getObjectify() |
ObjectifyImpl<?> |
getObjectifyImpl() |
L |
group(Class<?>... groups)
Enables one or more fetch groups.
|
com.google.appengine.api.datastore.QueryResultIterable<T> |
iterable()
Starts an asynchronous query which will return entities.
|
com.google.appengine.api.datastore.QueryResultIterator<T> |
iterator() |
<E> LoadResult<E> |
key(Key<E> key)
Load a single entity by key.
|
<E> Map<Key<E>,E> |
keys(Iterable<Key<E>> keys)
Load multiple entities by key from the datastore in a batch.
|
<E> Map<Key<E>,E> |
keys(Key<? extends E>... keys)
A convenient substitute for keys(Iterable)
|
<E> LoadType<E> |
kind(String kind)
Restricts the find operation to entities of a particular kind.
|
List<T> |
list()
Execute the query and get the results as a List.
|
<E> E |
now(Key<E> key)
Get the entity for a key immediately.
|
<E> LoadResult<E> |
ref(Ref<E> ref)
Load a single entity ref.
|
<E> Map<Key<E>,E> |
refs(Iterable<Ref<E>> refs)
Load multiple refs in a batch operation.
|
<E> Map<Key<E>,E> |
refs(Ref<? extends E>... refs)
A convenient substitute for refs(Iterable)
|
<E> LoadType<E> |
type(Class<E> type)
Restricts the find operation to entities of a particular type.
|
<E> LoadResult<E> |
value(Object key)
Load a single entity given any of a variety of acceptable key-like structures.
|
<E> Map<Key<E>,E> |
values(Iterable<?> values)
Fetch multiple entities from the datastore in a batch.
|
<E> Map<Key<E>,E> |
values(Object... values)
A convenient substitute for values(Iterable)
|
ancestor, chunk, chunkAll, distinct, endAt, filterKey, filterKey, hybrid, keys, limit, offset, orderKey, project, reverse, startAt
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
ancestor, chunk, chunkAll, count, distinct, endAt, filterKey, filterKey, hybrid, keys, limit, offset, orderKey, project, reverse, startAt, toString
first, iterable, list
forEach, spliterator
protected ObjectifyImpl<?> ofy
protected LoadArrangement loadArrangement
public LoaderImpl(ObjectifyImpl<?> ofy)
public L group(Class<?>... groups)
Loader
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
, then group(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.
public <E> LoadType<E> type(Class<E> type)
Loader
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.
public <E> LoadType<E> kind(String kind)
Loader
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.
public <E> LoadResult<E> ref(Ref<E> ref)
Loader
Load a single entity ref. This starts an asynchronous fetch operation.
Since fetching is asynchronous,
datastore exceptions
(DatastoreTimeoutException
, ConcurrentModificationException
, DatastoreFailureException
)
can be thrown from Result
operations.
public <E> Map<Key<E>,E> refs(Ref<? extends E>... refs)
Loader
A convenient substitute for refs(Iterable)
public <E> Map<Key<E>,E> refs(Iterable<Ref<E>> refs)
Loader
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.
public <E> LoadResult<E> key(Key<E> key)
Loader
Load a single entity by key. This starts an asynchronous fetch.
Since fetching is asynchronous,
datastore exceptions
(DatastoreTimeoutException
, ConcurrentModificationException
, DatastoreFailureException
)
can be thrown from Result
operations.
public <E> LoadResult<E> entity(E entity)
Loader
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 from Result
operations.
public <E> LoadResult<E> value(Object key)
Loader
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:
Since fetching is asynchronous,
datastore exceptions
(DatastoreTimeoutException
, ConcurrentModificationException
, DatastoreFailureException
)
may be thrown from Result
operations.
public <E> Map<Key<E>,E> keys(Key<? extends E>... keys)
Loader
A convenient substitute for keys(Iterable)
public <E> Map<Key<E>,E> keys(Iterable<Key<E>> keys)
Loader
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.
public <E> Map<Key<E>,E> entities(E... entities)
Loader
A convenient substitute for entities(Iterable)
public <E> Map<Key<E>,E> entities(Iterable<E> values)
Loader
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.
public <E> Map<Key<E>,E> values(Object... values)
Loader
A convenient substitute for values(Iterable)
public <E> Map<Key<E>,E> values(Iterable<?> values)
Loader
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:
Since fetching is asynchronous,
datastore exceptions
(DatastoreTimeoutException
, ConcurrentModificationException
, DatastoreFailureException
)
may be thrown when the Map is accessed.
values
in interface Loader
values
- defines a possibly heterogeneous mixture of Key>, Ref>, native datastore Key, or registered
entity instances with valid id/parent fields.public Objectify getObjectify()
getObjectify
in interface Loader
public Set<Class<?>> getLoadGroups()
getLoadGroups
in interface Loader
public ObjectifyImpl<?> getObjectifyImpl()
public <E> E now(Key<E> key)
Loader
public <T> T fromEntity(com.google.appengine.api.datastore.Entity entity)
Loader
fromEntity
in interface Loader
entity
- is a native datastore entity which has an appropriate kind registered in the ObjectifyFactory.protected LoaderImpl<L> clone()
public LoadResult<T> first()
QueryExecute
public com.google.appengine.api.datastore.QueryResultIterator<T> iterator()
public com.google.appengine.api.datastore.QueryResultIterable<T> iterable()
QueryExecute
Starts an asynchronous query which will return entities.
Note that since the Query
public int count()
SimpleQuery
Count the total number of values in the result. limit and offset are obeyed. This is somewhat faster than fetching, but the time still grows with the number of results. The datastore actually walks through the result set and counts for you.
Immediately executes the query; there is no async version of this method.
WARNING: Each counted entity is billed as a "datastore minor operation". Even though these are free, they may take significant time because they require an index walk.
public List<T> list()
QueryExecute
Execute the query and get the results as a List. The list will be equivalent to a simple ArrayList; you can iterate through it multiple times without incurring additional datastore cost.
Note that you must be careful about limit()ing the size of the list returned; you can easily exceed the practical memory limits of Appengine by querying for a very large dataset.
Copyright © 2016. All rights reserved.