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


Java NamespaceManager.get方法代码示例

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


在下文中一共展示了NamespaceManager.get方法的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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: runWithinNamespaces

import com.google.appengine.api.NamespaceManager; //导入方法依赖的package包/类
private void runWithinNamespaces(EventContext<Test> context, String[] namespaces) {
    final List<FailedNamespaceException> exceptions = new ArrayList<>();
    final String original = NamespaceManager.get();
    try {
        for (String namespace : namespaces) {
            try {
                NamespaceManager.set(namespace);
                context.proceed();
            } catch (Exception e) {
                exceptions.add(new FailedNamespaceException(e, namespace));
            }
        }
    } finally {
        NamespaceManager.set(original);
    }
    if (exceptions.size() > 1) {
        throw new MultipleExceptions(exceptions);
    } else if (exceptions.size() == 1) {
        throw exceptions.get(0);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:22,代码来源:NamespaceExtensionContainer.java

示例11: doFilter

import com.google.appengine.api.NamespaceManager; //导入方法依赖的package包/类
/**
 * {@inheritDoc}. Each request this method set the namespace. (Namespace is by version)
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {

  // If the NamespaceManager state is already set up from the context of the task creator the
  // current namespace will not be null. It's important to check that the current namespace
  // has not been set before setting it for this request.
  String applicationVersion = TechGalleryUtil.getApplicationVersion();

  if (NamespaceManager.get() == null && !applicationVersion.contains("$")) {
    logger.info("SystemProperty.applicationVersion.get():" + applicationVersion);
    String[] version = applicationVersion.split("\\.");
    if (version.length > 0 && version[0].contains("-")) {
      String namespace = version[0].split("-")[0];
      NamespaceManager.set(namespace);
    } else if (version.length > 0) {
      NamespaceManager.set(version[0]);
    } else {
      NamespaceManager.set(applicationVersion);
    }

    logger.info("set namespace:" + NamespaceManager.get());
  }
  // chain into the next request
  chain.doFilter(request, response);
}
 
开发者ID:ciandt-dev,项目名称:tech-gallery,代码行数:30,代码来源:NamespaceFilter.java

示例12: doFilter

import com.google.appengine.api.NamespaceManager; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
    throws IOException, ServletException {
  // Make sure set() is only called if the current namespace is not already set.
  if (NamespaceManager.get() == null) {
    // If your app is hosted on appspot, this will be empty. Otherwise it will be the domain
    // the app is hosted on.
    NamespaceManager.set(NamespaceManager.getGoogleAppsNamespace());
  }
  chain.doFilter(req, res); // Pass request back down the filter chain
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:12,代码来源:NamespaceFilter.java

示例13: createKeyForSession

import com.google.appengine.api.NamespaceManager; //导入方法依赖的package包/类
/**
 * Return a {@link Key} for the given session "key" string
 * ({@link SessionManager#SESSION_PREFIX} + sessionId) in the empty namespace.
 */
static Key createKeyForSession(String key) {
  String originalNamespace = NamespaceManager.get();
  try {
    NamespaceManager.set("");
    return KeyFactory.createKey(SESSION_ENTITY_TYPE, key);
  } finally {
    NamespaceManager.set(originalNamespace);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:14,代码来源:DatastoreSessionStore.java

示例14: createEntityForSession

import com.google.appengine.api.NamespaceManager; //导入方法依赖的package包/类
/**
 * Return an {@link Entity} for the given key and data in the empty
 * namespace.
 */
static Entity createEntityForSession(String key, SessionData data) {
  String originalNamespace = NamespaceManager.get();
  try {
    NamespaceManager.set("");
    Entity entity = new Entity(SESSION_ENTITY_TYPE, key);
    entity.setProperty(EXPIRES_PROP, data.getExpirationTime());
    entity.setProperty(VALUES_PROP, new Blob(serialize(data.getValueMap())));
    return entity;
  } finally {
    NamespaceManager.set(originalNamespace);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:17,代码来源:DatastoreSessionStore.java

示例15: makeKey

import com.google.appengine.api.NamespaceManager; //导入方法依赖的package包/类
private Key makeKey(String bucket, String object) {
  String origNamespace = NamespaceManager.get();
  try {
    NamespaceManager.set("");
    return KeyFactory.createKey(ENTITY_KIND_PREFIX + bucket, object);
  } finally {
    NamespaceManager.set(origNamespace);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:10,代码来源:LocalRawGcsService.java


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