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


Java PreparedQuery.asQueryResultList方法代码示例

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


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

示例1: testIndexListFromList

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Test
public void testIndexListFromList() throws Exception {
    Entity parent = createTestEntityWithUniqueMethodNameKey("Person", "testKeysOnly");
    Key key = parent.getKey();

    Entity joe = createEntity("Person", key)
        .withProperty("name", "Joe")
        .withProperty("surname", "Moe")
        .store();

    Query query = new Query("Person")
        .setAncestor(key)
        .setKeysOnly();

    PreparedQuery preparedQuery = service.prepare(query);
    QueryResultList<Entity> list = preparedQuery.asQueryResultList(FetchOptions.Builder.withDefaults());
    List<Index> indexes = list.getIndexList();
    if (indexes != null) {
        // TODO -- something useful
        System.out.println("indexes = " + indexes);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:23,代码来源:QueryResultTest.java

示例2: getFirstCursor

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
private String getFirstCursor() {
  Query q = new Query("Person").addSort("name", SortDirection.ASCENDING);
  PreparedQuery pq = datastore.prepare(q);
  FetchOptions fetchOptions = FetchOptions.Builder.withLimit(ListPeopleServlet.PAGE_SIZE);
  QueryResultList<Entity> results = pq.asQueryResultList(fetchOptions);
  return results.getCursor().toWebSafeString();
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:8,代码来源:ListPeopleServletTest.java

示例3: getRelatedEntities

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@ApiMethod(name = "getRelatedEntities", scopes = { Config.EMAIL_SCOPE }, clientIds = { Config.CHROME_CLIENT_ID, Config.WEB_CLIENT_ID,
 	    Config.API_EXPLORER_CLIENT_ID })
     public List<Long> getRelatedEntities(@Named("_name") String _name, @Named("_relatedEntityName") String _relatedEntityName, @Named("_id") Long _id, User user) throws UnauthorizedException {
 		if (user == null) {
 			throw new UnauthorizedException(
 					"UnauthorizedException # User is Null.");
 		}
 		DatastoreService datastore = DatastoreServiceFactory
 				.getDatastoreService();
 		
 		FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();
 		
 		Filter f = new FilterPredicate(_relatedEntityName+"_id", FilterOperator.EQUAL, _id);
 		
Query q = new Query(_name).setFilter(f);
 		PreparedQuery pq = datastore.prepare(q);    		
 		
 		QueryResultList<Entity> results = pq.asQueryResultList(fetchOptions);
 		
 		List<Long> relatedEntityIds = new ArrayList<Long>();
 		
 		for (Entity entity : results) {
     	    Map<String, Object> properties = entity.getProperties();
     	    Set<String> keySet = properties.keySet();
     	    
     	    for (String mapKey : keySet) {
		if(mapKey.equals("_id")){
			continue;
		}
		else if(mapKey.equals(_relatedEntityName+"_id")){
			continue;
		}
		else if(mapKey.endsWith("_id")){
			relatedEntityIds.add((Long)properties.get(mapKey));
		}
	}
 		}
 		return relatedEntityIds;
     }
 
开发者ID:AnujaK,项目名称:chrome-gae-sync,代码行数:40,代码来源:RelationEndpoint.java

示例4: doGet

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  FetchOptions fetchOptions = FetchOptions.Builder.withLimit(PAGE_SIZE);

  // If this servlet is passed a cursor parameter, let's use it.
  String startCursor = req.getParameter("cursor");
  if (startCursor != null) {
    fetchOptions.startCursor(Cursor.fromWebSafeString(startCursor));
  }

  Query q = new Query("Person").addSort("name", SortDirection.ASCENDING);
  PreparedQuery pq = datastore.prepare(q);

  QueryResultList<Entity> results;
  try {
    results = pq.asQueryResultList(fetchOptions);
  } catch (IllegalArgumentException e) {
    // IllegalArgumentException happens when an invalid cursor is used.
    // A user could have manually entered a bad cursor in the URL or there
    // may have been an internal implementation detail change in App Engine.
    // Redirect to the page without the cursor parameter to show something
    // rather than an error.
    resp.sendRedirect("/people");
    return;
  }

  resp.setContentType("text/html");
  resp.setCharacterEncoding("UTF-8");
  PrintWriter w = resp.getWriter();
  w.println("<!DOCTYPE html>");
  w.println("<meta charset=\"utf-8\">");
  w.println("<title>Cloud Datastore Cursor Sample</title>");
  w.println("<ul>");
  for (Entity entity : results) {
    w.println("<li>" + entity.getProperty("name") + "</li>");
  }
  w.println("</ul>");

  String cursorString = results.getCursor().toWebSafeString();

  // This servlet lives at '/people'.
  w.println("<a href='/people?cursor=" + cursorString + "'>Next page</a>");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:45,代码来源:ListPeopleServlet.java

示例5: findAll

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
/**
   * This method lists all the entities inserted in datastore. It uses HTTP GET method and paging support.
   * 
   * @return A CollectionResponse class containing the list of all entities persisted and a cursor to the next page.
   * @throws UnauthorizedException
   */
  @ApiMethod(name = "findAll", scopes = { Config.EMAIL_SCOPE }, clientIds = { Config.CHROME_CLIENT_ID, Config.WEB_CLIENT_ID,
   Config.API_EXPLORER_CLIENT_ID })
  public CollectionResponse<ServiceResponse> findAll(@Named("_name") String _name, @Nullable @Named("cursor") String cursorString,
   @Nullable @Named("limit") Integer limit, User user) throws UnauthorizedException {
if (user == null) {
	throw new UnauthorizedException(
			"UnauthorizedException # User is Null.");
}
DatastoreService datastore = DatastoreServiceFactory
		.getDatastoreService();
if (limit == null) {
	limit = 10;
}
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(limit);
if (cursorString != null) {
	fetchOptions.startCursor(Cursor.fromWebSafeString(cursorString));
}
Query q = new Query(_name);
q.addSort("_updatedAt", SortDirection.DESCENDING);
PreparedQuery pq = datastore.prepare(q);
QueryResultList<Entity> results = pq.asQueryResultList(fetchOptions);

List<ServiceResponse> responses = new ArrayList<ServiceResponse>();
ServiceResponse res = null;
for (Entity entity : results) {
	res = new ServiceResponse();
	//TODO add properties from entity to service response
	res.set_id(entity.getKey().getId());
  	    
  	    res.set_createdAt((Date) entity.getProperty(_createdAt));
  	    res.set_createdBy((String) entity.getProperty(_createdBy));
  	    
  	    res.set_upatedAt((Date) entity.getProperty(_updatedAt));
  	    res.set_updatedBy((String) entity.getProperty(_updatedBy));
  	    
  	    res.set_status((String) entity.getProperty(_status));
  	    
  	    Text dataText = (Text)entity.getProperty(data);
	res.setData(dataText.getValue());
	
	responses.add(res);
}

cursorString = results.getCursor().toWebSafeString();

return CollectionResponse.<ServiceResponse> builder().setItems(responses).setNextPageToken(cursorString).build();
  }
 
开发者ID:AnujaK,项目名称:chrome-gae-sync,代码行数:54,代码来源:StoreEndpoint.java


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