แสดงบทความที่มีป้ายกำกับ transaction แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ transaction แสดงบทความทั้งหมด

วันอังคารที่ 28 กรกฎาคม พ.ศ. 2552

Transaction annotation-driven แล้ว Spring สร้างอะไรให้บ้าง

การใช้งาน @Transactional จะต้องกำหนดใน Spring Context ดังนี้

<tx:annotation-driven transaction-manager="transactionManager" />

มาดูกันว่า มันสร้างอะไรให้บ้าง

<aop:aspectj-autoproxy />
<bean id="transactionAttributeSource" class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributeSource" ref="transactionAttributeSource" />
</bean>
<bean id="org.springframework.transaction.config.internalTransactionAdvisor" class="org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor">
<property name="transactionAttributeSource" ref="transactionAttributeSource" />
<property name="adviceBeanName" value="transactionInterceptor" />
</bean>

บรรทัดแรกสั่งให้ Spring ทำ auto proxy จาก Advisor ที่มีการคอนฟิกใน Spring Context
ที่ เหลือเป็นการคอนฟิก Advisor, Interceptor(เป็น Advice) และ TransactionAttributeSource ที่ทำหน้าที่ บอกว่า method ของ class ที่ถูกเรียกนี้มี TransactionAttribute ยังไง
ตัวที่บอกรายละเอียด Transaction พวก propagation, isolation, timeout ฯลฯ อยู่ที่ TransactionAttribute นี่แหละ

อันนี้เฉพาะโหมด proxy ของ annotation-driven ยังไม่ไล่โหมด aspectj แต่มันก็คือๆกันแหละแค่เปลี่ยนการทำ proxy จากใช้ Proxy ของ JDK เป็น cglib แทน

วันศุกร์ที่ 20 มีนาคม พ.ศ. 2552

The ways to deal with non-transactional resources

There are serveral ways to deal with them.
1. Interaction without regard to transactionality. This approach is appropriate when there is no need for transaction management.
2. Development of transactional interfaces. This approach is the most comprehensive, but also the most time consuming because it needs to implement JTA interfaces (implementation of javax.transaction.xa.XAResource).
3. Implement the interactions in a “pseudo-transaction” that explicitly checks for and manages error conditions and rollback. I thought this approach like transaction in the web service which have to implement method for rollback by yourself.
In the detail, you can read at TheServerSide.