[2008-5-15] Spring+Struts+Hibernate(一)

环境:
系统->window2000
使用工具->Eclipse3.2(插件:MyEclipse5.0)
服务器->Tomcat5.0

主要jar文件:
Spring1.2
Hibernate3.1
JSTL.12
Struts1.2

基本架构:

com.action.UpdateAction->com.services.Services->com.dao.tabDAO

其中com.services.Services采用了事务机制

数据库(Oracle9i)文件:

create table TAB(

      TABIDvarchar2(32) primary key not null,

     TABNAME number(10)  not null

);



struts-config.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
  <data-sources />
  <form-beans />
  <global-exceptions />
  <global-forwards />
  <action-mappings>
   <action path="/update" scope="request"
    type="org.springframework.web.struts.DelegatingActionProxy">
    <forward name="update" path="/update.jsp"></forward>
   </action>
  </action-mappings>
  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
 
  <plug-in
  className="org.springframework.web.struts.ContextLoaderPlugIn">
  <set-property property="contextConfigLocation"
   value="/WEB-INF/classes/applicationContext.xml" />
  </plug-in>
 
</struts-config>

Spring的applicationContext.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>


  <bean id="dataSource"
  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName">
   <value>oracle.jdbc.driver.OracleDriver</value>
  </property>
  <property name="url">
   <value>jdbc:oracle:thin:@localhost:1521:chenlong</value>
  </property>
  <property name="username">
   <value>scott</value>
  </property>
  <property name="password">
   <value>tiger</value>
  </property>
</bean>


<bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
  destroy-method="close">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
  <property name="mappingResources">
   <list>
    <value>com/pojo/Tab.hbm.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.Oracle9Dialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="connection.provider_class">
       org.hibernate.connection.ProxoolConnectionProvider
    </prop> 
   </props>
  </property>
</bean>

<bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
</bean>

<bean id="tabDAO" class="com.dao.tabDAO">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
</bean>

<bean id="services" class="com.services.Services">
  <property name="tabDAO">
   <ref bean="tabDAO" />
  </property>
</bean>

<bean id="servicesTransactionProxy"
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager">
   <ref bean="transactionManager" />
  </property>
  <property name="proxyInterfaces">
   <list>
    <value>com.services.IServices</value>
   </list>
  </property>
  <property name="target">
   <ref bean="services" />
  </property>
  <property name="transactionAttributes">
   <props>
    <prop key="update*">
     PROPAGATION_REQUIRED,-Exception
    </prop>
   </props>
  </property>
</bean>

<bean name="/update" singleton="false"
  class="com.action.UpdateAction">
  <property name="servicesTransactionProxy">
   <ref bean="servicesTransactionProxy" />
  </property>
</bean>

</beans>



类文件:

services类:


public void update() throws Exception {

  try {

   System.out.println("services.update===============================开始");

   this.tabDAO.update();

   System.out.println("services.update===============================结束");
   throw new Exception("AAA");
  
  } catch (Exception ex) {
   throw ex;
  }

}

tabDAO类:


public void update(){

  StringBuffer sql = new StringBuffer();
  sql.append("UPDATE Tab ");
  sql.append("SET tabname = tabname + 1 ");
  sql.append("WHERE tabid = '1' ");

  this.getHibernateTemplate().bulkUpdate(sql.toString());
}


测试:

使用jmetero2.3.1

线程数:50

Ramp-UP(in seconds):0

循环次数:10

可以成功更新到500


你可能感兴趣的:(spring,oracle,sql,Hibernate,struts)