简体   繁体   English

GAE实体组/交易

[英]GAE Entity Groups/Transaction

Say you have a Client Buying Card object and a product object. 假设您有一个客户购买卡对象和一个产品对象。 When the client chooses the buy opition you create the object and then add a product. 当客户选择购买选项时,您将创建对象,然后添加产品。 It should be transactional but it's not on the same entity group as the product and the card already been persisted, isn't it? 它应该是可交易的,但它与产品不在同一实体组上,并且卡已被保留,不是吗? Is there any way to overcome this simple scenario safely and easily? 有什么方法可以安全,轻松地克服这种简单情况?

here's a code sample: 这是一个代码示例:

Transaction tx = pm.currentTransaction();
tx.begin();
Product prod = pm.getObjectById(Product.class, "TV");
prod.setReserved(true);
pm.makePersistent(prod);

Card card = pm.getObjectById(Card.class, "user123");   /// <--- will thorw an exception as card and prod aren't on the same entity group
card.setProd(prod);
pm.makePersistent(card);
try {
    tx.commit();
    break;
}

This blog post may be helpful: http://blog.notdot.net/2009/9/Distributed-Transactions-on-App-Engine 这篇博客文章可能会有所帮助: http : //blog.notdot.net/2009/9/Distributed-Transactions-on-App-Engine

(Even though the examples are in Python, the concept is exactly the same) (即使示例在Python中,概念也完全相同)

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

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