English 中文(简体)
A. 与Atomikos的两阶段承诺组合
原标题:Two-phase commit (2PC) configuration with Atomikos

我正在制作试验两阶段承诺的样本申请(2PC)。 我从互联网上抽取了这里所用的密码。 我将春天、温特和阿特米科斯与我的我的SQL一道作为后台。 我正在使用两个数据库,并蓄意向第二个数据库发出呼吁,但未能核实第一个数据库的电话是否被退回。 可悲的是,这似乎并不奏效。 请允许我谈谈与一些抽样守则的一些联系?

Following is my configuration:
The Hibernate session factories:

<bean id="sessionFactory1" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource1"/>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.connection.isolation">3</prop>    
            <prop key="hibernate.current_session_context_class">jta</prop>    
            <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>    
            <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop> 
            <prop key="hibernate.connection.release_mode">on_close</prop>
        </props>
    </property>

    <property name="mappingResources">
        <list>
            <value>/hibernate/Stock.hbm.xml</value>
        </list>
    </property>
</bean>

<bean id="sessionFactory2" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource2"/>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.connection.isolation">3</prop>    
            <prop key="hibernate.current_session_context_class">jta</prop>    
            <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>    
            <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop> 
            <prop key="hibernate.connection.release_mode">on_close</prop>
        </props>
    </property>

    <property name="mappingResources">
        <list>
            <value>/hibernate/Stock1.hbm.xml</value>
        </list>
    </property>
</bean>

数据组合:

<bean id="dataSource1" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">        
    <!-- set an arbitrary but unique name for the datasource -->       
    <property name="uniqueResourceName"><value>XADBMS1</value></property>        
    <!-- set the underlying driver class to use, in this example case we use MySql  -->       
    <property name="xaDataSourceClassName">          
        <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>       
    </property>       
    <property name="xaProperties">           
    <!--   set the driver-specific XADataSource properties  (check your driver docs for more info)           -->                 
        <props>                         
            <prop key="user">${jdbc.username}</prop>                         
            <prop key="password">${jdbc.password}</prop>                         
            <prop key="URL" >${jdbc.url1}</prop>                 
        </props>      
    </property>           
    <!-- how many connections in the pool? -->       
    <property name="poolSize" value="3"/>    
</bean>

<bean id="dataSource2" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">        
    <!-- set an arbitrary but unique name for the datasource -->       
    <property name="uniqueResourceName"><value>XADBMS2</value></property>        
    <!-- set the underlying driver class to use, in this example case we use MySql  -->       
    <property name="xaDataSourceClassName">          
        <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>       
    </property>       
    <property name="xaProperties">           
    <!--   set the driver-specific XADataSource properties  (check your driver docs for more info)           -->                 
        <props>                         
            <prop key="user">${jdbc.username}</prop>                         
            <prop key="password">${jdbc.password}</prop>                         
            <prop key="URL" >${jdbc.url2}</prop>                 
        </props>      
    </property>           
    <!-- how many connections in the pool? -->       
    <property name="poolSize" value="3"/>    
</bean>

春季联合安排组合:

 <bean id="AtomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">     
<!-- when close is called, should we force transactions to terminate or not?     -->   
   <property name="forceShutdown" value="false" /> 
</bean>  
<!--Also use Atomikos UserTransactionImp, needed to configure Spring   --> 
<bean id="AtomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">     
    <property name="transactionTimeout" value="300" /> 
</bean>

<!--Configure the Spring framework to use JTA transactions from Atomikos  --> 
<bean id="JtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">    
    <property name="transactionManager" ref="AtomikosTransactionManager" />    
    <property name="userTransaction" ref="AtomikosUserTransaction" /> 
</bean>  

我有两台DAOImpl,我向上面定义的两届论坛投稿。 以下是 Java法典的呼吁:

public static void main( String[] args )
{
    ApplicationContext appContext = 
            new ClassPathXmlApplicationContext("spring/config/appContext.xml");

    StockBo stockBo = (StockBo)appContext.getBean("stockBo1");
    StockBo stockBo2 = (StockBo)appContext.getBean("stockBo2");

    /** insert **/
    Stock stock = new Stock();
    stock.setStockCode("7668");
    stock.setStockName("HAIO");
    stockBo.save(stock);

    Stock stock1 = new Stock();
    //stock1.setStockCode("1668"); **Commented to fail the second db insert**
    stock1.setStockName("AAIO");
    stockBo2.save(stock1);
}

任何要点都会得到极大帮助。

成就

最佳回答

• 了解你要求你在同一个交易中履行旅游局的要求,例如:

final StockBo stockBo = (StockBo)appContext.getBean("stockBo1");
final StockBo stockBo2 = (StockBo)appContext.getBean("stockBo2");
TransactionTemplate tx = new TransactionTemplate(appContext.getBean(PlatformTransactionManager.class);

tx.execute(new TransactionCallback<Void>() {
    public Void doInTransaction(TransactionStatus ts) {
        /** insert **/
        Stock stock = new Stock();
        stock.setStockCode("7668");
        stock.setStockName("HAIO");
        stockBo.save(stock);

        Stock stock1 = new Stock();
        //stock1.setStockCode("1668"); **Commented to fail the second db insert**
        stock1.setStockName("AAIO");
        stockBo2.save(stock1);

       return null;
    }
});

此外,我认为,由于你召集了春季会议,你不需要以下内容:

<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop> 
<prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>
<prop key="hibernate.connection.release_mode">on_close</prop>  

www.un.org/spanish/ecosoc 另见。

问题回答

暂无回答




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签