Objectify 查询结果与数据存储查看器结果不一致的问题?

2024-03-24

我正在编写一个基于 TodoMVC angularjs 的示例项目(http://todomvc.com/ http://todomvc.com/)并使用带有 Google App Engine Cloud Endpoint 的后端 api,当从 App Engine 数据存储区获取待办事项列表时,我得到了一些一致性结果。

Todo 对象使用 objectify 存储在 App Engine 数据存储区中。

Todo 实体的编码如下:

@Entity
public class Todo {

    @Id
    private Long id;
    private String title;
    private boolean completed;
    private Date lastEdit;

    @Index
    private Long userId;

    public Todo() {
    }

    public Todo(String title, boolean completed) {
        this.title = title;
        this.completed = completed;
    }

    public Todo(Long id, String title, boolean completed) {
        this.id = id;
        this.title = title;
        this.completed = completed;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public boolean isCompleted() {
        return completed;
    }

    public void setCompleted(boolean completed) {
        this.completed = completed;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Date getLastEdit() {
        return lastEdit;
    }

    public void setLastEdit(Date lastEdit) {
        this.lastEdit = lastEdit;
    }

    @Override
    public String toString() {
        return "Todo{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", completed=" + completed +
                ", lastEdit=" + lastEdit +
                ", userId='" + userId + '\'' +
                '}';
    }
}

将 Todo 保存在数据存储中的操作如下:

@ApiMethod(name = "create", httpMethod =  ApiMethod.HttpMethod.POST)
public Todo create(User user, Todo todo) {
    logger.info("creating todo : " + todo.toString());

    todo.setUserId(new Long(user.getUserId()));
    todo.setLastEdit(new Date());
    ofy().save().entity(todo).now();

    return todo;
}



@ApiMethod(name = "list", httpMethod =  ApiMethod.HttpMethod.GET)
public Collection<Todo> getTodos(User user) {
    logger.info("user:" + user);

    List<Todo> todos = null;

    if (user != null) {
        todos = ofy().consistency(ReadPolicy.Consistency.STRONG).load().type(Todo.class).filter("userId", new Long(user.getUserId())).list();
    }

    logger.info("todos:" + todos);

    return todos;
}

假设我的列表中有 4 个待办事项,我将它们全部设置为已完成 (completed=true)。 我在数据存储查看器中检查它们的状态:

然后,如果我在几秒钟后请求列表,我将遇到奇怪的一致性问题:

2014-03-08 13:08:43.326
fr.xebia.gae.todo.api.TodoEndpointV2 getTodos: todos:[
Todo{id=5639274879778816, title='vélo', completed=false, lastEdit=Fri Mar 07 23:36:08 UTC 2014, userId='104955400895435072612'}, 
Todo{id=5676830073815040, title='train', completed=true, lastEdit=Sat Mar 08 12:08:30 UTC 2014, userId='104955400895435072612'}, 
Todo{id=5717271485874176, title='avion', completed=false, lastEdit=Fri Mar 07 23:36:09 UTC 2014, userId='104955400895435072612'}, 
Todo{id=5757334940811264, title='voiture', completed=true, lastEdit=Sat Mar 08 12:08:32 UTC 2014, userId='104955400895435072612'}]

正如您所看到的,所有待办事项的完成值均未设置为 true,并且它们的最后编辑日期甚至未更新

2分钟后新请求:

2014-03-08 13:10:20.612
fr.xebia.gae.todo.api.TodoEndpointV2 getTodos: todos:[
Todo{id=5639274879778816, title='vélo', completed=false, lastEdit=Fri Mar 07 23:36:08 UTC 2014, userId='104955400895435072612'}, 
Todo{id=5676830073815040, title='train', completed=true, lastEdit=Sat Mar 08 12:08:30 UTC 2014, userId='104955400895435072612'}, 
Todo{id=5717271485874176, title='avion', completed=false, lastEdit=Fri Mar 07 23:36:09 UTC 2014, userId='104955400895435072612'}, 
Todo{id=5757334940811264, title='voiture', completed=true, lastEdit=Sat Mar 08 12:08:32 UTC 2014, userId='104955400895435072612'}]

17 分钟后又提出新要求,但仍然不是好的价值......

2014-03-08 13:27:07.918
fr.xebia.gae.todo.api.TodoEndpointV2 getTodos: todos:[Todo{id=5639274879778816, title='vélo', completed=false, lastEdit=Fri Mar 07 23:36:08 UTC 2014, userId='104955400895435072612'}, 
Todo{id=5676830073815040, title='train', completed=true, lastEdit=Sat Mar 08 12:08:30 UTC 2014, userId='104955400895435072612'}, 
Todo{id=5717271485874176, title='avion', completed=false, lastEdit=Fri Mar 07 23:36:09 UTC 2014, userId='104955400895435072612'}, 
Todo{id=5757334940811264, title='voiture', completed=true, lastEdit=Sat Mar 08 12:08:32 UTC 2014, userId='104955400895435072612'}]

有人知道为什么使用 Objectify 查询的内容与使用 GAE 数据存储查看器后台查看的内容之间存在如此大的差异吗? 是一致性问题吗?但如果是这样,为什么数据存储查看器没有同样的问题? 我在查询时是否滥用 objectify (如果我在运行过滤器时设置 ofy().consistency(ReadPolicy.Consistency.STRONG) 的事件)?


我没有很好地阅读 objectify 设置,并且错过了它告诉人们应该将以下内容添加到 web.xml 的部分

<filter>
     <filter-name>ObjectifyFilter</filter-name>
     <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
</filter>
<filter-mapping>
     <filter-name>ObjectifyFilter</filter-name>
     <url-pattern>/*</url-pattern> 
</filter-mapping>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Objectify 查询结果与数据存储查看器结果不一致的问题? 的相关文章

随机推荐

  • 两个 NSDate 之间的天数[重复]

    这个问题在这里已经有答案了 如何确定两次之间的天数NSDate值 也考虑到时间 The NSDate值可以是任何形式 NSDate date takes 具体来说 当用户在我的 iPhone 应用程序中进入非活动状态时 我存储以下值 exi
  • 如何检查变量是否是类的实例?

    在Java中 你可以这样做instanceof 有 Ruby 等价的吗 几乎一模一样 您可以使用Object s instance of method a instance of String gt true a instance of O
  • 使用 Perl split 函数,但保留某些分隔符

    我有一个字符串需要根据某个字符进行拆分 但是 当字符串两侧是数字时 我只需要在其中一个字符上拆分字符串 相同的字符存在于字符串中的其他位置 但两侧会有一个字母 至少在一侧 我尝试按如下方式使用 split 函数 使用 x 作为相关字符 my
  • 更改四开中的标题大小和颜色(html 输出)

    我有一个带有 HTML 渲染的四开文件 我想更改标题的大小和颜色 我应该如何操作 最小的例子 title Cars format html MTCars r head mtcars 您可以使用css直接在您的代码中 指定 title仅将更改
  • NuGet 打包和引用 dll

    背景 我有两个程序集 称为 A 和 B A 引用了 B A 还引用了一些其他 dll Microsoft Enterprise Library Data 和 Microsoft Enterprise Library Common 我认为这些
  • spring security - expiredUrl 不起作用

    我需要配置expired url在我的 Spring MVC 应用程序中 这是我的努力 但没有效果 Override protected void configure HttpSecurity http throws Exception h
  • 在 Android Studio 中调试 C++ 时“启动 LLDB 服务器”

    我想在 Android Studio 中调试 C 模块 我在 android studio 中创建了一个支持 C 的项目 When i debug this is what i get 启动 LLDB 服务器 永远不会停止 如果我停止调试
  • $_SERVER['document_root'] 返回 /htdocs 而不是 /public_html

    我正在寻找切换到新主机的机会 他们提供了这个不错的小 临时 URL 以便在切换之前测试您的文件 一切都很好 花花公子 所以我复制了所有文件 在每一页的顶部我require来自服务器的另一个文件 存储在public html includes
  • SQL 按匹配字段数对结果进行排序

    这里有一个复杂的 SQL 问题 我目前有一个匹配多个字段的 SELECT 语句 如下所示 SELECT field1 field2 field3 field4 field5 FROM table WHERE field1 variable
  • 转换为枚举与 Enum.ToObject

    我最近看到一个项目正在使用这个style SomeEnum Enum ToObject typeof SomeEnum some int 而不是这种风格 SomeEnum some int 为什么使用前者 这只是风格问题吗 来自 MSDN
  • intl 扩展名应该可用 symfony

    现在如果我去http localhost 8000 config php http localhost 8000 config php它告诉我 安装并启用 intl 扩展 用于验证器 所以我所做的是 Checked etc php 7 0
  • Mac App Store 应用程序 iTMSTransporter 错误

    我正在尝试将我的 pkg 文件发送给 Apple 但系统显示 Transporter 正在搜索更新的软件组件 并且该进程始终在运行 无法停止 这是我的活动日志 看起来像是上传错误 我已经安装了 iTMSTransporter 1 7 7 p
  • Spring 的 Azure Pipeline Gradle 构建失败

    我尝试通过 Yaml 管道在 Azure 上构建和部署 Spring API 但我在 spring 应用程序 gradle 构建期间收到错误消息 Error home vsts work 1 s gradlew failed with re
  • ionic 5 强制浏览器应用程序的浅色主题

    我已经构建了这个应用程序https cvirus app https cvirus app并在浏览器上构建和部署 在 Android 手机上的 Chrome 浏览器上 它会呈现深色背景 因为默认情况下似乎应用了深色主题 我想在任何地方强制使
  • Postgres LIKE 将列值作为子字符串

    我正在尝试编写一个 WHERE 语句 该语句将匹配列值是另一个字符串的子字符串的行 例如 我可能有一个event记录与name现场Edward Sharpe 我想做这样的事情 SELECT FROM events WHERE name LI
  • 如何在 X 秒后应用 window.close() ?

    我有一个弹出窗口 其中包含 onclick 操作 可以在按下提交按钮时关闭该框
  • UIBezierPath 的橡皮擦

    我正在使用 UIBezierPath 在 iPad 应用程序中进行免费手绘 我想用橡皮擦乌贝济耶路径 questions tagged uibezierpath 不过 我想only擦除其路径中的图形 我cannot使用路径颜色作为背景颜色
  • htmlspecialchars 输出空白

    同时使用 htmlspecialchars 和 htmlentities 会导致项目的空白输出 例如 符号甚至单个 引号 显然 这绝对没用 但是在不使用 html 字符的情况下输出数据会导致 和 都出现此符号 出现这种情况有什么原因吗 这是
  • 填充在 iE 中不起作用?

    我希望内容周围 元素边框内有空间 http www w3schools com CSS css padding asp http www w3schools com CSS css padding asp 我使用了 cellpadding
  • Objectify 查询结果与数据存储查看器结果不一致的问题?

    我正在编写一个基于 TodoMVC angularjs 的示例项目 http todomvc com http todomvc com 并使用带有 Google App Engine Cloud Endpoint 的后端 api 当从 Ap