2010-12-10 114 views
0

分佈式事務的例子slim3從例如<a href="http://sites.google.com/site/slim3appengine/" rel="nofollow">http://sites.google.com/site/slim3appengine/</a> AppEngine上

@Model 
public class Account { 

    @Attribute(primaryKey = true) 
    private Key key; 

    private Integer balance; 
    ... 
} 

我不明白爲什麼這樣做匯款需要2個不同的交易,因爲這是唯一的一個實體(同一實體)

Acount src = gtx.get(Acount.class, srcKey); //arent src and des same entity? why do 2 trans? 
    Acount dest = gtx.get(Acount.class, destKey); 
    if (src.getBalance() >= amount) { 
     src.setBalance(src.getBalance() - amount); 
     dest.setBalance(dest.getBalance() + amount); 
    } 

回答

1

src和dest是不同的實體 - 你用單獨的鍵(srcKey和destKey)來獲取它們。

+0

是獨立的實體,我同意。但都使用相同的實體組。所以不能在一個週期內完成交易?而不是2? – cometta 2010-12-14 04:09:12

+1

@cometta他們不在同一個實體組中。實體組是具有相同父代的實體,並且上述兩個實體都是根實體,沒有父母。 – 2010-12-14 22:53:52

相關問題