|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.googlecode.objectify.ObjectifyFactory
public class ObjectifyFactory
Factory which allows us to construct implementations of the Objectify interface.
Just call begin().
Note that unlike the DatastoreService, there is no implicit transaction management.
You either create an Objectify without a transaction (by calling begin() or you
create one with a transaction (by calling beginTransaction(). If you create
an Objectify with a transaction, you should use it like this:
Objectify data = factory.beginTransaction()
try {
// do work
data.getTxn().commit();
}
finally {
if (data.getTxn().isActive()) data.getTxn().rollback();
}
ObjectifyFactory is designed to be subclassed; much default behavior can be changed by overriding methods. In particular, see createObjectify(), construct(), getAsyncDatastoreService().
| Field Summary | |
|---|---|
protected EntityMemcache |
entityMemcache
Manages caching of entities at a low level |
static java.lang.String |
MEMCACHE_NAMESPACE
Default memcache namespace; override getRawMemcacheService() to change |
protected EntityMemcacheStats |
memcacheStats
Tracks stats |
protected Registrar |
registrar
Encapsulates entity registration info |
protected TranslatorRegistry |
translators
All the various loaders |
| Constructor Summary | |
|---|---|
ObjectifyFactory()
|
|
| Method Summary | ||
|---|---|---|
|
allocateId(java.lang.Class<T> clazz)
Allocates a single id from the allocator for the specified kind. |
|
|
allocateId(java.lang.Object parentKeyOrEntity,
java.lang.Class<T> clazz)
Allocates a single id from the allocator for the specified kind. |
|
|
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. |
|
|
allocateIds(java.lang.Class<T> clazz,
long num)
Preallocate a contiguous range of unique ids within the namespace of the specified entity class. |
|
|
allocateIds(java.lang.Object parentKeyOrEntity,
java.lang.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. |
|
|
construct(java.lang.Class<T> type)
Construct an instance of the specified type. |
|
|
constructCollection(java.lang.Class<T> type,
int size)
Construct a collection of the specified type and the specified size for use on a POJO field. |
|
|
constructMap(java.lang.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. |
|
|
getKey(java.lang.Object keyOrEntity)
Gets the Key |
|
EntityMemcacheStats |
getMemcacheStats()
Get the object that tracks memcache stats. |
|
|
getMetadata(java.lang.Class<T> clazz)
|
|
|
getMetadata(com.google.appengine.api.datastore.Key key)
|
|
|
getMetadata(Key<T> key)
|
|
|
getMetadata(java.lang.String kind)
Gets metadata for the specified kind, returning null if nothing registered |
|
|
getMetadataForEntity(T obj)
Named differently so you don't accidentally use the Object form |
|
com.google.appengine.api.datastore.Key |
getRawKey(java.lang.Object keyOrEntity)
Gets the raw datstore Key given an object that might be a Key, Key |
|
TranslatorRegistry |
getTranslators()
Gets the master list of all registered TranslatorFactory objects. |
|
|
register(java.lang.Class<T> clazz)
All POJO entity classes which are to be managed by Objectify must be registered first. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String MEMCACHE_NAMESPACE
protected Registrar registrar
protected TranslatorRegistry translators
protected EntityMemcacheStats memcacheStats
protected EntityMemcache entityMemcache
| Constructor Detail |
|---|
public ObjectifyFactory()
| Method Detail |
|---|
public <T> T construct(java.lang.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 java.util.Collection<?>> T constructCollection(java.lang.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 java.util.Map<?,?>> T constructMap(java.lang.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:
public <T> void register(java.lang.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 TranslatorRegistry *before* entity classes are registered.
Attempts to re-register entity classes are ignored.
public EntityMemcacheStats getMemcacheStats()
public <T> EntityMetadata<T> getMetadata(java.lang.Class<T> clazz)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if the kind has not been registeredpublic <T> EntityMetadata<T> getMetadata(com.google.appengine.api.datastore.Key key)
public <T> EntityMetadata<T> getMetadata(Key<T> key)
public <T> EntityMetadata<T> getMetadata(java.lang.String kind)
public <T> EntityMetadata<T> getMetadataForEntity(T obj)
java.lang.IllegalArgumentException - if the kind has not been registeredpublic <T> Key<T> getKey(java.lang.Object keyOrEntity)
Gets the Key
keyOrEntity - must be a Key, Keyjava.lang.NullPointerException - if keyOrEntity is null
java.lang.IllegalArgumentException - if keyOrEntity is not a Key, Keypublic com.google.appengine.api.datastore.Key getRawKey(java.lang.Object keyOrEntity)
Gets the raw datstore Key given an object that might be a Key, Key
keyOrEntity - must be a Key, Keyjava.lang.NullPointerException - if keyOrEntity is null
java.lang.IllegalArgumentException - if keyOrEntity is not a Key, Keypublic <T> Key<T> allocateId(java.lang.Class<T> clazz)
clazz - must be a registered entity class with a Long or long id field.
public <T> Key<T> allocateId(java.lang.Object parentKeyOrEntity,
java.lang.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(java.lang.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 billion
public <T> KeyRange<T> allocateIds(java.lang.Object parentKeyOrEntity,
java.lang.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 TranslatorRegistry 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.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||