當前位置: 首頁>>代碼示例>>Java>>正文


Java FetchOptions類代碼示例

本文整理匯總了Java中com.google.appengine.api.datastore.FetchOptions的典型用法代碼示例。如果您正苦於以下問題:Java FetchOptions類的具體用法?Java FetchOptions怎麽用?Java FetchOptions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FetchOptions類屬於com.google.appengine.api.datastore包,在下文中一共展示了FetchOptions類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGet

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {
	resp.setContentType("text/html");
	resp.getWriter().println("<html><body>");

	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	Query query = new Query("SharedList");
	query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
	List<Entity> results = datastore.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	for (Entity entity : results) {
		String email = (String) entity.getProperty("email");
		String productID = (String) entity.getKey().getName();
		String productName = (String) entity.getProperty("productName");
		Date sharedDate = (Date) entity.getProperty("sharedDate");

		resp.getWriter().println(
				email + " shared <a href=\"http://www.amazon.com/dp/"
						+ productID + "\" target=\"_blank\">" + "<b>"
						+ productName + "</b></a>!<br>");
	}

	resp.getWriter().println("</body></html>");
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:26,代碼來源:SharedlistServlet.java

示例2: getNationalHighScores

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
/**
 * Method to retrieve the national high scores 
 * @return
 */
public List<Entity> getNationalHighScores(String countryCode){
	log.info("Retrieving national high scores");
	
	//create the country code filter
	Filter country = new FilterPredicate(Constants.COUNTRY_CODE,FilterOperator.EQUAL,countryCode);
	//create the query to read the records sorted by score
	Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
	//set the filter to the query
	q.setFilter(country);
	
	PreparedQuery pq = datastore.prepare(q);
	
	//retrieve and return the list of records	
	return pq.asList(FetchOptions.Builder.withLimit(100));
}
 
開發者ID:mastorak,項目名稱:LeaderboardServer,代碼行數:20,代碼來源:ScoreDAO.java

示例3: getMonthlyHighScores

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
/**
 * Method to retrieve the monthly high scores 
 * @return
 */
public List<Entity> getMonthlyHighScores(){
	log.info("Retrieving monthly high scores");
	
	//calculate calendar info
	Calendar calendar= Calendar.getInstance();		
	int year=calendar.get(Calendar.YEAR);
	int month=calendar.get(Calendar.MONTH);
	
	//create filters
	Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
	Filter monthFilter = new FilterPredicate(Constants.MONTH,FilterOperator.EQUAL,month);
		
	//create the query to read the records sorted by score
	Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
	//set filters to the query
	q.setFilter(yearFilter);
	q.setFilter(monthFilter);
	
	//prepare query
	PreparedQuery pq = datastore.prepare(q);
	
	//retrieve and return the list of records	
	return pq.asList(FetchOptions.Builder.withLimit(100));
}
 
開發者ID:mastorak,項目名稱:LeaderboardServer,代碼行數:29,代碼來源:ScoreDAO.java

示例4: getWeeklyHighScores

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
/**
 * Method to retrieve the weekly high scores 
 * @return
 */
public List<Entity> getWeeklyHighScores(){
	log.info("Retrieving weekly high scores");
	
	//calculate calendar info
	Calendar calendar= Calendar.getInstance();		
	int year=calendar.get(Calendar.YEAR);
	int week=calendar.get(Calendar.WEEK_OF_YEAR);
	
	//create filters
	Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
	Filter weekFilter = new FilterPredicate(Constants.WEEK_OF_THE_YEAR,FilterOperator.EQUAL,week);
		
	//create the query to read the records sorted by score
	Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
	//set filters to the query
	q.setFilter(yearFilter);
	q.setFilter(weekFilter);
	
	//prepare query
	PreparedQuery pq = datastore.prepare(q);
	
	//retrieve and return the list of records	
	return pq.asList(FetchOptions.Builder.withLimit(100));
}
 
開發者ID:mastorak,項目名稱:LeaderboardServer,代碼行數:29,代碼來源:ScoreDAO.java

示例5: getDailyHighScores

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
/**
 * Method to retrieve the daily high scores 
 * @return
 */
public List<Entity> getDailyHighScores(){
	log.info("Retrieving weekly high scores");
	
	//calculate calendar info
	Calendar calendar= Calendar.getInstance();
	int year=calendar.get(Calendar.YEAR);
	int day=calendar.get(Calendar.DAY_OF_YEAR);
	
	//create filters
	Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
	Filter dayFilter = new FilterPredicate(Constants.DAY_OF_THE_YEAR,FilterOperator.EQUAL,day);
	
	//create the query to read the records sorted by score
	Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
	
	//set filters to the query
	q.setFilter(yearFilter);
	q.setFilter(dayFilter);
	
	//prepare query
	PreparedQuery pq = datastore.prepare(q);
	
	//retrieve and return the list of records	
	return pq.asList(FetchOptions.Builder.withLimit(100));
}
 
開發者ID:mastorak,項目名稱:LeaderboardServer,代碼行數:30,代碼來源:ScoreDAO.java

示例6: getAllUdwIds

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
public List<ConvUdwMapping> getAllUdwIds(SlobId convObjectId)
    throws PermanentFailure, RetryableFailure {
  Query q = new Query(ENTITY_KIND)
    .setFilter(FilterOperator.GREATER_THAN_OR_EQUAL.of(Entity.KEY_RESERVED_PROPERTY,
        directory.makeKey(new Key(convObjectId, FIRST))))
    .addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);

  List<ConvUdwMapping> entries = Lists.newArrayList();

  CheckedIterator it = datastore.prepareNontransactionalQuery(q)
      .asIterator(FetchOptions.Builder.withDefaults());
  while (it.hasNext()) {
    ConvUdwMapping entry = directory.parse(it.next());
    if (!entry.getKey().getConvObjectId().equals(convObjectId)) {
      break;
    }
    entries.add(entry);
  }
  log.info("Found " + entries.size() + " user data wavelets for " + convObjectId);
  return entries;
}
 
