Announcement Announcement Module
Collapse
No announcement yet.
Legacy code calling Spring: Ability to pass java.sql.Connection to Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Legacy code calling Spring: Ability to pass java.sql.Connection to Spring

    Hi there,
    We have legacy code and transaction mgmt which is centered around getting a java.sql.Connection and passing it around using the autoCommit flag to false to maintain a transaction boundary.
    Our newer code uses Spring and declarative txn mgmt.
    How can we take a java.sql.Connection obtained in the older code and pass this to Spring to use as the Connection behind the scenes to maintain transaction visibility for uncommited work?

    Thanks in advance
    Pat

  • #2
    Hello

    We have legacy code and transaction mgmt which is centered around getting a java.sql.Connection and passing it around using the autoCommit flag to false to maintain a transaction boundary.
    I am assuming the follow. Are You working with JDBC?. How work your transactions? BMP, CMP?

    Our newer code uses Spring and declarative txn mgmt.
    OK

    Could you use @Transactions and JdbcTemplate instead?. Do a migration.

    Comment


    • #3
      We are working with JDBC.
      This application manages its own transactions by simply wrapping the java.sql.Connection and sets autoCommit to false.
      This wrapper is passed around via method calls.
      The originator of the transaction determines to commit or rollback the transaction.
      We do not use BMP.
      We essentially do not use CMP either.

      We are using JDBCTemplate in our new DAO layer. We are currently not using annotations as we do not want to couple our code to Spring directly (as much as possible).

      Comment


      • #4
        Although this has gone on the back burner a little, we will still need this capability.

        My thoughts right now are to subclass
        DataSourceTransactionManager
        .
        In
        doGetTransaction()
        we will determine if an existing java.sql.Connection has been provided (from the old application framework). If this is the case then we setup a
        ConnectionHolder
        using this connection and return it in the transaction object.
        We will override the
        doBegin(..)
        ,
        doCommit(..)
        and
        doRollback(..)
        to handle this situation.

        If the connection is not provided then just delegate to
        DataSourceTransactionManager

        Comment


        • #5
          Have you considered changing your legacy transaction management to use the Spring transaction template?

          Comment

          Working...
          X