当前位置: 首页>>代码示例>>Java>>正文


Java NamespaceManager类代码示例

本文整理汇总了Java中com.google.appengine.api.NamespaceManager的典型用法代码示例。如果您正苦于以下问题:Java NamespaceManager类的具体用法?Java NamespaceManager怎么用?Java NamespaceManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NamespaceManager类属于com.google.appengine.api包,在下文中一共展示了NamespaceManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws java.io.IOException {

  // Update the count for the current namespace.
  updateCount("request");

  // Update the count for the "-global-" namespace.
  String namespace = NamespaceManager.get();
  try {
    // "-global-" is namespace reserved by the application.
    NamespaceManager.set("-global-");
    updateCount("request");
  } finally {
    NamespaceManager.set(namespace);
  }
  resp.setContentType("text/plain");
  resp.getWriter().println("Counts are now updated.");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:20,代码来源:UpdateCountsServlet.java

示例2: doGet

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req,
                     HttpServletResponse resp)
    throws IOException {

  // Increment the count for the current namespace asynchronously.
  QueueFactory.getDefaultQueue().add(
      TaskOptions.Builder.withUrl("/_ah/update_count")
          .param("countName", "SomeRequest"));
  // Increment the global count and set the
  // namespace locally.  The namespace is
  // transferred to the invoked request and
  // executed asynchronously.
  String namespace = NamespaceManager.get();
  try {
    NamespaceManager.set("-global-");
    QueueFactory.getDefaultQueue().add(
        TaskOptions.Builder.withUrl("/_ah/update_count")
            .param("countName", "SomeRequest"));
  } finally {
    NamespaceManager.set(namespace);
  }
  resp.setContentType("text/plain");
  resp.getWriter().println("Counts are being updated.");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:26,代码来源:SomeRequestServlet.java

示例3: doGet

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

  // Increment the count for the current namespace asynchronously.
  QueueFactory.getDefaultQueue()
      .add(TaskOptions.Builder.withUrl("/_ah/update_count").param("countName", "SomeRequest"));
  // Increment the global count and set the
  // namespace locally.  The namespace is
  // transferred to the invoked request and
  // executed asynchronously.
  String namespace = NamespaceManager.get();
  try {
    NamespaceManager.set("-global-");
    QueueFactory.getDefaultQueue()
        .add(TaskOptions.Builder.withUrl("/_ah/update_count").param("countName", "SomeRequest"));
  } finally {
    NamespaceManager.set(namespace);
  }
  resp.setContentType("text/plain");
  resp.getWriter().println("Counts are being updated.");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:22,代码来源:SomeRequestServlet.java

示例4: populate

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
private void populate(DatastoreService ds, String namespace) {
  NamespaceManager.set(namespace);
  Entity e = new Entity("Fun");
  e.setProperty("me", "yes");
  e.setProperty("you", 23);
  e.setUnindexedProperty("haha", 0);
  ds.put(e);
  Entity s = new Entity("Strange");
  ArrayList nowhereList = new ArrayList<Integer>();
  nowhereList.add(1);
  nowhereList.add(2);
  nowhereList.add(3);
  s.setProperty("nowhere", nowhereList);
  ds.put(s);
  Entity s2 = new Entity("Stranger");
  s2.setProperty("missing", new ArrayList<Integer>());
  ds.put(s2);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:19,代码来源:TestMetadataServlet.java

示例5: getAllSessions

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Override
public Map<String, SessionData> getAllSessions() {
  final String originalNamespace = NamespaceManager.get();
  NamespaceManager.set("");
  try {
    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    PreparedQuery pq = ds.prepare(new Query(SESSION_ENTITY_TYPE));
    Map<String, SessionData> sessions = new HashMap<>();
    for (Entity entity : pq.asIterable()) {
      sessions.put(entity.getKey().getName(), createSessionFromEntity(entity));
    }
    return sessions;
  } finally {
    NamespaceManager.set(originalNamespace);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:17,代码来源:DatastoreSessionStore.java

示例6: createKeyWithNamespace

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
/**
 * Creates a {@link com.google.appengine.api.datastore.Key} from the specified kindName and CloudEntity id. If
 * the kindName has _private suffix, the key will be created under a namespace
 * for the specified {@link com.google.appengine.api.users.User}.
 *
 * @param kindName
 *          Name of kind
 * @param id
 *          CloudEntity id
 * @param user
 *          {@link com.google.appengine.api.users.User} of the requestor
 * @return {@link com.google.appengine.api.datastore.Key}
 */
public Key createKeyWithNamespace(String kindName, String id, User user) {

  // save the original namespace
  String origNamespace = NamespaceManager.get();

  // set namespace based on the kind suffix
  if (kindName.startsWith(SecurityChecker.KIND_PREFIX_PRIVATE)) {
    String userId = getUserId(user);
    NamespaceManager.set(userId);
  } else {
    NamespaceManager.set(SecurityChecker.NAMESPACE_DEFAULT);
  }

  // create a key
  Key k = KeyFactory.createKey(kindName, id);

  // restore the original namespace
  NamespaceManager.set(origNamespace);
  return k;
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:34,代码来源:SecurityChecker.java

示例7: createKindQueryWithNamespace

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
/**
 * Creates {@link com.google.appengine.api.datastore.Query} from the specified kindName. If the kindName has
 * _private suffix, the key will be created under a namespace for the
 * specified {@link com.google.appengine.api.users.User}.
 *
 * @param kindName
 *          Name of kind
 * @param user
 *          {@link com.google.appengine.api.users.User} of the requestor
 * @return {@link com.google.appengine.api.datastore.Query}
 */
public Query createKindQueryWithNamespace(String kindName, User user) {

  // save the original namespace
  String origNamespace = NamespaceManager.get();

  // set namespace based on the kind suffix
  if (kindName.startsWith(KIND_PREFIX_PRIVATE)) {
    String userId = getUserId(user);
    NamespaceManager.set(userId);
  } else {
    NamespaceManager.set(NAMESPACE_DEFAULT);
  }

  // create a key
  Query q = new Query(kindName);

  // restore the original namespace
  NamespaceManager.set(origNamespace);
  return q;
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:32,代码来源:SecurityChecker.java

示例8: createKeyWithNamespace

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
/**
 * Creates a {@link Key} from the specified kindName and CloudEntity id. If
 * the kindName has _private suffix, the key will be created under a namespace
 * for the specified {@link User}.
 *
 * @param kindName
 *          Name of kind
 * @param id
 *          CloudEntity id
 * @param user
 *          {@link User} of the requestor
 * @return {@link Key}
 */
public Key createKeyWithNamespace(String kindName, String id, User user) {

  // save the original namespace
  String origNamespace = NamespaceManager.get();

  // set namespace based on the kind suffix
  if (kindName.startsWith(SecurityChecker.KIND_PREFIX_PRIVATE)) {
    String userId = getUserId(user);
    NamespaceManager.set(userId);
  } else {
    NamespaceManager.set(SecurityChecker.NAMESPACE_DEFAULT);
  }

  // create a key
  Key k = KeyFactory.createKey(kindName, id);

  // restore the original namespace
  NamespaceManager.set(origNamespace);
  return k;
}
 
开发者ID:googlearchive,项目名称:solutions-mobile-backend-starter-java,代码行数:34,代码来源:SecurityChecker.java

示例9: createKindQueryWithNamespace

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
/**
 * Creates {@link Query} from the specified kindName. If the kindName has
 * _private suffix, the key will be created under a namespace for the
 * specified {@link User}.
 *
 * @param kindName
 *          Name of kind
 * @param user
 *          {@link User} of the requestor
 * @return {@link Query}
 */
public Query createKindQueryWithNamespace(String kindName, User user) {

  // save the original namespace
  String origNamespace = NamespaceManager.get();

  // set namespace based on the kind suffix
  if (kindName.startsWith(KIND_PREFIX_PRIVATE)) {
    String userId = getUserId(user);
    NamespaceManager.set(userId);
  } else {
    NamespaceManager.set(NAMESPACE_DEFAULT);
  }

  // create a key
  Query q = new Query(kindName);

  // restore the original namespace
  NamespaceManager.set(origNamespace);
  return q;
}
 
开发者ID:googlearchive,项目名称:solutions-mobile-backend-starter-java,代码行数:32,代码来源:SecurityChecker.java

示例10: testUserNameSpace

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Test
public void testUserNameSpace() {
    String testMethodTag = "testUserNameSpace";
    NamespaceManager.set("junittest");

    TaskOptions taskOptions = TaskOptions.Builder
        .withMethod(TaskOptions.Method.POST)
        .param(TEST_RUN_ID, testRunId)
        .param(TEST_METHOD_TAG, testMethodTag)
        .url("/queuetask/addentity");
    // task name explicitly not specified.

    QueueFactory.getQueue(E2E_TESTING).add(taskOptions);
    Entity entity = dsUtil.waitForTaskThenFetchEntity(waitInterval, retryMax, testMethodTag);
    Map<String, String> expectedParams = dsUtil.createParamMap(testMethodTag);
    dsUtil.assertTaskParamsMatchEntityProperties(expectedParams, entity);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:18,代码来源:TaskQueueTest.java

示例11: testDeferredUserNS

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Test
public void testDeferredUserNS() {
    String testMethodTag = "testDeferredUserNS";
    String specifiedNameSpace = "the_testDeferredUserNS";
    Map<String, String> paramMap = dsUtil.createParamMap(testMethodTag);

    NamespaceManager.set(specifiedNameSpace);

    TaskOptions taskOptions = TaskOptions.Builder.withPayload(new ExecDeferred(dsUtil, paramMap));

    // no task name specified.
    QueueFactory.getQueue(E2E_TESTING_DEFERRED).add(taskOptions);
    Entity entity = dsUtil.waitForTaskThenFetchEntity(waitInterval, retryMax, testMethodTag);

    Map<String, String> expectedMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    expectedMap.putAll(paramMap);
    expectedMap.put("X-AppEngine-Current-Namespace", specifiedNameSpace);

    dsUtil.assertTaskParamsMatchEntityProperties(expectedMap, entity);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:21,代码来源:DeferredTest.java

示例12: testQueryListWithNamespaceChange

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Test
public void testQueryListWithNamespaceChange() throws Exception {
    Key parentKey = createQueryNamespaceTestParent("testQueryListWithNamespaceChange");
    Entity bob = createEntity("QLWNC", parentKey)
        .withProperty("name", "Bob")
        .withProperty("lastName", "Smith")
        .store();

    try {
        Query query = new Query("QLWNC");
        List<Entity> list = service.prepare(query).asList(withDefaults());

        final String previousNS = NamespaceManager.get();
        NamespaceManager.set("QwertyNS");
        try {
            assertEquals(1, list.size());
        } finally {
            NamespaceManager.set(previousNS);
        }
    } finally {
        service.delete(bob.getKey(), parentKey);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:24,代码来源:QueryNamespaceTest.java

示例13: testQueriesOnlyReturnResultsInCurrentNamespace

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Test
public void testQueriesOnlyReturnResultsInCurrentNamespace() {
    deleteNsKinds("one", "foo");
    deleteNsKinds("two", "foo");
    sync();

    NamespaceManager.set("one");
    Entity fooOne = new Entity("foo");
    service.put(fooOne);

    NamespaceManager.set("two");
    Entity fooTwo = new Entity("foo");
    service.put(fooTwo);
    sync();

    List<Entity> listTwo = service.prepare(new Query("foo").setAncestor(fooTwo.getKey())).asList(withDefaults());
    assertEquals(Collections.singletonList(fooTwo), listTwo);

    NamespaceManager.set("one");
    List<Entity> listOne = service.prepare(new Query("foo").setAncestor(fooOne.getKey())).asList(withDefaults());
    assertEquals(Collections.singletonList(fooOne), listOne);

    service.delete(fooOne.getKey());
    service.delete(fooTwo.getKey());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:26,代码来源:DatastoreMultitenancyTest.java

示例14: testQueriesByAncestorInOtherNamespaceThrowsIllegalArgumentException

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testQueriesByAncestorInOtherNamespaceThrowsIllegalArgumentException() {
    deleteNsKinds("one", "foo");
    deleteNsKinds("two", "foo");
    sync();

    NamespaceManager.set("one");
    Entity fooOne = new Entity("foo");
    service.put(fooOne);

    NamespaceManager.set("two");
    Entity fooTwo = new Entity("foo");
    service.put(fooTwo);
    sync();

    // java.lang.IllegalArgumentException: Namespace of ancestor key and query must match.
    service.prepare(new Query("foo").setAncestor(fooOne.getKey())).asList(withDefaults());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:19,代码来源:DatastoreMultitenancyTest.java

示例15: testQueryConsidersCurrentNamespaceWhenCreatedNotWhenPreparedOrExecuted

import com.google.appengine.api.NamespaceManager; //导入依赖的package包/类
@Test
public void testQueryConsidersCurrentNamespaceWhenCreatedNotWhenPreparedOrExecuted() {
    deleteNsKinds("one", "foo");
    deleteNsKinds("two", "foo");
    sync();

    NamespaceManager.set("one");
    Entity fooOne = new Entity("foo");
    service.put(fooOne);

    NamespaceManager.set("two");
    Entity fooTwo = new Entity("foo");
    service.put(fooTwo);
    sync();

    Query query = new Query("foo").setAncestor(fooTwo.getKey()); // query created in namespace "two"

    NamespaceManager.set("one");
    PreparedQuery preparedQuery = service.prepare(query);
    assertEquals(fooTwo, preparedQuery.asSingleEntity());

    service.delete(fooOne.getKey());
    service.delete(fooTwo.getKey());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:25,代码来源:DatastoreMultitenancyTest.java


注:本文中的com.google.appengine.api.NamespaceManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。