Class ObjectifyService
- java.lang.Object
-
- com.googlecode.objectify.ObjectifyService
-
public class ObjectifyService extends Object
Holder of the master ObjectifyFactory and provider of the current thread-local Objectify instance. Callofy()
at any point to get the current Objectify with the correct transaction context.- Author:
- Jeff Schnitzer
-
-
Constructor Summary
Constructors Constructor Description ObjectifyService()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Closeable
begin()
An alternative to run() which is somewhat easier to use with testing (ie, @Before and @After) frameworks.static ObjectifyFactory
factory()
static void
init()
This is a shortcut forObjectifyService.init(new ObjectifyFactory())
static void
init(ObjectifyFactory fact)
static Objectify
ofy()
The method to call at any time to get the current Objectify, which may change depending on txn contextstatic void
register(Class<?> clazz)
A shortcut forfactory().register()
static <R> R
run(Work<R> work)
Runs one unit of work, making the root Objectify context available.
-
-
-
Method Detail
-
init
public static void init()
This is a shortcut forObjectifyService.init(new ObjectifyFactory())
-
init
public static void init(ObjectifyFactory fact)
-
factory
public static ObjectifyFactory factory()
- Returns:
- the current factory
-
register
public static void register(Class<?> clazz)
A shortcut forfactory().register()
- See Also:
ObjectifyFactory.register(Class)
-
ofy
public static Objectify ofy()
The method to call at any time to get the current Objectify, which may change depending on txn context
-
run
public static <R> R run(Work<R> work)
Runs one unit of work, making the root Objectify context available. This does not start a transaction, but it makes the static ofy() method return an appropriate object.
Normally you do not need to use this method. When servicing a normal request, the ObjectifyFilter will run this for you. This method is useful for using Objectify outside of a normal request - using the remote api, for example.
Alternatively, you can use the begin() method and close the session manually.
- Returns:
- the result of the work.
-
begin
public static Closeable begin()
An alternative to run() which is somewhat easier to use with testing (ie, @Before and @After) frameworks. You must close the return value at the end of the request in a finally block. It's better/safer to use run().
This method is not typically necessary - in a normal request, the ObjectifyFilter takes care of this housekeeping for you. However, in unit tests or remote API calls it can be useful.
-
-