開發者ID:ArloJamesBarnes,項目名稱:walkaround,代碼行數:22,代碼來源:UdwDirectory.java

示例7: getDeltaEntityIterator

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
private CheckedIterator getDeltaEntityIterator(long startVersion, @Nullable Long endVersion,
    FetchOptions fetchOptions, boolean forward, boolean keysOnly)
    throws PermanentFailure, RetryableFailure {
  checkRange(startVersion, endVersion);
  if (endVersion != null && startVersion == endVersion) {
    return CheckedIterator.EMPTY;
  }
  Query.Filter filter = FilterOperator.GREATER_THAN_OR_EQUAL.of(Entity.KEY_RESERVED_PROPERTY,
      makeDeltaKey(objectId, startVersion));
  if (endVersion != null) {
    filter = Query.CompositeFilterOperator.and(filter,
        FilterOperator.LESS_THAN.of(Entity.KEY_RESERVED_PROPERTY,
            makeDeltaKey(objectId, endVersion)));
  }
  Query q = new Query(deltaEntityKind)
      .setAncestor(makeRootEntityKey(objectId))
      .setFilter(filter)
      .addSort(Entity.KEY_RESERVED_PROPERTY,
          forward ? SortDirection.ASCENDING : SortDirection.DESCENDING);
  if (keysOnly) {
    q.setKeysOnly();
  }
  return tx.prepare(q).asIterator(fetchOptions);
}
 
開發者ID:ArloJamesBarnes,項目名稱:walkaround,代碼行數:25,代碼來源:MutationLog.java

