当前位置:首页 > 开发 > 系统架构 > 架构 > 正文

zeus持久层spring事务单元测试

发表于: 2015-05-11   作者:deng520159   来源:转载   浏览:
摘要: 今天把zeus事务单元测试放出来,让大家指出他的毛病, 1.ZeusTransactionTest.java 单元测试   package com.dengliang.zeus.webdemo.test; import java.util.ArrayList; import java.util.List; import org.junit.Test; import

今天把zeus事务单元测试放出来,让大家指出他的毛病,

1.ZeusTransactionTest.java 单元测试

 

package com.dengliang.zeus.webdemo.test;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.dengliang.zeus.webdemo.services.IDajc01Service;
import com.dengliang.zeus.webdemo.util.UIDGenerator;
import com.dengliang.zeus.webdemo.vo.Dajc01VO;


//
/**
 * zeus 持久层事务测试 由于打包时要调用 test方法 ,如果测试手工添加@Test
 * @author 100755_邓亮 2015年4月28日
 *
 */
public class ZeusTransactionTest {
	private static ApplicationContext context;
	/**
	 * 获取bean
	 * 
	 * @param id
	 * @return
	 */
	public static Object getBean(String id) {
		if (context == null) {
			synchronized (id) {
				context = new ClassPathXmlApplicationContext(
						"applicationContext-simpledb.xml",
						"applicationContext-dao.xml",
						"applicationContext-service.xml",
						"applicationContext-transaction.xml");
			}
		}
		return context.getBean(id);
	}
	@Test
	public void addTransactionTest() {
		// 新增测试
		IDajc01Service service = (IDajc01Service) ZeusTransactionTest.getBean("dajc01Service");
		try {
			List<Dajc01VO> list=new ArrayList();
			for (int i = 0; i < 10; i++) {
				Dajc01VO da001 = new Dajc01VO();
				da001.setUuid(UIDGenerator.getUUID());
				da001.setSysId(i+"");
				list.add(da001);
			}
			service.addList(list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}	
}

 2.相关几个配置文件

 

applicationContext-simpledb.xml

 

<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd 
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx.xsd ">

	<context:property-placeholder location="classpath:*.properties" />
	<bean id="parentDataSource" class="com.alibaba.druid.pool.DruidDataSource"
		destroy-method="close">
		<!-- 配置初始化大小、最小、最大 -->
		<property name="initialSize" value="20" />
		<property name="minIdle" value="20" />
		<property name="maxIdle" value="30" />
		<property name="maxActive" value="50" />
		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="0" />
		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="60000" />
		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="300000" />
		<property name="validationQuery" value="SELECT 'x'" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		<property name="removeAbandoned" value="false" />
		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
		<property name="poolPreparedStatements" value="true" />
		<property name="maxPoolPreparedStatementPerConnectionSize"
			value="20" />
			<property name="filters" value ="stat,wall"></property>
	 </bean>
     
     <bean id="jlerp_db" parent="parentDataSource" destroy-method="close">
		<property name="url" value="jdbc:oracle:thin:@10.68.2.23:1521/erpdb" />
		<property name="username" value="jlerp_db" />
		<property name="password" value="jlerp_db" />
	</bean>	
	
	<!--daoSupport-->
	<bean id="zeusdaoSupport" class="com.dengliang.zeus.framework.dao.ZeusDaoSupport">
		<property name="dataSource" ref="jlerp_db"/>
	</bean>

</beans>

 applicationContext-dao.xml

 

 

<?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:p="http://www.springframework.org/schema/p" 
		xmlns:aop="http://www.springframework.org/schema/aop" 
		xmlns:tx="http://www.springframework.org/schema/tx"
		xmlns:context="http://www.springframework.org/schema/context"  
		xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.2.xsd 
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
	<!-- DAO -->
	<bean id="dajc01DAO" class="com.dengliang.zeus.webdemo.dao.Dajc01DAO" parent="zeusdaoSupport"/>
</beans>

 applicationContext-service.xml

 

<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.2.xsd 
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

	<!-- BIZ -->
	<bean id="dajc01Service" class="com.dengliang.zeus.webdemo.services.impl.Dajc01Service">
		<property name="dajc01DAO" ref="dajc01DAO" />
	</bean>
	
</beans>

 applicationContext-transaction.xml

<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd 
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx.xsd ">

	  <bean id = "transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    	<property name="dataSource" ref="jlerp_db" />
      </bean>
      <!-- 声明式事务配置 -->
	  <tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
				<tx:method name="do*" propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
			<tx:method name="del*" propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
			<tx:method name="save*" propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
			<tx:method name="add*" propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
			<tx:method name="begin*" propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
			<tx:method name="end*" propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
			<tx:method name="update*" propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
			<tx:method name="modify*" propagation="REQUIRED" rollback-for="Throwable, Exception, RuntimeException"/>
			<tx:method name="query*" propagation="NOT_SUPPORTED"/>
			<tx:method name="load*" propagation="NOT_SUPPORTED"/>
			<tx:method name="find*" propagation="NOT_SUPPORTED"/>
			<tx:method name="*" read-only="true" propagation="SUPPORTS" />
	</tx:attributes>
	</tx:advice>
	<!-- service切面 -->
	<aop:config>
		<aop:pointcut expression="execution(* com.dengliang.zeus.webdemo.services.*.*(..))" id="pointCut" />
		<aop:advisor  pointcut-ref="pointCut" advice-ref="txAdvice"/>
	</aop:config>
   

	


	
</beans>

 

zeus持久层spring事务单元测试

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
,由于工作原因,把工作相关技术整合成一个持久层框架:zeus,它是一个基于spring jdbctemplate的,maven
原文出自:http://www.cnblogs.com/liunanjava/p/4412408.html 一、Spring对DAO的支持 DAO:Data Acc
一、Spring对DAO的支持 DAO:Data Access Object Spring提供了DAO框架,让开发人员无须耦合特定的数
当您自以为已经了解了所有开发工具时,肯定又会冒出一个新的工具。在本文中,developerWorks 的固定
使用SQL2005的数据库。 1 Spring Bean定义文件test-cintext.xml <?xml version="1.0" encoding="
第一次写博客,记录下今天学习Spring Test时遇到的问题。 一、问题描述 参照开涛博客在自己的项目上
今天,我们玩玩数据库,搞搞持久层。不搞太复杂的东西,Spring注解对于持久层的改造并不难懂! 我们
前言 我们时常会遇到一些 web 项目,需要从不同的数据源中抓取数据来进行分析,而这些数据源是有可
今天,我们玩玩数据库,搞搞持久层。不搞太复杂的东西,Spring注解对于持久层的改造并不难懂! 我们
今天,我们玩玩数据库,搞搞持久层。不搞太复杂的东西,Spring注解对于持久层的改造并不难懂! 我们
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号