我使用 eclipse 创建了一个 google app engine 客户端,并且 google 分发了 android demo。我创建了后端和一些模型。当我在 GAE 上将一个实体从 android 添加到我的数据库时,它会按日期而不是按最新创建的顺序对其进行排序。关键它只是当前日期并与 android 绑定。我不确定如何使用后端,因为谷歌在我的项目中为我创建了它。我是否可以对其进行快速更改,或者当我添加一个项目时它会通过数据对其进行排序,它只会将最新的列表保留在顶部?
编辑后的问题,这是 Google 为我生成的端点类。如何修改它以首先接收最新添加的实体?
@Api(name = "quotesendpoint", namespace = @ApiNamespace(ownerDomain = "projectquotes.com" ownerName = "projectquotes.com", packagePath = ""))
public class quotesEndpoint {
/**
* 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.
*/
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listquotes")
public CollectionResponse<quotes> listquotes(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<quotes> execute = null;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from quotes as quotes");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<quotes>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (quotes obj : execute)
;
} finally {
mgr.close();
}
return CollectionResponse.<quotes> builder().setItems(execute)
.setNextPageToken(cursorString).build();