示例8: getEntitiesBrowser

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
@GET
@Produces(MediaType.TEXT_XML)
public List<SharedProduct> getEntitiesBrowser() {
	List<SharedProduct> list = new ArrayList<SharedProduct>();
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	Query query = new Query("SharedList");
	query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
	List<Entity> results = datastore.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	for (Entity entity : results) {
		String email = (String) entity.getProperty("email");
		String productID = (String) entity.getKey().getName();
		String productName = (String) entity.getProperty("productName");
		Date sharedDate = (Date) entity.getProperty("sharedDate");

		list.add(new SharedProduct(email, productID, productName,
				sharedDate));
	}

	return list;
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:23,代碼來源:Sharedlist.java

示例9: getEntities

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<SharedProduct> getEntities() {
	List<SharedProduct> list = new ArrayList<SharedProduct>();
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	Query query = new Query("SharedList");
	query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
	List<Entity> results = datastore.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	for (Entity entity : results) {
		String email = (String) entity.getProperty("email");
		String productID = (String) entity.getKey().getName();
		String productName = (String) entity.getProperty("productName");
		Date sharedDate = (Date) entity.getProperty("sharedDate");

		list.add(new SharedProduct(email, productID, productName,
				sharedDate));
	}

	return list;
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:23,代碼來源:Sharedlist.java

示例10: listBooks

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
@Override
public Result<Book> listBooks(String startCursorString) {
  FetchOptions fetchOptions = FetchOptions.Builder.withLimit(10); // Only show 10 at a time
  if (startCursorString != null && !startCursorString.equals("")) {
    fetchOptions.startCursor(Cursor.fromWebSafeString(startCursorString)); // Where we left off
  }
  Query query = new Query(BOOK_KIND) // We only care about Books
      .addSort(Book.TITLE, SortDirection.ASCENDING); // Use default Index "title"
  PreparedQuery preparedQuery = datastore.prepare(query);
  QueryResultIterator<Entity> results = preparedQuery.asQueryResultIterator(fetchOptions);

  List<Book> resultBooks = entitiesToBooks(results);     // Retrieve and convert Entities
  Cursor cursor = results.getCursor();              // Where to start next time
  if (cursor != null && resultBooks.size() == 10) {         // Are we paging? Save Cursor
    String cursorString = cursor.toWebSafeString();               // Cursors are WebSafe
    return new Result<>(resultBooks, cursorString);
  } else {
    return new Result<>(resultBooks);
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:getting-started-java,代碼行數:21,代碼來源:DatastoreDao.java

示例11: listBooksByUser

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
@Override
public Result<Book> listBooksByUser(String userId, String startCursorString) {
  FetchOptions fetchOptions = FetchOptions.Builder.withLimit(10); // Only show 10 at a time
  if (startCursorString != null && !startCursorString.equals("")) {
    fetchOptions.startCursor(Cursor.fromWebSafeString(startCursorString)); // Where we left off
  }
  Query query = new Query(BOOK_KIND) // We only care about Books
      // Only for this user
      .setFilter(new Query.FilterPredicate(
          Book.CREATED_BY_ID, Query.FilterOperator.EQUAL, userId))
      // a custom datastore index is required since you are filtering by one property
      // but ordering by another
      .addSort(Book.TITLE, SortDirection.ASCENDING);
  PreparedQuery preparedQuery = datastore.prepare(query);
  QueryResultIterator<Entity> results = preparedQuery.asQueryResultIterator(fetchOptions);

  List<Book> resultBooks = entitiesToBooks(results);     // Retrieve and convert Entities
  Cursor cursor = results.getCursor();              // Where to start next time
  if (cursor != null && resultBooks.size() == 10) {         // Are we paging? Save Cursor
    String cursorString = cursor.toWebSafeString();               // Cursors are WebSafe
    return new Result<>(resultBooks, cursorString);
  } else {
    return new Result<>(resultBooks);
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:getting-started-java,代碼行數:26,代碼來源:DatastoreDao.java

示例12: hasRelation

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
/**
 * Determine whether this relation already exists.
 * 
 * @return false because we don't care about naming collisions.
 * @throws ODKDatastoreException 
 */
@Override
public boolean hasRelation(String schema, String tableName, User user) throws ODKDatastoreException {
  List<com.google.appengine.api.datastore.Entity> gaeKeys = null;
  try {
    com.google.appengine.api.datastore.Query query = new com.google.appengine.api.datastore.Query(
        schema + "." + tableName);
    query.setKeysOnly();
    PreparedQuery preparedQuery = ds.prepare(query);
    gaeKeys = preparedQuery.asList(FetchOptions.Builder.withLimit(2));
  } catch (OverQuotaException e) {
    throw new ODKOverQuotaException(e);
  } catch (Exception ex) {
    // No-op
  }
  if (gaeKeys == null || gaeKeys.size() == 0)
    return false;
  return true;
}
 
開發者ID:opendatakit,項目名稱:aggregate,代碼行數:25,代碼來源:DatastoreImpl.java

示例13: removeObject

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
/**
 * Remove an object from the datastore
 * 
 * @param uri The URI
 */
public void removeObject(String uri) {
	if (!isObjectRegistered(uri)) {
		return;
	}
	// Remove all WebObjectInstance entries associated
	Filter uriFilter = new FilterPredicate("uri", FilterOperator.EQUAL, uri);
	Query instanceQuery = new Query(OBJECT_INSTANCE)
			.setFilter(uriFilter)
			.addSort("timestamp", SortDirection.DESCENDING);
	List<Entity> instances = datastoreService
			.prepare(instanceQuery)
			.asList(FetchOptions.Builder.withDefaults());
	List<Key> keys = new ArrayList<Key>();
	for (Entity e : instances) {
		keys.add(e.getKey());
	}
	datastoreService.delete(keys);
	
	// Remove actual WebObject entry
	Query objectQuery = new Query(OBJECT).setFilter(uriFilter);
	Entity object = datastoreService.prepare(objectQuery).asSingleEntity();
	datastoreService.delete(object.getKey());
}
 
開發者ID:lorenzosaino,項目名稱:gae-webmonitor,代碼行數:29,代碼來源:DataStoreService.java

示例14: getAllObjectInstances

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
/**
 * Get all instances of an object present in the data store
 * 
 * @param uri The URI of the Web object
 * @return The list of Web instances
 */
public List<WebObjectInstance> getAllObjectInstances(String uri) {
	Filter uriFilter = new FilterPredicate("uri", FilterOperator.EQUAL, uri);
	Query query = new Query(OBJECT_INSTANCE)
			.setFilter(uriFilter)
			.addSort("timestamp", SortDirection.DESCENDING);

	List<Entity> instances = datastoreService.prepare(query)
			.asList(FetchOptions.Builder.withDefaults());
	List<WebObjectInstance> instanceList = new ArrayList<WebObjectInstance>();
	for (Entity e : instances) {
		String content = ((Text) e.getProperty("content")).getValue();
		String contentType = (String) e.getProperty("contentType");
		int statusCode = ((Integer) e.getProperty("statusCode")).intValue();
		Date timestamp = (Date) e.getProperty("timestamp");
		instanceList.add(new WebObjectInstance(uri, content, contentType,
				timestamp, statusCode));
	}
	return instanceList;
}
 
開發者ID:lorenzosaino,項目名稱:gae-webmonitor,代碼行數:26,代碼來源:DataStoreService.java

示例15: getMostRecentObjectInstance

import com.google.appengine.api.datastore.FetchOptions; //導入依賴的package包/類
/**
 * Get the most recent instance of a web object available
 * 
 * @param uri The URI of the Web object
 * @return The instance of the Web object
 */
public WebObjectInstance getMostRecentObjectInstance(String uri) {
	Filter uriFilter = new FilterPredicate("uri", FilterOperator.EQUAL, uri);
	Query query = new Query(OBJECT_INSTANCE)
			.setFilter(uriFilter)
			.addSort("timestamp", SortDirection.DESCENDING);
	List<Entity> instances = datastoreService.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	if (instances == null || instances.isEmpty()) {
		return null;
	}
	Entity mostRecentInstance = instances.get(0);
	String content = ((Text) mostRecentInstance.getProperty("content"))
			.getValue();
	String contentType = (String) mostRecentInstance
			.getProperty("contentType");
	Date timestamp = (Date) mostRecentInstance.getProperty("timestamp");
	int statusCode = ((Long) mostRecentInstance.getProperty("statusCode"))
			.intValue();
	return new WebObjectInstance(uri, content, contentType, timestamp,
			statusCode);
}
 
開發者ID:lorenzosaino,項目名稱:gae-webmonitor,代碼行數:28,代碼來源:DataStoreService.java


注:本文中的com.google.appengine.api.datastore.FetchOptions類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。