0

我正在尝试在实体的端点类中添加一个新方法。但是,当我右键单击我的应用程序引擎项目以生成端点客户端库时,eclipse 会抛出消息,指出生成端点库已引发错误。下面是我在端点库中为我的实体添加的代码。谁能建议这里有什么问题。

          @SuppressWarnings("unchecked")
    public List<UserTable> getUserTableByEmail(String email) {
        EntityManager mgr = null;
        List<UserTable> execute = null;
        try {
            mgr = getEntityManager();
            Query query = mgr.createQuery("select n from UserTable n where n.emailAddress = :emailAddress");
            query.setParameter("emailAddress", email);
            execute = (List<UserTable>) query.getResultList();
        } finally {
            mgr.close();
        }
        return execute;
    }
4

1 回答 1

0

下面更新了工作代码,用于使用我的自定义查询添加我自己的端点方法。

@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "getUserTableByEmail")
public CollectionResponse<UserTable> getUserTableByEmail(
        @Nullable @Named("cursor") String cursorString,
        @Nullable @Named("limit") Integer limit,
        @Named ("emailAddres") String email) {

    EntityManager mgr = null;
    Cursor cursor = null;
    List<UserTable> execute = null;

    try {
        mgr = getEntityManager();
        Query query = mgr.createQuery("select n from UserTable n where n.emailAddress = '"+email+"'");
        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<UserTable>) 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 (UserTable obj : execute)
            ;
    } finally {
        mgr.close();
    }

    return CollectionResponse.<UserTable> builder().setItems(execute)
            .setNextPageToken(cursorString).build();
}
于 2013-06-07T04:59:49.450 回答