|
|||||||||
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();
}
It would be fairly easy for someone to implement a ScanningObjectifyFactory on top of this class that looks for @Entity annotations based on Scannotation or Reflections, but this would add extra dependency jars and need a hook for application startup.
Field Summary | |
---|---|
protected Conversions |
conversions
All the various converters |
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 |
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()
Create a lightweight Objectify instance with the default options. |
|
Objectify |
begin(ObjectifyOpts opts)
|
|
Objectify |
beginTransaction()
|
|
protected ObjectifyOpts |
createDefaultOpts()
Creates the default options for begin() and beginTransaction(). |
|
protected Objectify |
createObjectify(com.google.appengine.api.datastore.AsyncDatastoreService ds,
ObjectifyOpts opts)
Override this in your factory if you wish to use a different impl, say, one based on the ObjectifyWrapper. |
|
com.google.appengine.api.datastore.AsyncDatastoreService |
getAsyncDatastoreService(ObjectifyOpts opts)
Get an AsyncDatastoreService facade appropriate to the options. |
|
Conversions |
getConversions()
|
|
com.google.appengine.api.datastore.DatastoreService |
getDatastoreService(ObjectifyOpts opts)
Get a DatastoreService facade appropriate to the options. |
|
|
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, or throws an exception if the kind is unknown |
|
|
getMetadataForEntity(T obj)
Named differently so you don't accidentally use the Object form |
|
protected com.google.appengine.api.datastore.AsyncDatastoreService |
getRawAsyncDatastoreService(com.google.appengine.api.datastore.DatastoreServiceConfig cfg)
You can override this to add behavior at the raw datastoreservice level. |
|
protected com.google.appengine.api.datastore.DatastoreService |
getRawDatastoreService(com.google.appengine.api.datastore.DatastoreServiceConfig cfg)
You can override this to add behavior at the raw datastoreservice level. |
|
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 |
|
java.lang.String |
keyToString(Key<?> key)
Converts a Key> into a web-safe string suitable for http parameters in URLs. |
|
protected com.google.appengine.api.datastore.DatastoreServiceConfig |
makeConfig(ObjectifyOpts opts)
Make a datastore service config that corresponds to the specified options. |
|
java.lang.Object |
makeFilterable(java.lang.Object keyOrEntityOrOther)
Translate Key> or Entity objects into something that can be used in a filter clause. |
|
|
register(java.lang.Class<T> clazz)
All POJO entity classes which are to be managed by Objectify must be registered first. |
|
|
stringToKey(java.lang.String stringifiedKey)
Converts a String generated with keyToString() back into an Objectify
Key. |
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 Conversions conversions
protected EntityMemcacheStats memcacheStats
protected EntityMemcache entityMemcache
Constructor Detail |
---|
public ObjectifyFactory()
Method Detail |
---|
protected ObjectifyOpts createDefaultOpts()
protected Objectify createObjectify(com.google.appengine.api.datastore.AsyncDatastoreService ds, ObjectifyOpts opts)
ds
- the DatastoreServiceopts
- the options for creating this Objectify
protected com.google.appengine.api.datastore.DatastoreServiceConfig makeConfig(ObjectifyOpts opts)
public com.google.appengine.api.datastore.DatastoreService getDatastoreService(ObjectifyOpts opts)
public com.google.appengine.api.datastore.AsyncDatastoreService getAsyncDatastoreService(ObjectifyOpts opts)
protected com.google.appengine.api.datastore.DatastoreService getRawDatastoreService(com.google.appengine.api.datastore.DatastoreServiceConfig cfg)
protected com.google.appengine.api.datastore.AsyncDatastoreService getRawAsyncDatastoreService(com.google.appengine.api.datastore.DatastoreServiceConfig cfg)
public Objectify begin()
public Objectify begin(ObjectifyOpts opts)
public Objectify beginTransaction()
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.
public EntityMemcacheStats getMemcacheStats()
public <T> EntityMetadata<T> getMetadata(com.google.appengine.api.datastore.Key key)
java.lang.IllegalArgumentException
- if the kind has not been registeredpublic <T> EntityMetadata<T> getMetadata(Key<T> key)
java.lang.IllegalArgumentException
- if the kind has not been registeredpublic <T> EntityMetadata<? extends T> getMetadata(java.lang.Class<T> clazz)
java.lang.IllegalArgumentException
- if the kind has not been registeredpublic <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 java.lang.Object makeFilterable(java.lang.Object keyOrEntityOrOther)
public java.lang.String keyToString(Key<?> key)
Converts a Key> into a web-safe string suitable for http parameters
in URLs. Note that you can convert back and forth with the keyToString()
and stringToKey()
methods.
The String is actually generated by using the KeyFactory keyToString()
method on a raw version of the datastore key. You can, if you wanted, use
these web safe strings interchangeably.
key
- is any Objectify key
public <T> Key<T> stringToKey(java.lang.String stringifiedKey)
keyToString()
back into an Objectify
Key. The String could also have been generated by the GAE KeyFactory
.
stringifiedKey
- is generated by either ObjectifyFactory.keyToString()
or
KeyFactory.keyToString()
.
public <T> long allocateId(java.lang.Class<T> clazz)
clazz
- must be a registered entity class with a Long or long id field.public <T> long 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 billionpublic <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 Conversions getConversions()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |