简体   繁体   English

parse.com数据存储区不会固定多个未保存的对象

[英]parse.com datastore not pinning more than one unsaved object

Within a Task and without any internet connection, I am creating a ParseObject and referencing another ParseObject and the current user in it. 在一个任务中,没有任何互联网连接,我正在创建一个ParseObject并引用另一个ParseObject和当前用户。 I'm then pinning it to the local datastore, for saving later (these classes and the datastore are correctly initialised). 然后我将其固定到本地数据存储区,以便稍后保存(这些类和数据存储区已正确初始化)。

    final Rating rating = new Rating(substationObjectId, data);

    // inside constructor
    put(KEY_OTHER_OBJECT, OtherObject.createWithoutData(OtherObject.class, substationObjectId));
    put(KEY_USER, ParseUser.getCurrentUser());

    rating.pin("unsent");

I follow this up with a quick query to fetch all Ratings from that pin. 我通过快速查询来跟进此操作,以从该引脚获取所有评级。

final ParseQuery<Rating> queryUnsent = ParseQuery.getQuery(Rating.class);
queryUnsent.whereEqualTo(Rating.KEY_USER, ParseUser.getCurrentUser());
queryUnsent.fromPin("unsent");
final List<Rating> unsentRatings = queryUnsent.find();

Logger.d(LOG_TAG, "queryUnsent count = %d", unsentRatings.size());
for (Rating unsentRating: unsentRatings) {
    Logger.d(LOG_TAG, "\tdatastore for %s with objectId='%s'", unsentRating().getName(), unsentRating.getObjectId());
}

The problem: only one Rating appears to be pinned. 问题:只有一个评级似乎固定。 A second Rating is not stored, even though parse reports success. 即使解析报告成功,也不会存储第二个评级。

First pinning (null objectId is ok and expected) of a Rating for 'Albury' yields these in a subsequent get-all query against the pin: 对于'Albury'的评级的第一个固定(null objectId是正确的和预期的)在针对该引脚的后续get-all查询中产生这些:

queryUnsent count = 1
datastore for Albury with objectId='null'

Second for 'Arapuni': 第二个'Arapuni':

queryUnsent count = 1
datastore for Albany with objectId='null'

Other things tried: 其他事情尝试过:

  • pinEventually("unsent") pinEventually( “未发送”)
  • pin() without a label pin()没有标签
  • save() immediately afterwards and discarding the connection exception 之后立即保存()并丢弃连接异常
  • removing user=current user clause from everywhere 从任何地方删除user = current user子句
  • general queries against the datastore as a whole confirm that additional objects are not stored at all 对数据存储区的一般查询作为一个整体确认根本没有存储其他对象

After coming online and saving the Rating (which gives it an objectId), a new offline Rating will be pinned correctly but the problem then repeats itself with a second offline Rating. 在上线并保存评级(给它一个objectId)后,新的离线评级将被正确固定,但问题会以第二个离线评级重复。

I have a feeling it's a bug with parse.com's Android SDK library. 我觉得这是parse.com的Android SDK库的一个错误。 It seems like the datastore is enforcing a unique constraint on objectId, but unsaved objects don't have an objectId yet. 看起来数据存储区正在对objectId强制执行唯一约束,但未保存的对象还没有objectId。

Has anybody else run into this issue, or can suggest a work around? 有没有其他人遇到这个问题,或者可以建议一个解决方案?

This is truly odd. 这真是奇怪。

As I wrote in the comments my problems mainly involved getting unsaved objects unpinned, and so I started creating a project that would resemble some of the behavior in my app with a reproducible demonstration of the problem. 正如我在评论中所写,我的问题主要涉及取消未保存的对象,因此我开始创建一个类似于我的应用程序中的一些行为的项目,并且可以重现性地演示问题。

The Android Studio project can be found here: https://www.dropbox.com/sh/6whcw0qa1wdmnl2/AAAeELECIxgDjfa5ICULn2Zya?dl=0 可以在此处找到Android Studio项目: https//www.dropbox.com/sh/6whcw0qa1wdmnl2/AAAeELECIxgDjfa5ICULn2Zya?dl=0

About the project 关于该项目

The idea I have been trying to realize is to tie a task (ParseObject) together with a log entry (another ParseObject) and a JSONArray in a object called TaskSummaryHolder. 我一直想要实现的想法是在一个名为TaskSummaryHolder的对象中将任务(ParseObject)与日志条目(另一个ParseObject)和JSONArray绑定在一起。

Having these 3 entities tied together locally, I can push a lot of information into the JSONArray and only periodically push the information from the JSONArray to the log entry. 将这3个实体绑定在本地,我可以将大量信息推送到JSONArray中,并且只定期将信息从JSONArray推送到日志条目。

The summary object that binds it all together are never meant to be stored online. 将它们绑定在一起的汇总对象永远不会在线存储。

This scheme should be possible to apply to a range of different tasks so that one TaskSummaryHolder instance can store occurring events over a time period, while another keeps eg GPS entries. 该方案应该可以应用于一系列不同的任务,以便一个TaskSummaryHolder实例可以存储一段时间内发生的事件,而另一个保存例如GPS条目。

Currently I have something somewhat similar to what is shown in the project in a live app, but due to the unpinning problem I am currently clearing the summaries instead of unpinning (removing columns and pinning). 目前我有一些类似于实时应用程序中项目中显示的内容,但由于解决问题,我目前正在清除摘要而不是取消固定(删除列和固定)。

Problem 1 unpinning 问题1取消固定

My first observation was that 我的第一个观察是

ParseObject.unpinAllInBackground(TaskSummaryHolder.PIN)

Did not always work, whereas 并不总是有效

ParseObject.unpinAllInBackground(TaskSummaryHolder.PIN, summaries)

Seemed more reliable. 似乎更可靠。 Just a bit strange if one has to query before unpinning if the goal is to purge a pin from the datastore. 如果必须在取消固定之前进行查询,如果目标是从数据存储区清除引脚,则有点奇怪。

Problem 2 pinning 问题2钉扎

To my surprise I encountered exactly the problem you describe. 令我惊讶的是,我遇到了你描述的问题。 In the test project I fetch two tasks online and add a TaskSummaryHolder instance to each of them. 在测试项目中,我在线获取两个任务,并为每个任务添加一个TaskSummaryHolder实例。 Only the first instance got pinned locally. 只有第一个实例被固定在本地。

Inspired by your description of the problem, I tried to let it pin and then save (see TaskSummaryHolder line 114). 受到您对问题的描述的启发,我试图让它固定然后保存(参见TaskSummaryHolder第114行)。

After this it worked an have been unable to reproduce the problem from then on wards. 在此之后它工作了一直无法从病房重现问题。 Both pinning and unpinning behaved as expected even after uninstall and/or restart of phone. 即使在卸载和/或重新启动手机后,固定和取消固定也都按预期运行。

It could be interesting if you would try and run the project and see how it behaves. 如果您尝试运行项目并查看其行为方式,可能会很有趣。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM