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


Java Query类代码示例

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


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

示例1: doGet

import com.google.appengine.api.datastore.Query; //导入依赖的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: convert

import com.google.appengine.api.datastore.Query; //导入依赖的package包/类
private Query.FilterOperator convert(Condition condition) {
    OperationKey key = condition.getKey();
    switch (key) {
        case EQUALS:
            return condition.isNegating() ? Query.FilterOperator.NOT_EQUAL : Query.FilterOperator.EQUAL;
        case IN:
            return Query.FilterOperator.IN;
        case GREATER:
            return Query.FilterOperator.GREATER_THAN;
        case GREATER_EQUAL:
            return Query.FilterOperator.GREATER_THAN_OR_EQUAL;
        case LESS:
            return Query.FilterOperator.LESS_THAN;
        case LESS_EQUAL:
            return Query.FilterOperator.LESS_THAN_OR_EQUAL;
        default:
            throw new IllegalArgumentException("Unsupported operator " + condition.getKey());
    }
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:20,代码来源:FilterCriteriaConverter.java

示例3: getNationalHighScores

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例4: getMonthlyHighScores

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例5: getWeeklyHighScores

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例6: getDailyHighScores

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例7: getAllUdwIds

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例8: getDeltaEntityIterator

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例9: getSnapshotEntryAtOrBefore

import com.google.appengine.api.datastore.Query; //导入依赖的package包/类
@Nullable private SnapshotEntry getSnapshotEntryAtOrBefore(@Nullable Long atOrBeforeVersion)
    throws RetryableFailure, PermanentFailure {
  Query q = new Query(snapshotEntityKind)
      .setAncestor(makeRootEntityKey(objectId))
      .addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.DESCENDING);
  if (atOrBeforeVersion != null) {
    q.setFilter(FilterOperator.LESS_THAN_OR_EQUAL.of(Entity.KEY_RESERVED_PROPERTY,
        makeSnapshotKey(objectId, atOrBeforeVersion)));
  }
  Entity e = tx.prepare(q).getFirstResult();
  log.info("query " + q + " returned first result " + e);
  if (e == null) {
    return null;
  } else {
    snapshotPropertyMover.postGet(e);
    return parseSnapshot(e);
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:19,代码来源:MutationLog.java

示例10: getEntitiesBrowser

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例11: getEntities

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例12: listBooks

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例13: listBooksByUser

import com.google.appengine.api.datastore.Query; //导入依赖的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

示例14: queryRestrictions_missingSortOnInequality_isInvalid

import com.google.appengine.api.datastore.Query; //导入依赖的package包/类
@Test
public void queryRestrictions_missingSortOnInequality_isInvalid() throws Exception {
  long minBirthYear = 1940;
  // [START inequality_filters_sort_orders_invalid_example_1]
  Filter birthYearMinFilter =
      new FilterPredicate("birthYear", FilterOperator.GREATER_THAN_OR_EQUAL, minBirthYear);

  // Not valid. Missing sort on birthYear.
  Query q =
      new Query("Person")
          .setFilter(birthYearMinFilter)
          .addSort("lastName", SortDirection.ASCENDING);
  // [END inequality_filters_sort_orders_invalid_example_1]

  // Note: The local devserver behavior is different than the production
  // version of Cloud Datastore, so there aren't any assertions we can make
  // in this test.  The query appears to work with the local test runner,
  // but will fail in production.
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:20,代码来源:QueriesTest.java

示例15: deleteSessionWithValue

import com.google.appengine.api.datastore.Query; //导入依赖的package包/类
protected void deleteSessionWithValue(String varName, String varValue) {
  Transaction transaction = datastore.beginTransaction();
  try {
    Query query = new Query(SESSION_KIND)
        .setFilter(new FilterPredicate(varName, FilterOperator.EQUAL, varValue));
    Iterator<Entity> results = datastore.prepare(transaction, query).asIterator();
    while (results.hasNext()) {
      Entity stateEntity = results.next();
      datastore.delete(transaction, stateEntity.getKey());
    }
    transaction.commit();
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:18,代码来源:DatastoreSessionFilter.java


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