Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.appengine.api
Class NamespaceManager

    java.lang.Object
      com.google.appengine.api.NamespaceManager

    public final class NamespaceManager

extends java.lang.Object

Provides functions for manipulating the current namespace used for App Engine APIs.

The "current namespace" is the string that is returned by `get()` and used by a number of APIs including Datatore, Memcache and Task Queue.

When a namespace aware class (e.g., `Key`, `Query` and `MemcacheService`) is constructed, it determines which namespace will be used by calling `get()` if it is otherwise unspecified. If `get()` returns null, the current namespace is unset and these APIs will use the empty ("") namespace in its place.

Example: ``

     NamespaceManager.set(java.lang.String)("a-namespace");
     MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
     // Store record in namespace "a-namespace"
     memcache.put("key1", "value1");

     NamespaceManager.set(java.lang.String)("other-namespace");
     // Store record in namespace "other-namespace"
     memcache.put("key2", "value2");

     MemcacheService boundMemcache =
         MemcacheServiceFactory.getMemcacheService("specific-namespace");
     NamespaceManager.set(java.lang.String)("whatever-namespace");
     // The record is still stored in namespace "specific-namespace".
     boundMemcache.put("key3", "value3");

MemcacheService `memcache` (in the above example) uses the current namespace and `key1` will be stored in namespace `"a-namespace"`, while `key2` is stored in namespace `"other-namespace"`. It is possible to override the current namespace and store data in specific namespace. In the above example `key3` is stored in namespace `"specific-namespace"`.

The Task Queue `Queue.add()` methods will forward the `NamespaceManager` settings into the task being added causing the added task to be executed with the same current namespace as the task creator. The exception is that an unset current namespace (i.e. `get()` returns null) will be forwarded as an empty ("") namespace to the created task's requests.

Method Summary
`static java.lang.String` | `get()` Returns the current namespace setting or `null` if not set.
`static java.lang.String` | `getGoogleAppsNamespace()` Returns the Google Apps domain referring this request or otherwise the empty string ("").
`static void` | `set(java.lang.String newNamespace)` Set the value used to initialize the namespace of namespace-aware services.
`static void` | `validateNamespace(java.lang.String namespace)` Validate the format of a namespace string.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### set

    public static void set(java.lang.String newNamespace)

  Set the value used to initialize the namespace of namespace-aware services.

  Parameters:
    `newNamespace` - the new namespace.
  Throws:
    `java.lang.IllegalArgumentException` - if namespace string is invalid.

### get

    public static java.lang.String get()

  Returns the current namespace setting or `null` if not set.

  If the current namespace is unset, callers should assume the use of the "" (empty) namespace in all namespace-aware services.

### getGoogleAppsNamespace

    public static java.lang.String getGoogleAppsNamespace()

  Returns the Google Apps domain referring this request or otherwise the empty string ("").

### validateNamespace

    public static void validateNamespace(java.lang.String namespace)

  Validate the format of a namespace string.

  Throws:
    `java.lang.IllegalArgumentException` - If the format of the namespace string is invalid.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD