81,122
社区成员




<?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:context="http://www.springframework.org/schema/context"
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.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd "
default-autowire="byName">
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<!--
<property name="url" value="jdbc:sqlserver://172.16.5.48:1433;DatabaseName=TAMS"/>
<property name="username" value="sa"/>
<property name="password" value="TEST"/>
-->
<property name="url" value="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=TAMS;"/>
<property name="username" value="ad"/>
<property name="password" value="ad"/>
<!-- 连接池启动时的初始值 -->
<property name="initialSize" value="1"/>
<!-- 连接池的最大值 -->
<property name="maxActive" value="500"/>
<!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
<property name="maxIdle" value="2"/>
<!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
<property name="minIdle" value="1"/>
<!-- <property name="defaultAutoCommit" value="false"/> -->
</bean>
<!-- 配置事务管理器-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置业务bean -->
<!-- 采用@Transactional注解方式来使用事务
<tx:annotation-driven transaction-manager="txManager"/> -->
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation"
value="classpath:sqlmap-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sqlMapClientTemplate"
class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean id="baseTxService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="txManager" />
<property name="proxyTargetClass" value="true" />
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="query*">readOnly</prop>
<prop key="get*">readOnly</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean id="textDao" class="com.strike.java.core.db.daoImpl.TextDaoImpl2">
<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"></property>
</bean>
</beans>
package com.strike.java.core.db.daoImpl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.strike.java.core.db.dao.TextDao;
import com.strike.java.core.db.daoBean.TextDaoBean;
public class TextDaoImpl2 implements TextDao {
private SqlMapClientTemplate sqlMapClientTemplate;
public SqlMapClientTemplate getSqlMapClientTemplate() {
return sqlMapClientTemplate;
}
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
this.sqlMapClientTemplate = sqlMapClientTemplate;
}
@Override
public int text() throws SQLException {
List<TextDaoBean> parm = new ArrayList();
for(int i = 0;i < 15000; i++){
TextDaoBean textDaoBean = new TextDaoBean();
textDaoBean.setUsername(String.valueOf(i));
textDaoBean.setPassword(String.valueOf(i));
parm.add(textDaoBean);
}
SqlMapClient st = sqlMapClientTemplate.getSqlMapClient();
st.startTransaction();
st.startBatch();
long batchStartTime = System.currentTimeMillis();
System.out.println(batchStartTime);
for(int j = 0;j < parm.size(); j++){
st.insert("BC_MST_PREF_SqlMap.insertUser", parm.get(j));
}
st.executeBatch();
st.commitTransaction();
long batchEndTime = System.currentTimeMillis();
System.out.println(batchEndTime-batchStartTime);
st.endTransaction();
// TODO Auto-generated method stub
return 0;
}
}