App多个多对一的JDO事务处理引擎 [英] App Engine JDO Transaction on multiple many-to-one
问题描述
驱动程序 - 键(字符串),运行计数,唯一跟踪计数
Track-key(字符串),run-count,unique-driver-count,best-time
运行键(?),驱动程序-key,track-key,time,boolean-driver-update,boolean-track-updated
我需要能够更新Run和Driver交易;以及同一个交易中的Run和Track(显然,为了确保我不会更新统计信息两次,或者错过了增量计数器)
现在我曾尝试将其分配为运行键,一个由driver-key / track-key / run-key(字符串)组成的键。
这会让我在一次事务中更新Run实体和Driver实体。
但是,如果我尝试一起更新Run和Track实体,它会抱怨它无法在多个组上进行交易。它表示它在交易中既有司机又有卡车,并且它不能同时运行......
tx.begin ();
run = pmf.getObjectById(Run.class,runKey);
track = pmf.getObjectById(Track.class,trackKey);
//这是失败的地方;
incrementCounters();
updateUpdatedFlags();
tx.commit();
奇怪的是,当我做类似的事情来更新Run和Driver时,它工作正常。
任何有关我如何映射我的域模型以实现相同功能的建议?
我认为我发现了一个横向但仍然清晰的解决方案,在我的域模型中仍然有意义。
域模型略有变化,如下所示:
Driver - key(string-id),driver-stats - ex。 id =Michael,runs = 17
Track - 键(string-id),track-stats - ex。 id =Monza,bestTime = 157
RunData - key(string-id),stat-data - TrackRun - 键(Track / string-id),track-stats-updated - ex。例如, DriverRun - 键(驱动程序/字符串 - ID),驱动程序 - 统计信息 - 更新的版本号 - Monza / Michael-Monza-20101010,track-stats-updated = false - 前。我现在可以更新自动化(即精确地,更准确地说, )立即或在我自己的时间内统计跑步的统计数据。 (和Driver / Run的统计数据一样)。
因此,基本上我必须以一种非常规的关系方式来扩展一些我的问题建模方式。你怎么看?I have a simple domain model as follows
Driver - key(string), run-count, unique-track-count
Track - key(string), run-count, unique-driver-count, best-time
Run - key(?), driver-key, track-key, time, boolean-driver-update, boolean-track-updated
I need to be able to update a Run and a Driver in the same transaction; as well as a Run and a Track in the same transaction (obviously to make sure i don't update the statistics twice, or miss out on an increment counter)
Now I have tried assigning as run key, a key made up of driver-key/track-key/run-key(string)
This will let me update in one transaction the Run entity and the Driver entity.
But if I try updating the Run and Track entities together, it will complain that it cannot transact over multiple groups. It says that it has both the Driver and the Truck in the transaction and it can't operate on both...
tx.begin(); run = pmf.getObjectById(Run.class, runKey); track = pmf.getObjectById(Track.class, trackKey); //This is where it fails; incrementCounters(); updateUpdatedFlags(); tx.commit();Strangely enough when I do a similar thing to update Run and Driver it works fine.
Any suggestions on how else I can map my domain model to achieve the same functionality?
解决方案I think I found a lateral but still clean solution which still makes sense in my domain model.
The domain model changes slightly as follows:
Driver - key(string-id), driver-stats - ex. id="Michael", runs=17
Track - key(string-id), track-stats - ex. id="Monza", bestTime=157
RunData - key(string-id), stat-data - ex. id="Michael-Monza-20101010", time=148
TrackRun - key(Track/string-id), track-stats-updated - ex. id="Monza/Michael-Monza-20101010", track-stats-updated=false
DriverRun - key(Driver/string-id), driver-stats-updated - ex. id="Michael/Michael-Monza-20101010", driver-stats-updated=true
I can now update atomically (i.e. precisely) the statistics of a Track with the statistics from a Run, immediately or in my own time. (And same with the Driver / Run statistics).
So basically I have to expand a little bit the way I model my problem, in a non-conventional relational way. What do you think?
这篇关于App多个多对一的JDO事务处理引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!