【问题标题】:GAE: Do puts and gets inside a cross group transaction (XG) need to be called with the transaction as parameter?GAE:跨组事务 (XG) 中的 put 和 get 是否需要以事务作为参数调用?
【发布时间】:2013-12-16 23:35:25
【问题描述】:

我刚刚注意到 XG 事务的 docs' example 使用包含事务作为参数的 put 方法,但它没有提到这样做的必要性。

TransactionOptions options = TransactionOptions.Builder.withXG(true);
Transaction txn = datastore.beginTransaction(options);

Entity a = new Entity("A");
a.setProperty("a", 22);
datastore.put(txn, a);

Entity b = new Entity("B");
b.setProperty("b", 11);
datastore.put(txn, b);

txn.commit();

根据API,单参数put(和get)使用事务:

如果有当前事务,该操作将在 那笔交易

我担心 XG 交易。如果我在该示例中只使用为两个实体放置的单个参数(并且我有很多这样的代码),它们是否仍会在 XG 事务中执行?

【问题讨论】:

    标签: java google-app-engine transactions google-cloud-datastore


    【解决方案1】:

    是的,它们都仍将在 XG 事务中执行。

    如果您没有明确指定事务,将使用最近创建的事务。 DatastoreService 存储使用beginTransaction 创建的事务堆栈,并在没有显式事务的情况下执行puts 时使用顶部的事务。它不会对您的 XG 事务有任何不同的处理,它只会将其从堆栈中拉出并使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2012-06-04
      • 2022-07-05
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多