全局事务jta小探(二)

 

对应设置的xml

<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="oracle.jdbc.pool.OracleDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="true" is-isolation-level-guaranteed="false" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="itown" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">

      <property name="DataSourceName" value="OracleDataSource"/>

      <property name="ImplicitCachingEnabled" value="false"/>

      <property name="NetworkProtocol" value="tcp"/>

      <property name="LoginTimeout" value="0"/>

      <property name="URL" value="dbc:oracle:thin:@localhost:1521:ityc"/>

      <property name="User" value="itown"/>

      <property name="ExplicitCachingEnabled" value="false"/>

      <property name="PortNumber" value="0"/>

      <property name="MaxStatements" value="0"/>

      <property name="Password" value="itown"/>

    </jdbc-connection-pool>

 

 

 

 

<jdbc-resource enabled="true" jndi-name="jdbc/wfmsDataSource" object-type="user" pool-name="itown"/>

 

 

spring的配置(常规的jdni的配置)

 

 

 

 

采用的是springdefault-autowire="byName"属性通过beanid值进行自动匹配

 

<bean id="dataSource"  class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>  java:comp/env/jdbc/feng  </value>
        </property>
</bean>

 

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"/>

 

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingJarLocations">
            <list>
                <value>WEB-INF/lib/jarname _*.jar</value>
            </list>
        </property>
        <property name="mappingDirectoryLocations">
            <list>
                <value>WEB-INF/mappings</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9iDialect </prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                <prop key="hibernate.hibernate.cglib.use_reflection_optimizer">false</prop>
                <prop key="hibernate.hbm2ddl.auto"> update </prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.connection.release_mode">after_transaction</prop>
            </props>
        </property>
    </bean>

 

<bean id="baseJdbcDAO" class=" com.company.module.funciton.dao.jdbc.BaseJdbcDAO"/>

 

<bean id="BService" class="com.company.module.funciton.services.scheduler.SchedulerServiceImpl"/>

 

 

获取jdni和事务

Context initCtx = new InitialContext();

            ut = (UserTransaction) initCtx.lookup("java:comp/UserTransaction");

            Context envCtx = (Context) initCtx.lookup("java:comp/env");

            DataSource ds = (DataSource) envCtx.lookup("jdbc/wfmsDataSource");

            out.println("<<< before lookup(\"java:comp/UserTransaction\" >>>");

 

ut.begin()

ut.commit();

ut.rollback();

 

详细代码:见附录

你可能感兴趣的:(spring,oracle,Hibernate,bean,jdbc)