`
eastPoint
  • 浏览: 53433 次
  • 性别: Icon_minigender_1
  • 来自: 湖北武汉
社区版块
存档分类
最新评论

Programmatic transaction demarcation

阅读更多
xml 代码
  1. <beans>  
  2.    ...   
  3.   
  4.    <bean id="myTxManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">  
  5.      <property name="sessionFactory" ref="mySessionFactory"/>  
  6.    </bean>  
  7.   
  8.    <bean id="myProductService" class="product.ProductServiceImpl">  
  9.      <property name="transactionManager" ref="myTxManager"/>  
  10.      <property name="productDao" ref="myProductDao"/>  
  11.    </bean>  
  12.   
  13. </beans>  

 

java 代码
  1. public class ProductServiceImpl implements ProductService {   
  2.   
  3.      private PlatformTransactionManager transactionManager;   
  4.      private ProductDao productDao;   
  5.   
  6.      public void setTransactionManager(PlatformTransactionManager transactionManager) {   
  7.          this.transactionManager = transactionManager;   
  8.      }   
  9.   
  10.      public void setProductDao(ProductDao productDao) {   
  11.          this.productDao = productDao;   
  12.      }   
  13.   
  14.      public void increasePriceOfAllProductsInCategory(final String category) {   
  15.          TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);   
  16.          transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);   
  17.          transactionTemplate.execute(   
  18.              new TransactionCallbackWithoutResult() {   
  19.                  public void doInTransactionWithoutResult(TransactionStatus status) {   
  20.                      List productsToChange = productDAO.loadProductsByCategory(category);   
  21.                      ...   
  22.                  }   
  23.              }   
  24.          );   
  25.      }   
  26. }   
分享到:
评论

相关推荐

    spring-framework-reference4.1.4

    Not Using Commons Logging ................................................................... 12 Using SLF4J ..............................................................................................

    spring-framework-reference-4.1.2

    Not Using Commons Logging ................................................................... 12 Using SLF4J ..............................................................................................

    WEB开发相关的Transaction管理战略

    2. **编程式事务(Programmatic Transaction)模型**: - 特点:允许开发者显式地控制事务的开始、提交和回滚。 - 实现:通过编程接口(如JTA API)实现事务管理。 - 应用场景:复杂的业务逻辑或需要跨多个资源管理...

    前端开源库-npm-programmatic

    "前端开源库-npm-programmatic"这个主题主要聚焦于如何以编程方式使用NPM命令,即通过编写脚本或者集成到自动化流程中来执行NPM操作,而非通过命令行界面手动输入命令。这种编程方式在构建自动化、持续集成和部署...

    QTP Using Programmatic Descriptions

    然而,在某些情况下,比如对象没有唯一名称或者对象数量动态变化时,就需要采用更加灵活的方式——编程性描述(Programmatic Descriptions)。 #### 二、编程性描述的基本概念 编程性描述是一种基于对象属性及其值来...

    Spring事务配置的五种方式

    1. **编程式事务管理(Programmatic Transaction Management)** 编程式事务管理是指在代码中显式地调用事务管理API进行事务的开始、提交、回滚等操作。使用`PlatformTransactionManager`接口的`getTransaction()`,...

    Spring事务配置的五种方式[参照].pdf

    3. **基于XML的编程式事务管理(Programmatic Transaction Management in XML)** 尽管声明式事务管理更常见,但Spring也支持编程式事务管理。这种方式需要在代码中显式地开始、提交、回滚事务。例如,通过使用`...

    实例详解Spring JDBC事务管理.doc

    Spring框架提供了两种事务管理方式:编程式的事务管理(Programmatic transaction management)和声明式的事务管理(Declarative transaction management)。在本文中,我们将以JDBC事务管理为例,详细介绍Spring的...

    jam3-lesson-programmatic-animation:这是关于程序化动画的课程。 它涵盖了使用代码为网络制作动画的不同方法

    程序化动画目录下载课程文件打开终端并输入npm i jam3/jam3-lesson-programmatic-animation -g 。 这将安装课程模块并使其全球可用。 创建一个名为“jam3-lesson-programmatic-animation”的文件夹。 cd 到此目录并...

    helloworld-programmatic-2.0-m11.zip

    【标题】"helloworld-programmatic-2.0-m11.zip" 暗示这是一个开源项目,名为 "HelloWorld" 的编程示例,版本为2.0的第11个里程碑(M11)。通常,这样的项目会包含一个简单的应用程序,用于演示如何使用特定的技术或...

    spring 事务配置方式

    1. **编程式事务管理(Programmatic Transaction Management)** 编程式事务管理允许你在代码中直接控制事务的开始、提交、回滚等操作。使用`PlatformTransactionManager`接口来管理事务,如`...

    AWS Programmatic Access from SAML-crx插件

    使用SSO(SAML 2.0)登录到AWS控制台后,使用编程访问凭证打开一个新选项卡。 使用SSO(SAML 2.0)登录到AWS控制台后,使用编程访问凭证打开一个新选项卡。 基于GTC Laan(prolane... 支持语言:English (United States)

    spring的5中事物配置 介绍spring的5中事物配置

    5. **编程式事务管理(Programmatic Transaction Management)** - 编程式事务管理允许在代码中直接控制事务的开始、提交、回滚等操作,使用`PlatformTransactionManager`接口和`TransactionDefinition`、`...

    Spring事务配置的五种方式.rar

    1. **编程式事务管理(Programmatic Transaction Management)** 编程式事务管理是通过调用`PlatformTransactionManager`接口的方法来显式控制事务的开始、提交、回滚。例如,使用`TransactionTemplate`或直接操作`...

Global site tag (gtag.js) - Google Analytics