Results 1 to 3 of 3

Thread: Spring how to support multy datasoure(not use jta)

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    1

    Default 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 :qilong2000@hotmail.com. if you think the mail is better communication fashion, you can send mail to me

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    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.)
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Announcement: Spring IDE WebFlow Support Preview Release 2
    By Christian Dupuis in forum Announcements
    Replies: 2
    Last Post: Sep 15th, 2006, 11:50 AM
  3. New Spring Support Forums are Live
    By Colin Sampaleanu in forum Announcements
    Replies: 17
    Last Post: May 22nd, 2005, 12:57 AM
  4. Announcement: Spring IDE WebFlow Support Preview Release 1
    By Christian Dupuis in forum Announcements
    Replies: 0
    Last Post: May 20th, 2005, 08:15 PM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •