简体   繁体   English

使用Java随机查询Google App Engine数据存储区实体

[英]Random querying for Google App Engine Datastore entities using Java

Let's say I have 100 entities in my datastore. 假设我的数据存储区中有100个实体。

I have sorted my query on basis of a property say "age" using 我已经根据使用“年龄”的属性对查询进行了排序,

Query q = new Query("EntityTYPE").addSort("age", SortDirection.DESCENDING);

I have a variable startPoint from another function which tells me the start point of the result needed. 我从另一个函数有一个变量startPoint,它告诉我所需结果的起点。

Now that I need to query 10 entities (startPoint to startPoint+10) from the sorted query. 现在,我需要从已排序的查询中查询10个实体(从startPoint到startPoint + 10)。

Example: If startPoint = 51, I need result entity to have values of 51-61 rows of the sorted query. 示例:如果startPoint = 51,则我需要结果实体具有已排序查询的51-61行的值。

How can I implement this in Java? 如何用Java实现呢?

Please do comment if any further information is necessary. 如果需要进一步的信息,请发表评论。

The way to do something like this would be to use an "offset". 做这样的事情的方法是使用“偏移”。 Unfortunately, the way offset it implemented, it doesn't "skip" looking at 1-50. 不幸的是,它实现的补偿方式并没有“跳过” 1-50。 It'll read them (costing you a read in your daily quotas/budgets), and return the following results. 它将读取它们(使您的每日配额/预算花费一读),然后返回以下结果。 It will do what you want, but it will still charge you, unfortunately, 它会做您想要的,但不幸的是,它仍然会向您收费,

You'd have to write something like 你必须写一些像

List<Entity> getRandomEntities() {
   DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  Query queryForEntities = new Query("Entity");

  PreparedQuery preppedEntityQuery = datastore.prepare(q);
  return preppedEntityQuery.asList(FetchOptions.Builder.withOffset([OFFSET_YOU_WANT]).withLimit([AMOUNT_YOU_WANT]));
}

Look into this if you need additional info :) 如果需要其他信息,请查看信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Google App Engine数据存储区中的实体列表 - Using lists of entities in Google App Engine Datastore Google App Engine HR数据存储-Java-以编程方式删除实体 - Google App Engine HR Datastore - Java - Delete Entities programatically 在Google应用引擎java本地数据存储区中添加/编辑实体 - Add/Edit Entities in google app engine java local datastore 覆盖Google App Engine- Java中的数据存储区实体 - Overwrite Datastore entities in Google App Engine- Java 计算数据存储区Google App引擎中的实体 - Count entities in datastore Google app engine 使用乐观锁定创建新的数据存储区实体(Google App Engine Java / JPA) - Creating new Datastore entities with optimistic locking (Google App Engine Java / JPA) Google App Engine DataStore - 如何以有效的方式从 Java 中子表的键中获取 select 父实体? - Google App Engine DataStore - How to select parent entities from keys of a child table in Java in an efficient way? 查询Google App Engine数据存储时的并发问题 - Concurrency issues when querying the Google App Engine datastore 在App Engine Java Servlet中查询数据存储区统计信息时发生NullpointerException - NullpointerException while querying for the Datastore statistics in App Engine Java Servlet 更新Google App Engine的DataStore中的查询-Java - Update query in DataStore of google app engine - java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM