atomikos jndi spring

spring :
1. 先配置JTA事务:
Java代码
<!-- 配置了JTA事务管理器 -->

<bean id="transactionManager"  
      class="org.springframework.transaction.jta.JtaTransactionManager">   
    <property name="transactionManager">   
        <ref bean="atomikosTransactionManager" />   
    </property>   
    <property name="userTransaction">   
        <ref bean="atomikosUserTransaction" />   
    </property>   
</bean>   
<bean id="atomikosTransactionManager"  
      class="com.atomikos.icatch.jta.UserTransactionManager"  
    init-method="init" destroy-method="close">   
    <property name="forceShutdown">   
        <value>true</value>   
    </property>   
</bean>   
<bean id="atomikosUserTransaction"  
    class="com.atomikos.icatch.jta.UserTransactionImp">   
    <property name="transactionTimeout" value="0" />   
</bean>  



<!-- 配置了JTA事务管理器 -->

<bean id="transactionManager"
      class="org.springframework.transaction.jta.JtaTransactionManager">
	<property name="transactionManager">
		<ref bean="atomikosTransactionManager" />
	</property>
	<property name="userTransaction">
		<ref bean="atomikosUserTransaction" />
	</property>
</bean>
<bean id="atomikosTransactionManager"
      class="com.atomikos.icatch.jta.UserTransactionManager"
	init-method="init" destroy-method="close">
	<property name="forceShutdown">
		<value>true</value>
	</property>
</bean>
<bean id="atomikosUserTransaction"
	class="com.atomikos.icatch.jta.UserTransactionImp">
	<property name="transactionTimeout" value="0" />
</bean>



2. 通过JNDI获取数据源:
Java代码

<bean id="sqlServerDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">   
        <property name="jndiName" value="${jdbc.sqlserver.datasource}" />   
</bean>   
<bean id="oracleDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">   
        <property name="jndiName" value="${jdbc.oracle.datasource}" />   
</bean>  



3. 创建 TransactionProxyFactoryBean:
Java代码

<bean id="transactionProxy"  
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"    
         abstract="true">   
        <property name="transactionManager" ref="transactionManager" />   
        <property name="transactionAttributes">   
            <props>   
                <prop key="*">PROPAGATION_REQUIRED,ISOLATION_DEFAULT,timeout_3000</prop>   
                <prop key="insert*">PROPAGATION_REQUIRED</prop>   
                <prop key="save*">PROPAGATION_REQUIRED</prop>   
                <prop key="update*">PROPAGATION_REQUIRED</prop>   
                <prop key="create*">PROPAGATION_REQUIRED</prop>   
                <prop key="remove*">PROPAGATION_REQUIRED</prop>   
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>   
                <prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>   
                <prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>   
                <prop key="execute*">PROPAGATION_REQUIRED</prop>   
                <prop key="unique*">PROPAGATION_REQUIRED,readOnly</prop>   
            </props>   
        </property>   
</bean>  

<bean id="transactionProxy"
		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" 
         abstract="true">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<props>
				<prop key="*">PROPAGATION_REQUIRED,ISOLATION_DEFAULT,timeout_3000</prop>
				<prop key="insert*">PROPAGATION_REQUIRED</prop>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="update*">PROPAGATION_REQUIRED</prop>
				<prop key="create*">PROPAGATION_REQUIRED</prop>
				<prop key="remove*">PROPAGATION_REQUIRED</prop>
				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="execute*">PROPAGATION_REQUIRED</prop>
				<prop key="unique*">PROPAGATION_REQUIRED,readOnly</prop>
			</props>
		</property>
</bean>



JBOSS:
配置连接池mssql-xa-ds.xml:
Java代码

<datasources>   
 <xa-datasource>   
  <jndi-name>interfaceSqlServer</jndi-name>   
    <track-connection-by-tx/>   
    <!--<track-connection-by-tx>true</track-connection-by-tx>-->   
  <!--<isSameRM-override-value>false</isSameRM-override-value>-->   
    <!--<new-connection-sql>set autocommit=1</new-connection-sql>-->   
    <!--<no-tx-separate-pools>true</no-tx-separate-pools>-->   
    <xa-datasource-class>net.sourceforge.jtds.jdbcx.JtdsDataSource</xa-datasource-class>   
  <xa-datasource-property name="ServerName">192.168.**.**</xa-datasource-property>   
  <xa-datasource-property name="DatabaseName">wsinterface</xa-datasource-property>   
    <use-java-context>false</use-java-context>   
    <!--<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>-->   
  <user-name>**</user-name>   
  <password>**</password>   
  <metadata>   
    <type-mapping>MSSQLSERVER2000</type-mapping>   
  </metadata>   
    <min-pool-size>1</min-pool-size>   
    <max-pool-size>50</max-pool-size>   
    <blocking-timeout-millis>5000</blocking-timeout-millis>   
    <idle-timeout-minutes>15</idle-timeout-minutes>   
 </xa-datasource>   
</datasources>  

<datasources>
 <xa-datasource>
  <jndi-name>interfaceSqlServer</jndi-name>
	<track-connection-by-tx/>
	<!--<track-connection-by-tx>true</track-connection-by-tx>-->
  <!--<isSameRM-override-value>false</isSameRM-override-value>-->
	<!--<new-connection-sql>set autocommit=1</new-connection-sql>-->
	<!--<no-tx-separate-pools>true</no-tx-separate-pools>-->
 	<xa-datasource-class>net.sourceforge.jtds.jdbcx.JtdsDataSource</xa-datasource-class>
  <xa-datasource-property name="ServerName">192.168.**.**</xa-datasource-property>
  <xa-datasource-property name="DatabaseName">wsinterface</xa-datasource-property>
	<use-java-context>false</use-java-context>
	<!--<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>-->
  <user-name>**</user-name>
  <password>**</password>
  <metadata>
    <type-mapping>MSSQLSERVER2000</type-mapping>
  </metadata>
	<min-pool-size>1</min-pool-size>
	<max-pool-size>50</max-pool-size>
	<blocking-timeout-millis>5000</blocking-timeout-millis>
	<idle-timeout-minutes>15</idle-timeout-minutes>
 </xa-datasource>
</datasources>



oracle-xa-ds.xml:
Java代码

<datasources>   
  <xa-datasource>   
    <jndi-name>interfaceOracle</jndi-name>   
    <track-connection-by-tx/>   
    <!--<track-connection-by-tx>true</track-connection-by-tx>   
  <isSameRM-override-value>false</isSameRM-override-value>   
    <new-connection-sql>set autocommit=1</new-connection-sql>   
    <no-tx-separate-pools>true</no-tx-separate-pools>-->   
    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>   
    <xa-datasource-property name="URL">jdbc:oracle:thin:@192.168.**.**:1521:****</xa-datasource-property>   
    <xa-datasource-property name="User">***</xa-datasource-property>   
    <xa-datasource-property name="Password">***</xa-datasource-property>   
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>   
    <use-java-context>false</use-java-context>   
    <metadata>   
        <type-mapping>Oracle9i</type-mapping>   
    </metadata>   
    <!--<mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"  
        name="jboss.jca:service=OracleXAExceptionFormatter">   
        <depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>   
    </mbean>-->   
    <min-pool-size>1</min-pool-size>   
    <max-pool-size>50</max-pool-size>   
    <blocking-timeout-millis>5000</blocking-timeout-millis>   
    <idle-timeout-minutes>15</idle-timeout-minutes>   
  </xa-datasource>   


</datasources>

 

你可能感兴趣的:(spring,oracle,sql,bean,jboss)