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


Java PreparedQuery.asList方法代码示例

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


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

示例1: getNationalHighScores

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

示例2: getMonthlyHighScores

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

示例3: getWeeklyHighScores

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

示例4: getDailyHighScores

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

示例5: hasRelation

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

示例6: findDeviceByRegId

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
private static Entity findDeviceByRegId(String regId) {
  Query query = new Query(DEVICE_TYPE)
      .addFilter(DEVICE_REG_ID_PROPERTY, FilterOperator.EQUAL, regId);
  PreparedQuery preparedQuery = datastore.prepare(query);
  List<Entity> entities = preparedQuery.asList(DEFAULT_FETCH_OPTIONS);
  Entity entity = null;
  if (!entities.isEmpty()) {
    entity = entities.get(0);
  }
  int size = entities.size();
  if (size > 0) {
    logger.severe(
        "Found " + size + " entities for regId " + regId + ": " + entities);
  }
  return entity;
}
 
开发者ID:army-of-dumbledore,项目名称:pennappsF13,代码行数:17,代码来源:Datastore.java

示例7: findByBuildTypeIdOrderByBuildIdDesc

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
/**
 * Finds the {@code TestReport} with the given build type id ordered by build id in the descendant order.
 *
 * @param buildTypeId      the build type id.
 * @param limit            the optional fetch limit, by default {@link com.google.appengine.tck.site.endpoints.TestReport#DEFAULT_FETCH_LIMIT}.
 * @param reports          the reports entry point
 * @return the matching test reports list or an empty one if none.
 */
