2010-09-11 19 views

回答

13

命名空间允许您为多租户应用程序实现数据分离。 official documentation链接到一些示例项目,让您知道如何使用它。

-3

命名空间可用于为不同的用户创建不同的数据库。它有助于在数据库中创建层次结构。

0

寻找,对这个问题没有太多好的回顾和回答,所以试图给这个。

当使用名称空间时,我们可以在给定的名称空间上实现键和值分离的最佳实践。以下是彻底提供名称空间信息的最佳示例。

from google.appengine.api import namespace_manager 
from google.appengine.ext import db 
from google.appengine.ext import webapp 

class Counter(db.Model): 
    """Model for containing a count.""" 
    count = db.IntegerProperty() 


def update_counter(name): 
    """Increment the named counter by 1.""" 
def _update_counter(name): 
    counter = Counter.get_by_key_name(name) 
    if counter is None: 
     counter = Counter(key_name=name); 
     counter.count = 1 
    else: 
     counter.count = counter.count + 1 
    counter.put() 
# Update counter in a transaction. 
db.run_in_transaction(_update_counter, name) 

class SomeRequest(webapp.RequestHandler): 
"""Perform synchronous requests to update counter.""" 
def get(self): 
    update_counter('SomeRequest') 
    # try/finally pattern to temporarily set the namespace. 
    # Save the current namespace. 
    namespace = namespace_manager.get_namespace() 
    try: 
     namespace_manager.set_namespace('-global-') 
     update_counter('SomeRequest') 
    finally: 
     # Restore the saved namespace. 
     namespace_manager.set_namespace(namespace) 
    self.response.out.write('<html><body><p>Updated counters') 
    self.response.out.write('</p></body></html>') 
1

命名空间用于谷歌应用程序引擎来创建多租户应用程序。在Multitenent应用程序中,应用程序的单个实例在服务器上运行,为多个客户机构(租户)提供服务。有了这个,可以将应用程序设计为虚拟分割其数据和配置(业务逻辑),并且每个客户端组织都可以使用自定义的虚拟应用程序实例。只需通过为每个租户指定唯一的名称空间字符串。

命名空间的其他用途:

  1. Compartmentalizing用户信息
  2. 从应用数据
  3. 创建用于测试和生产
  4. 单独的数据存储的实例上的单个App Engine上运行多个应用程序分离管理数据实例

For More inform请访问以下链接:

http://www.javacodegeeks.com/2011/12/multitenancy-in-google-appengine-gae.html 
https://developers.google.com/appengine/docs/java/multitenancy/ 
http://java.dzone.com/articles/multitenancy-google-appengine 

http://www.sitepoint.com/multitenancy-and-google-app-engine-gae-java/ 
相关问题