ceram1
ceram1

Reputation: 525

GAE datastore - How to deal with multiple namespace at same time

How can I design hierarchical entity with namespace, and use it with default namespace in single request?

Default namespace is used for administrative purpose, like holding informations about admin of each namespace.

Hierarchy

User (Namespace: default)
  - Organization (Namespace: default)
    - User (Namespace: name of organization)

Summary:

1. How can I use multiple namespace in single request? - Available

2. Is NamespaceManager.set() should be called before Key.create, or before datastore operation?

----- Update ----- Key key = KeyFactory.createKey('Test', 100) NamespaceManager.set('NS_NEW') Key nsKey = KeyFactory.createKey('Test', 100) NamespaceManager.set(null) [key: key, nsKey: nsKey];

Result :

{"key": {"kind":"Test","appId":"gaetest","id":100,"name":null,"parent":null,"namespace":"","complete":true},"nsKey":{"kind":"Test","appId":"gaetest","id":100,"name":null,"parent":null,"namespace":"NS_NEW","complete":true}}

According to result, Key holds namespace. (And objectify becomes problem..)

3. If I need to do this with entity group (parent key), how can I bypass concurrent query limit?

Upvotes: 2

Views: 861

Answers (1)

Dave W. Smith
Dave W. Smith

Reputation: 24966

If you're asking whether the the app engine datastore supports cross-namespace entities, the answer is no. Entities live within a single namespace (the namespace embedded in the Entity key). It's possible to store, as an Entity property value, a key to an Entity in a different namespace, but I don't know enough about Objectify to say whether Objectify supports that, or whether you'd need to bypass Objectify to use a lower-level API.

If you're asking whether you can use multiple namespaces with a HTTP request, the answer is clearly yes, since the handler starts in the default namespace until the namespace is changed by code within the handler. If you're asking whether you can use multiple namespaces within a datastore query (say, to join data from different namespaces), the answer (as I understand it) is no.

Upvotes: 2

Related Questions