生成端点客户端库时出错

时间:2013-06-06 16:12:28

标签: android entity google-cloud-endpoints

我正在尝试在实体的端点类中添加新方法。但是,当我右键单击我的应用程序引擎项目以生成端点客户端库时,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;
    }

1 个答案:

答案 0 :(得分: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();
}