Announcement Announcement Module
Collapse
No announcement yet.
Spring how to support multy datasoure(not use jta) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring how to support multy datasoure(not use jta)

    i know jta can support multiple datasource. but the performance is bad, and also need datasource to support it.

    in my old project, we just use pure jdbc to handle multiple datasource(in fact , they are two oracle database)
    the old code style is

    Connection conn1=null;
    Connection conn2=null;
    try{
    conn1=DataSource1.getConn();
    conn2=DataSource2.getConn();
    ........
    conn1.commit();--------(1)
    conn2.commit();--------(2)

    }catch{
    conn1.rollback();
    conn2.rollback();
    }finally{
    cleanUp(conn1..);
    cleanUP(conn2...)
    }

    in this old code style, only fail happen between (1) and (2) will cause the data not consistent. but since the two data base all in our local area network. so it few happen. In fact. we think it is ok. no need JTA.


    but now if we use Spring jdbc declare transaction. we find the framework can not reach the goal as the old code style.
    In fact, the Spring Jdbc 's simulant code style is below



    Connection conn1=null;
    Connection conn2=null;
    try{
    conn1=DataSource1.getConn();
    ...... --------use conn1 do someting
    try{
    conn2=DataSource2.getConn();
    .....................use conn2 do someting
    conn2.commit();--------(1)
    }catch(e){
    conn2.rollback()
    }finally{
    clean up conn2
    }
    ........----------- still use conn1 do thing
    conn1.commit();--------(2)


    }catch{

    conn2.rollback();
    }finally{

    cleanUP(conn2...)
    }

    to compare the two code style, you will find the Spring jdbc framework will more easy cause the data not consistent. how to make Spring generate code like the first code style.
    we would not want to use jca,since the two database both in our company.
    we think the code style(1) is enough. but we want to use Spring jdbc framework.

    who can help me.
    my email is :[email protected] if you think the mail is better communication fashion, you can send mail to me

  • #2
    you will find the Spring jdbc framework will more easy cause the data not consistent
    You mean developer?

    in fact , they are two oracle database
    we would not want to use jca,since the two database both in our company.
    What about Oracle Database Links?

    Comment


    • #3
      You can easily use two JdbcTemplate instances each configured with a different DataSource. So Spring JDBC won't cause any problem with using multiple datasources.

      If you want robust distributed transactions, you need to take the performance hit of two phase commit. We recommend JTA (from an app server or a product such as JOTM) in this case, and Spring does not provide a distributed transaction coordinator itself.

      However, as Omar points out, if you're using 2 Oracle databases, you might be best to try to address your problem using database functionality rather than in Java. That should notably simplify your Java code, too. (You'll probably need just one datasource.)

      Comment

      Working...
      X