Results 1 to 5 of 5

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

  1. #1
    Join Date
    Dec 2011
    Posts
    9

    Default 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. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Dec 2011
    Posts
    9

    Default

    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).

  4. #4
    Join Date
    Dec 2011
    Posts
    9

    Default

    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

  5. #5
    Join Date
    Jan 2008
    Location
    Merion, Pa
    Posts
    65

    Default

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

Posting Permissions

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