JTA技术实现
来源:互联网 发布:侠客风云传读条优化 编辑:程序博客网 时间:2024/05/16 14:00
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="net.sourceforge.jtds.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/test">
</property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
<property name="maxActive">
<value>200</value>
</property>
<property name="maxIdle">
<value>70</value>
</property>
<property name="minIdle">
<value>60</value>
</property>
<property name="maxWait">
<value>2000</value>
</property>
<property name="initialSize">
<value>60</value>
</property>
<property name="removeAbandoned">
<value>true</value>
</property>
<property name="removeAbandonedTimeout">
<value>60</value>
</property>
<property name="logAbandoned">
<value>true</value>
</property>
</bean>
<bean id="newsDataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="net.sourceforge.jtds.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/test2">
</property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
<property name="maxActive">
<value>200</value>
</property>
<property name="maxIdle">
<value>70</value>
</property>
<property name="minIdle">
<value>60</value>
</property>
<property name="maxWait">
<value>2000</value>
</property>
<property name="initialSize">
<value>60</value>
</property>
<property name="removeAbandoned">
<value>true</value>
</property>
<property name="removeAbandonedTimeout">
<value>60</value>
</property>
<property name="logAbandoned">
<value>true</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>demo/jpa/pojo/Student.hbm.xml</value>
</list>
</property>
</bean>
<bean id="newsSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="newsDataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>demo/jpa/pojo/Teacher.hbm.xml</value>
</list>
</property>
</bean>
<bean id="jotm"
class="org.springframework.transaction.jta.JotmFactoryBean" />
<bean id="myTxManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="jotm" />
</bean>
<!-- 配置事务特性-->
<tx:advice id="txAdvice" transaction-manager="myTxManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置那些类的方法进行事务管理-->
<aop:config>
<aop:pointcut id="allManagerMethod"
expression="execution (* demo.jpa.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="allManagerMethod" />
</aop:config>
<bean id="studentDAO" class="demo.jpa.dao.impl.StudentDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="teacherDAO" class="demo.jpa.dao.impl.TeacherDAOImpl">
<property name="sessionFactory">
<ref local="newsSessionFactory" />
</property>
</bean>
<bean id="studentService" class="demo.jpa.service.impl.StudentServiceImpl">
<property name="studentDAO">
<ref local="studentDAO"/>
</property>
<property name="teacherDAO">
<ref local="teacherDAO"/>
</property>
</bean>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="net.sourceforge.jtds.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/test">
</property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
<property name="maxActive">
<value>200</value>
</property>
<property name="maxIdle">
<value>70</value>
</property>
<property name="minIdle">
<value>60</value>
</property>
<property name="maxWait">
<value>2000</value>
</property>
<property name="initialSize">
<value>60</value>
</property>
<property name="removeAbandoned">
<value>true</value>
</property>
<property name="removeAbandonedTimeout">
<value>60</value>
</property>
<property name="logAbandoned">
<value>true</value>
</property>
</bean>
<bean id="newsDataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="net.sourceforge.jtds.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/test2">
</property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
<property name="maxActive">
<value>200</value>
</property>
<property name="maxIdle">
<value>70</value>
</property>
<property name="minIdle">
<value>60</value>
</property>
<property name="maxWait">
<value>2000</value>
</property>
<property name="initialSize">
<value>60</value>
</property>
<property name="removeAbandoned">
<value>true</value>
</property>
<property name="removeAbandonedTimeout">
<value>60</value>
</property>
<property name="logAbandoned">
<value>true</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>demo/jpa/pojo/Student.hbm.xml</value>
</list>
</property>
</bean>
<bean id="newsSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="newsDataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>demo/jpa/pojo/Teacher.hbm.xml</value>
</list>
</property>
</bean>
<bean id="jotm"
class="org.springframework.transaction.jta.JotmFactoryBean" />
<bean id="myTxManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="jotm" />
</bean>
<!-- 配置事务特性-->
<tx:advice id="txAdvice" transaction-manager="myTxManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置那些类的方法进行事务管理-->
<aop:config>
<aop:pointcut id="allManagerMethod"
expression="execution (* demo.jpa.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="allManagerMethod" />
</aop:config>
<bean id="studentDAO" class="demo.jpa.dao.impl.StudentDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="teacherDAO" class="demo.jpa.dao.impl.TeacherDAOImpl">
<property name="sessionFactory">
<ref local="newsSessionFactory" />
</property>
</bean>
<bean id="studentService" class="demo.jpa.service.impl.StudentServiceImpl">
<property name="studentDAO">
<ref local="studentDAO"/>
</property>
<property name="teacherDAO">
<ref local="teacherDAO"/>
</property>
</bean>
</beans>
public class TestJPA
{
@Test
public void saveCustomerAndOrder()
{
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
IStudentService studentService=(IStudentService)ctx.getBean("studentService");
Student student = new Student();
student.setSname("张三");
Teacher teacher = new Teacher();
teacher.setTname("李四");
studentService.saveStudent(student, teacher);
}
}
- JTA技术实现
- JTA - 原理与实现
- JTA实现跨数据库操作
- Spring+JTA实现分布式事务
- Tomcat 结合Atomikos 实现JTA
- JTA
- JTA
- jta
- JTA
- JTA
- JTA
- jta
- JTA
- JTA
- JTA
- Spring+iBatis+Atomikos实现JTA事务
- Spring+iBatis+Atomikos实现JTA事务
- JTA 深度历险 - 原理与实现
- Java I/O 学习
- ExtJS4 GridPanel 单选支持反选功能实现
- VC及eVC中将一个对话框作为控件放入另一个对话框
- 改android程序的包名
- 选用合适的win7
- JTA技术实现
- 约束
- Coolite 服务器端弹出对话框
- linux查看cup使用情况 sar命令
- C#验证Email是否真正存在,不是验证邮件格式,是邮件地址是否存在 .
- XMPP客户端关于用户组和好友列表的管理的一个实现方法
- asp.net中上传图片并生成小图片,自动添加水印的代码 .
- 在web.xml定义,在网页中使用变量实例 使用只有创建变量的servlet才可以访问的<init-param>方式 附带登陆和跳转实现
- 磁带驱动器工作环境