@SuppressWarnings("unchecked")
public static List<TestReport> findByBuildTypeIdOrderByBuildIdDesc(String buildTypeId, Optional<Integer> limit, Reports reports) {
    final MemcacheService memcacheService = reports.getMemcacheService();
    List<TestReport> results = (List<TestReport>) memcacheService.get(buildTypeId);
    if (results == null) {
        final Filter buildTypeFilter = new Query.FilterPredicate("buildTypeId", FilterOperator.EQUAL, buildTypeId);
        final Query query = new Query(TEST_REPORT).setFilter(buildTypeFilter).addSort("buildId", DESCENDING);

        final DatastoreService datastoreService = reports.getDatastoreService();
        final PreparedQuery preparedQuery = datastoreService.prepare(query);
        final List<Entity> entities = preparedQuery.asList(FetchOptions.Builder.withLimit(limit.or(DEFAULT_FETCH_LIMIT)));

        results = new ArrayList<>();
        for (Entity oneEntity : entities) {
            final TestReport report = from(oneEntity);
            results.add(report);
        }

        memcacheService.put(buildTypeId, results);
    }
    return results;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:31,代码来源:TestReport.java

示例8: testFilterByEntityKey

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Test
public void testFilterByEntityKey() {
    Entity parentEntity = createTestEntityWithUniqueMethodNameKey(TEST_ENTITY_KIND, "testFilterByEntityKey");
    Key parentKey = parentEntity.getKey();

    Key fooKey = KeyFactory.createKey(parentKey, "foo", 1);
    Entity fooEntity = new Entity(fooKey);
    service.put(fooEntity);

    Query query = new Query("foo")
        .setAncestor(parentKey)
        .setFilter(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, EQUAL, fooKey));

    PreparedQuery preparedQuery = service.prepare(query);
    List<Entity> results = preparedQuery.asList(FetchOptions.Builder.withDefaults());

    assertEquals(1, results.size());
    assertEquals(fooEntity, results.get(0));
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:20,代码来源:QueryFilteringByGAEPropertyTypesTest.java

示例9: testQueryWithoutAnyConstraints

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Test
public void testQueryWithoutAnyConstraints() throws Exception {
    Key parentKey = createQueryBasicsTestParent("testQueryWithoutAnyConstraints");

    Entity person = new Entity("Person", parentKey);
    service.put(person);

    Entity address = new Entity("Address", parentKey);
    service.put(address);

    PreparedQuery preparedQuery = service.prepare(new Query().setAncestor(parentKey));
    assertTrue(preparedQuery.countEntities(withDefaults()) >= 2);

    List<Entity> results = preparedQuery.asList(withDefaults());
    assertTrue(results.containsAll(Arrays.asList(person, address)));
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:17,代码来源:QueryBasicsTest.java

示例10: findDeviceByRegId

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
/**
 * Returns the device object with the given registration ID.
 */
private static Entity findDeviceByRegId(String regId) {
    Query query = new Query(DEVICE_TYPE)
            .addFilter(DEVICE_REG_ID_PROPERTY, FilterOperator.EQUAL, regId);
    PreparedQuery preparedQuery = ds.prepare(query);
    List<Entity> entities = preparedQuery.asList(DEFAULT_FETCH_OPTIONS);
    Entity entity = null;
    if (!entities.isEmpty()) {
        entity = entities.get(0);
    }
    int size = entities.size();
    if (size > 0) {
        logger.severe(
                "Found " + size + " entities for regId " + regId + ": " + entities);
    }
    return entity;
}
 
开发者ID:amardeshbd,项目名称:google-iosched,代码行数:20,代码来源:Datastore.java

示例11: getLastStatus

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
private ArrayList<Medicion> getLastStatus(int amountData) {
    // Poner Key estacion + hora_muestra
    Calendar calendarTwoAgo = Calendar.getInstance(TimeZone.getTimeZone("CET"));
    calendarTwoAgo.add(Calendar.DATE, -3);
    Date dateTwoAgo = calendarTwoAgo.getTime();

    // Prepare
    Query.Filter keyFilter = new Query.FilterPredicate(PROPERTY_MEASURE_DATE, Query.FilterOperator.GREATER_THAN, dateTwoAgo);
    Query.Filter no2Filter = new Query.FilterPredicate(PROPERTY_COMPUESTO, Query.FilterOperator.EQUAL, NO2.name());
    List<Query.Filter> filterList = new ArrayList<>();
    filterList.add(keyFilter);
    filterList.add(no2Filter);
    Query.Filter filter = new Query.CompositeFilter(Query.CompositeFilterOperator.AND, filterList);
    Query query = new Query(ENTITY_TYPE_MEDIDAS)
            .setFilter(filter)
            .addSort(PROPERTY_MEASURE_DATE
                    , Query.SortDirection.DESCENDING);

    // Query
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    PreparedQuery pq = datastore.prepare(query);
    // Get results

    List<com.google.appengine.api.datastore.Entity> resultList = pq.asList(FetchOptions.Builder.withLimit(amountData));
    ArrayList<Medicion> result = new ArrayList<>();
    if (resultList.size()!=0) {
        mLogger.info("Watching " + resultList.size() + " last values of ESTADO");
        for (com.google.appengine.api.datastore.Entity item : resultList){
            result.add(new Medicion((Date) item.getProperty(PROPERTY_MEASURE_DATE), (String) item.getProperty(PROPERTY_AVISO), (String) item.getProperty(PROPERTY_AVISO_STATE), (String) item.getProperty(PREPERTY_AVISO_MAX_TODAY), (String) item.getProperty(PROPERTY_ESCENARIO_STATE_TODAY), (String) item.getProperty(PROPERTY_ESCENARIO_STATE_TOMORROW),  (String) item.getProperty(PROPERTY_ESCENARIO_STATE_TOMORROW_MANUAL) ,isPureMadrid()));
        }
    } else {
        // No hay datos
        mLogger.info("No previous values for ESTADO");
    }
    return result;
}
 
开发者ID:medialab-prado,项目名称:puremadrid,代码行数:37,代码来源:GetNewData.java

示例12: getGlobalHighScores

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
/**
 * Method to retrieve the global high scores 
 * @return
 */
public List<Entity> getGlobalHighScores(){
	log.info("Retrieving global high scores");
	//create the query to read the records sorted by score
	Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
	PreparedQuery pq = datastore.prepare(q);
	//retrieve and return the list of records	
	return pq.asList(FetchOptions.Builder.withLimit(100));
}
 
开发者ID:mastorak,项目名称:LeaderboardServer,代码行数:13,代码来源:ScoreDAO.java

示例13: cleanDatastore

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
public static void cleanDatastore(DatastoreService ds, String book) {
  Query query = new Query("Greeting")
      .setAncestor(new KeyFactory.Builder("Guestbook", book)
          .getKey()).setKeysOnly();
  PreparedQuery pq = ds.prepare(query);
  List<Entity> entities = pq.asList(FetchOptions.Builder.withDefaults());
  ArrayList<Key> keys = new ArrayList<>(entities.size());

  for (Entity e : entities) {
    keys.add(e.getKey());
  }
  ds.delete(keys);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:14,代码来源:GuestbookTestUtilities.java

示例14: usesForTransactions_readSnapshot

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Test
public void usesForTransactions_readSnapshot() throws Exception {
  String boardName = "my-message-board";
  Entity b = new Entity("MessageBoard", boardName);
  b.setProperty("count", 13);
  datastore.put(b);

  // [START uses_for_transactions_3]
  DatastoreService ds = DatastoreServiceFactory.getDatastoreService();

  // Display information about a message board and its first 10 messages.
  Key boardKey = KeyFactory.createKey("MessageBoard", boardName);

  Transaction txn = datastore.beginTransaction();

  Entity messageBoard = datastore.get(boardKey);
  long count = (Long) messageBoard.getProperty("count");

  Query q = new Query("Message", boardKey);

  // This is an ancestor query.
  PreparedQuery pq = datastore.prepare(txn, q);
  List<Entity> messages = pq.asList(FetchOptions.Builder.withLimit(10));

  txn.commit();
  // [END uses_for_transactions_3]

  assertThat(count).named("board.count").isEqualTo(13L);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:30,代码来源:TransactionsTest.java

示例15: getTallestPeople

import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
private List<Entity> getTallestPeople() {
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  Query q = new Query("Person").addSort("height", SortDirection.DESCENDING);

  PreparedQuery pq = datastore.prepare(q);
  return pq.asList(FetchOptions.Builder.withLimit(5));
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:QueriesTest.java


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