podagation.requires_new在JDBC级别上工作?

发布于 2025-02-02 03:18:28 字数 1161 浏览 3 评论 0 原文

我已经阅读了文档,并且了解了传播的方式。requires_new有效,但

Create a new transaction, and suspend the current transaction if one exists. Analogous to the EJB transaction attribute of the same name.
NOTE: Actual transaction suspension will not work out-of-the-box on all transaction managers. This in particular applies to org.springframework.transaction.jta.JtaTransactionManager, which requires the javax.transaction.TransactionManager to be made available to it (which is server-specific in standard Java EE).
See Also:
org.springframework.transaction.jta.JtaTransactionManager.setTransactionManager

我不明白暂停如何工作。

对于单级事务,我想Spring会创建这样的代码:

Connection connection = DriverManager.getConnection(...);

try {
  connection.setAutoCommit(false);
  PreparedStatement firstStatement = connection.prepareStatement(...);

  firstStatement.executeUpdate();

  PreparedStatement secondStatement = connection.prepareStatement(...);

  secondStatement.executeUpdate();
  connection.commit();
} catch (Exception e) {
  connection.rollback();
}

您能为 propagation.requires_new 提供一个示例吗?

它是否通过JDBC保存点以某种方式完成?

I've read the documentation and I understand how Propagation.REQUIRES_NEW works but

Create a new transaction, and suspend the current transaction if one exists. Analogous to the EJB transaction attribute of the same name.
NOTE: Actual transaction suspension will not work out-of-the-box on all transaction managers. This in particular applies to org.springframework.transaction.jta.JtaTransactionManager, which requires the javax.transaction.TransactionManager to be made available to it (which is server-specific in standard Java EE).
See Also:
org.springframework.transaction.jta.JtaTransactionManager.setTransactionManager

I can't understand how suspension could work.

For a single level transaction I suppose that spring creates the code like this:

Connection connection = DriverManager.getConnection(...);

try {
  connection.setAutoCommit(false);
  PreparedStatement firstStatement = connection.prepareStatement(...);

  firstStatement.executeUpdate();

  PreparedStatement secondStatement = connection.prepareStatement(...);

  secondStatement.executeUpdate();
  connection.commit();
} catch (Exception e) {
  connection.rollback();
}

Could you please provide an example for the Propagation.REQUIRES_NEW?

Is it done somehow via jdbc savepoint?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不甘平庸 2025-02-09 03:18:28

,但我不明白暂停如何起作用。

大多不是。

是通过JDBC SavePoint以某种方式完成的?

JDBC不支持暂停交易的概念(它支持了子交易的概念,但是 - 这就是SavePoint的意义。JDBC确实如此,也就是说 - 许多DB发动机都没有)。

那么 它如何工作?

通过超越JDBC的范围。数据库需要支持它,驱动程序还需要在JDBC API之外进行支持。因此,通过基于非JDBC的DB交互模型或发送SQL命令。

例如,在WebLogic中,有。这不是开源的,所以我不知道它是如何工作的,但是它是单独的API(不是JDBC)的事实。

这也说, jtatransactionManager 的Javadoc说,只有2个已知的实现,并且这些实现非常接近JTA中的定义。

直接从那个Javadoc:

WebSphere特定的PlatformTransActionManager实现,该实现将从WebSphere的JNDI环境中获得的UOWMANAGER实例。

所以,jndi。确实,“ Voodoo跳过JDBC直接与数据库魔术交谈”。

but I can't understand how suspension could work.

It mostly doesn't.

Is it done somehow via jdbc savepoint ?

JDBC doesn't support the notion of suspending transactions (it supports the notion of subtransactions, though - that's what savepoints are about. JDBC does, that is - many DB engines do not).

So how does it work?

By moving beyond the confines of JDBC. The database needs to support it, and the driver also needs to support it, outside of the JDBC API. So, via a non-JDBC-based DB interaction model, or by sending an SQL command.

For example, In WebLogic, there's the WebLogic TransactionManager. That's not open source, so I have no idea how it works, but the fact that it's a separate API (not JDBC) is rather telling.

It's also telling that the javadoc of JtaTransactionManager says that there are only 2 known implementations, and that these implementations steer quite close to the definitions in JTA.

Straight from that javadoc:

WebSphere-specific PlatformTransactionManager implementation that delegates to a UOWManager instance, obtained from WebSphere's JNDI environment.

So, JNDI then. "Voodoo skip JDBC talk directly to the database magic" indeed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文