public class ObjectifyFactory extends Object implements Forge
Factory which allows us to construct implementations of the Objectify interface. You should usually use the ObjectifyService to access Objectify.
ObjectifyFactory is designed to be subclassed; much default behavior can be changed by overriding methods. In particular, see createObjectify(), construct(), getAsyncDatastoreService().
Modifier and Type | Field and Description |
---|---|
protected EntityMemcache |
entityMemcache
Manages caching of entities at a low level
|
protected Keys |
keys
Some useful bits for working with keys
|
static String |
MEMCACHE_NAMESPACE
Default memcache namespace
|
protected EntityMemcacheStats |
memcacheStats
Tracks stats
|
protected Registrar |
registrar
Encapsulates entity registration info
|
protected Translators |
translators
All the various loaders
|
Constructor and Description |
---|
ObjectifyFactory() |
Modifier and Type | Method and Description |
---|---|
<T> Key<T> |
allocateId(Class<T> clazz)
Allocates a single id from the allocator for the specified kind.
|
<T> Key<T> |
allocateId(Object parentKeyOrEntity,
Class<T> clazz)
Allocates a single id from the allocator for the specified kind.
|
<T> com.google.appengine.api.datastore.DatastoreService.KeyRangeState |
allocateIdRange(KeyRange<T> range)
Allocates a user-specified contiguous range of unique IDs, preventing the allocator from
giving them out to entities (with autogeneration) or other calls to allocate methods.
|
<T> KeyRange<T> |
allocateIds(Class<T> clazz,
long num)
Preallocate a contiguous range of unique ids within the namespace of the
specified entity class.
|
<T> KeyRange<T> |
allocateIds(Object parentKeyOrEntity,
Class<T> clazz,
long num)
Preallocate a contiguous range of unique ids within the namespace of the
specified entity class and the parent key.
|
Objectify |
begin()
This is the beginning of any Objectify session.
|
<T> T |
construct(Class<T> type)
Construct an instance of the specified type.
|
<T extends Collection<?>> |
constructCollection(Class<T> type,
int size)
Construct a collection of the specified type and the specified size for use on a POJO field.
|
<T extends Map<?,?>> |
constructMap(Class<T> type)
Construct a map of the specified type for use on a POJO field.
|
com.google.appengine.api.datastore.AsyncDatastoreService |
createAsyncDatastoreService(com.google.appengine.api.datastore.DatastoreServiceConfig cfg,
boolean globalCache)
Get an AsyncDatastoreService facade appropriate to the options.
|
protected com.google.appengine.api.datastore.AsyncDatastoreService |
createRawAsyncDatastoreService(com.google.appengine.api.datastore.DatastoreServiceConfig cfg)
You can override this to add behavior at the raw datastoreservice level.
|
EntityMemcacheStats |
getMemcacheStats()
Get the object that tracks memcache stats.
|
<T> EntityMetadata<T> |
getMetadata(Class<T> clazz) |
<T> EntityMetadata<T> |
getMetadata(com.google.appengine.api.datastore.Key key) |
<T> EntityMetadata<T> |
getMetadata(Key<T> key) |
<T> EntityMetadata<T> |
getMetadata(String kind)
Gets metadata for the specified kind, returning null if nothing registered.
|
<T> EntityMetadata<T> |
getMetadataForEntity(T obj)
Named differently so you don't accidentally use the Object form
|
Translators |
getTranslators()
Gets the master list of all registered TranslatorFactory objects.
|
Keys |
keys()
Some tools for working with keys.
|
<T> void |
register(Class<T> clazz)
All POJO entity classes which are to be managed by Objectify
must be registered first.
|
void |
setMemcacheErrorHandler(com.google.appengine.api.memcache.ErrorHandler handler)
Sets the error handler for the main memcache object.
|
public static final String MEMCACHE_NAMESPACE
protected Registrar registrar
protected Keys keys
protected Translators translators
protected EntityMemcacheStats memcacheStats
protected EntityMemcache entityMemcache
public <T> T construct(Class<T> type)
Construct an instance of the specified type. Objectify uses this method whenever possible to create instances of entities, condition classes, or other types; by overriding this method you can substitute Guice or other dependency injection mechanisms. By default it constructs with a simple no-args constructor.
public <T extends Collection<?>> T constructCollection(Class<T> type, int size)
Construct a collection of the specified type and the specified size for use on a POJO field. You can override this with Guice or whatnot.
The default is to call construct(Class), with one twist - if a Set, SortedSet, or List interface is presented, Objectify will construct a HashSet, TreeSet, or ArrayList (respectively). If you override this method with dependency injection and you use uninitialized fields of these interface types in your entity pojos, you will need to bind these interfaces to concrete types.
public <T extends Map<?,?>> T constructMap(Class<T> type)
Construct a map of the specified type for use on a POJO field. You can override this with Guice or whatnot.
The default is to call construct(Class), with one twist - if a Map or SortedMap List interface is presented, Objectify will construct a HashMap or TreeMap (respectively). If you override this method with dependency injection and you use uninitialized fields of these interface types in your entity pojos, you will need to bind these interfaces to concrete types.
public com.google.appengine.api.datastore.AsyncDatastoreService createAsyncDatastoreService(com.google.appengine.api.datastore.DatastoreServiceConfig cfg, boolean globalCache)
protected com.google.appengine.api.datastore.AsyncDatastoreService createRawAsyncDatastoreService(com.google.appengine.api.datastore.DatastoreServiceConfig cfg)
public Objectify begin()
The default options are:
Note that when using Objectify you will almost never directly call this method. Instead you should call the static ofy() method on ObjectifyService.
public <T> void register(Class<T> clazz)
All POJO entity classes which are to be managed by Objectify must be registered first. This method must be called in a single-threaded mode sometime around application initialization.
Any extra translators must be added to the Translators *before* entity classes are registered.
Attempts to re-register entity classes are ignored.
public EntityMemcacheStats getMemcacheStats()
public void setMemcacheErrorHandler(com.google.appengine.api.memcache.ErrorHandler handler)
public <T> EntityMetadata<T> getMetadata(Class<T> clazz) throws IllegalArgumentException
IllegalArgumentException
- if the kind has not been registeredpublic <T> EntityMetadata<T> getMetadata(com.google.appengine.api.datastore.Key key) throws IllegalArgumentException
IllegalArgumentException
- if the kind has not been registeredpublic <T> EntityMetadata<T> getMetadata(Key<T> key) throws IllegalArgumentException
IllegalArgumentException
- if the kind has not been registeredpublic <T> EntityMetadata<T> getMetadata(String kind)
public <T> EntityMetadata<T> getMetadataForEntity(T obj) throws IllegalArgumentException
IllegalArgumentException
- if the kind has not been registeredpublic <T> Key<T> allocateId(Class<T> clazz)
clazz
- must be a registered entity class with a Long or long id field.public <T> Key<T> allocateId(Object parentKeyOrEntity, Class<T> clazz)
parentKeyOrEntity
- must be a legitimate parent for the class type. It need not
point to an existent entity, but it must be the correct type for clazz.clazz
- must be a registered entity class with a Long or long id field, and
a parent key of the correct type.public <T> KeyRange<T> allocateIds(Class<T> clazz, long num)
clazz
- must be a registered entity class with a Long or long id field.num
- must be >= 1 and <= 1 billionpublic <T> KeyRange<T> allocateIds(Object parentKeyOrEntity, Class<T> clazz, long num)
parentKeyOrEntity
- must be a legitimate parent for the class type. It need not
point to an existent entity, but it must be the correct type for clazz.clazz
- must be a registered entity class with a Long or long id field, and
a parent key of the correct type.num
- must be >= 1 and <= 1 billionpublic <T> com.google.appengine.api.datastore.DatastoreService.KeyRangeState allocateIdRange(KeyRange<T> range)
public Translators getTranslators()
Gets the master list of all registered TranslatorFactory objects. By adding Translators, Objectify can process additional field types which are not part of the standard GAE SDK. You must add translators *before* registering entity pojo classes.
public Keys keys()
Copyright © 2016. All rights reserved.