Beehive
  1. Beehive
  2. BEEHIVE-1019

Allow multiple JDBC Controls to share the same database connection

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: V.Next
    • Component/s: System Controls
    • Labels:
      None

      Description

      Allow multiple JDBC controls to share a single database connection. One benefit of this improvment would be that multiple jdbc controls could participate in a transaction.

      1. PATCH_FIXED.txt
        30 kB
        Drew Varner
      2. PATCH.txt
        29 kB
        Drew Varner

        Activity

        Hide
        Drew Varner added a comment -

        Patch Notes:

        This patch adds a setConnection(Connection conn) method to JDBC Controls.

        This method is useful for:

        1) Easy unit testing setup (no need to create JNDI context just to test)..
        2) Putting multiple JDBC Controls in a single database transaction
        3) Integrating JDBC Controls with third party Connection factories
        4) Sharing connections between JDBCControls, DAOs and plain JDBC calls

        This patch changes the way JDBC Controls behave:

        1) They no longer get a Connection at the onAcquire() lifecycle method
        2) Connections are obtained lazily at invoke()
        3) Connections are not closed if they were set by setConnection()
        4) Controls can function without declaring a connection source in annotations

        The following files are added/modified in this patch:

        M system-controls/test/ant/junitCore.xml
        A system-controls/test/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/setconnection
        A system-controls/test/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/setconnection/NoConnectionAnnotationCtrl.jcx
        A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection
        A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/DBSetConnectionTest.java
        A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/JdbcTypesTest.java
        A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/SetConnectionTest.java
        A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/TxResultsTest.java
        M system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/JdbcControl.java
        M system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/JdbcControlImpl.java

        What you might not like about this patch:

        1) I removed .jcx references in the JDBC Control Javadoc, I don't think they have to be called .jcx.
        2) The following test suites extend other test suites. I thought it was an easy way to test functionality. I just call setConnection() in the setUp() method

        system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/DBSetConnectionTest.java
        system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/JdbcTypesTest.java
        system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/TxResultsTest.java

        The following Ant target passed:

        ant clean deploy systemcontrols.drt

        On OS X, Java 1.5.0_06

        Show
        Drew Varner added a comment - Patch Notes: This patch adds a setConnection(Connection conn) method to JDBC Controls. This method is useful for: 1) Easy unit testing setup (no need to create JNDI context just to test).. 2) Putting multiple JDBC Controls in a single database transaction 3) Integrating JDBC Controls with third party Connection factories 4) Sharing connections between JDBCControls, DAOs and plain JDBC calls This patch changes the way JDBC Controls behave: 1) They no longer get a Connection at the onAcquire() lifecycle method 2) Connections are obtained lazily at invoke() 3) Connections are not closed if they were set by setConnection() 4) Controls can function without declaring a connection source in annotations The following files are added/modified in this patch: M system-controls/test/ant/junitCore.xml A system-controls/test/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/setconnection A system-controls/test/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/setconnection/NoConnectionAnnotationCtrl.jcx A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/DBSetConnectionTest.java A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/JdbcTypesTest.java A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/SetConnectionTest.java A system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/TxResultsTest.java M system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/JdbcControl.java M system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/JdbcControlImpl.java What you might not like about this patch: 1) I removed .jcx references in the JDBC Control Javadoc, I don't think they have to be called .jcx. 2) The following test suites extend other test suites. I thought it was an easy way to test functionality. I just call setConnection() in the setUp() method system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/DBSetConnectionTest.java system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/JdbcTypesTest.java system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/setconnection/TxResultsTest.java The following Ant target passed: ant clean deploy systemcontrols.drt On OS X, Java 1.5.0_06
        Hide
        Drew Varner added a comment -

        There is a problem with my patch. The setConnection() piece does not close out the existing connection if it is generated by the Control.

        Show
        Drew Varner added a comment - There is a problem with my patch. The setConnection() piece does not close out the existing connection if it is generated by the Control.
        Hide
        Drew Varner added a comment -

        This fixes an issue in my first patch. I forgot to close the existing connection when setConnection(Connection con) was called.

        Show
        Drew Varner added a comment - This fixes an issue in my first patch. I forgot to close the existing connection when setConnection(Connection con) was called.
        Hide
        Chad Schoettger added a comment -

        Taking a look at applying Drew's patch.

        Show
        Chad Schoettger added a comment - Taking a look at applying Drew's patch.
        Hide
        Chad Schoettger added a comment -

        Resolved, thanks for the patch Drew.

        Show
        Chad Schoettger added a comment - Resolved, thanks for the patch Drew.
        Hide
        matt c added a comment -

        Verified this functionality and the tests. May add additional tests for this going forward.

        Show
        matt c added a comment - Verified this functionality and the tests. May add additional tests for this going forward.

          People

          • Assignee:
            matt c
            Reporter:
            Chad Schoettger
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development