Package com.googlecode.objectify
Class NamespaceManager
java.lang.Object
com.googlecode.objectify.NamespaceManager
A simple thread local namespace manager, similar to legacy GAE's
NamespaceManager
.-
Constructor Summary
-
Method Summary
-
Constructor Details
-
NamespaceManager
public NamespaceManager()
-
-
Method Details
-
set
Sets the default namespace for this thread. Similar to legacy GAE's
NamespaceManager
. While a namespace is set, all keys which are not created with an explicit namespace and all queries without an explicit namespace will inherit this value.To exit the namespace, call
close()
on the return value. This should be performed in a finally block, or even better with the a try-with-resources idiom:try (Closeable ignored = NamespaceManager.set("blah")) { ... }
Note that this namespace affects key creation, but once a key has been created, it has an inherent namespace.
final Key<Foo> key = Key.create(Foo.class, 123); try (final Closeable ignored = NamespaceManager.set("blah")) { ofy().load().key(key); // The key already has the default namespace ofy().load().type(Foo.class).id(123); // Uses the 'blah' namespace ofy().load().key(Key.create(Foo.class, 123)); // Uses the 'blah' namespace }
You can call
set(null)
to clear the namespace; this is identical to callingclose()
on the return value. -
get
- Returns:
- the currently set default namespace, or null if one is not set
-