OpenJPA
  1. OpenJPA
  2. OPENJPA-1729 Simplified connection pooling
  3. OPENJPA-1764

Automatically enable connection pooling in unmanaged environments

    Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.1.0
    • Component/s: jdbc, performance
    • Labels:
      None

      Description

      When commons-dbcp is present on the classpath and we are running in a JSE or unmanaged environment, we should automatically configure DriverClassName=org.apache.commons.dbcp.BasicDataSource and apply some DBCP args (this might be the tricky part, based on the different dbcp args we have to use today for different databases...)

      1. OPENJPA-1764-docs.diff
        12 kB
        Donald Woods
      2. OPENJPA-1764-20100928.diff
        35 kB
        Donald Woods
      3. OPENJPA-1764-20100927.diff
        34 kB
        Donald Woods

        Issue Links

          Activity

          Hide
          Donald Woods added a comment -

          doc updates

          Show
          Donald Woods added a comment - doc updates
          Hide
          Albert Lee added a comment -

          Hitting the following exception in 3 tests in TestSwitchConnection after fixing the derby check condition:

          r422266:1022612 fatal user error> org.apache.openjpa.util.UserException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
          at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:76)
          at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:842)
          at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:600)
          at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1486)
          at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518)
          at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443)
          at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104)
          at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
          at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
          at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:949)
          at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:940)
          at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.clear(AbstractPersistenceTestCase.java:301)
          at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.closeEMF(AbstractPersistenceTestCase.java:233)
          at org.apache.openjpa.persistence.conf.TestSwitchConnection.testDataCache(TestSwitchConnection.java:195)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          Looks like the closeEMF(emf1) in the finally clause of the failing tests still require the ConnectionDriverName to be available.

          Show
          Albert Lee added a comment - Hitting the following exception in 3 tests in TestSwitchConnection after fixing the derby check condition: r422266:1022612 fatal user error> org.apache.openjpa.util.UserException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property. at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:76) at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:842) at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:600) at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1486) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443) at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104) at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68) at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:949) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:940) at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.clear(AbstractPersistenceTestCase.java:301) at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.closeEMF(AbstractPersistenceTestCase.java:233) at org.apache.openjpa.persistence.conf.TestSwitchConnection.testDataCache(TestSwitchConnection.java:195) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) Looks like the closeEMF(emf1) in the finally clause of the failing tests still require the ConnectionDriverName to be available.
          Hide
          Albert Lee added a comment -

          After r1021574 commit, I am getting a NPE as in:

          java.lang.NullPointerException
          at org.apache.openjpa.persistence.conf.TestSwitchConnection.setUp(TestSwitchConnection.java:55)
          at junit.framework.TestCase.runBare(TestCase.java:125)
          at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.runBare(AbstractPersistenceTestCase.java:536)
          at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.runBare(AbstractPersistenceTestCase.java:512)
          at junit.framework.TestResult$1.protect(TestResult.java:106)
          at junit.framework.TestResult.runProtected(TestResult.java:124)
          at junit.framework.TestResult.run(TestResult.java:109)
          at junit.framework.TestCase.run(TestCase.java:118)
          at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.run(AbstractPersistenceTestCase.java:205)
          at junit.framework.TestSuite.runTest(TestSuite.java:208)
          at junit.framework.TestSuite.run(TestSuite.java:203)
          at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
          at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

          I believe this occurs when I tried Derby without specifying connection user/pwd.

          TestSwitchConnection/TestOverrideNonJtaDataSource

          public void setUp() throws Exception {
          super.setUp(Person.class, CLEAR_TABLES);
          OpenJPAEntityManager em = emf.createEntityManager();
          JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration();
          if (conf.getConnectionUserName() != null || !conf.getConnectionUserName().equals("")) { <<<< the 2nd getConnectionUserName() call returns null and hence the NPE
          // Disable for non-Derby, due to connectionUserName to schema mapping failures
          setTestsDisabled(true);

          Are we assuming if no username is specified, Derby is used? If so, should the check be

          if (conf.getConnectionUserName() == null || conf.getConnectionUserName().equals(""))

          { // create an EMF for each database. init(defaultJndiName); init(jndiNames[0]); }

          else

          { // Disable for non-Derby, due to connectionUserName to schema mapping failures setTestsDisabled(true); getLog().trace("TestOverrideNonJtaDataSource can only be executed against Derby w/o a schema"); }

          Albert Lee.

          Show
          Albert Lee added a comment - After r1021574 commit, I am getting a NPE as in: java.lang.NullPointerException at org.apache.openjpa.persistence.conf.TestSwitchConnection.setUp(TestSwitchConnection.java:55) at junit.framework.TestCase.runBare(TestCase.java:125) at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.runBare(AbstractPersistenceTestCase.java:536) at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.runBare(AbstractPersistenceTestCase.java:512) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.run(AbstractPersistenceTestCase.java:205) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) I believe this occurs when I tried Derby without specifying connection user/pwd. TestSwitchConnection/TestOverrideNonJtaDataSource public void setUp() throws Exception { super.setUp(Person.class, CLEAR_TABLES); OpenJPAEntityManager em = emf.createEntityManager(); JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration(); if (conf.getConnectionUserName() != null || !conf.getConnectionUserName().equals("")) { <<<< the 2nd getConnectionUserName() call returns null and hence the NPE // Disable for non-Derby, due to connectionUserName to schema mapping failures setTestsDisabled(true); Are we assuming if no username is specified, Derby is used? If so, should the check be if (conf.getConnectionUserName() == null || conf.getConnectionUserName().equals("")) { // create an EMF for each database. init(defaultJndiName); init(jndiNames[0]); } else { // Disable for non-Derby, due to connectionUserName to schema mapping failures setTestsDisabled(true); getLog().trace("TestOverrideNonJtaDataSource can only be executed against Derby w/o a schema"); } Albert Lee.
          Hide
          Donald Woods added a comment -

          Updates based on Rick's comments.

          Show
          Donald Woods added a comment - Updates based on Rick's comments.
          Hide
          Rick Curtis added a comment -

          One nit... change your constants(ie DBCPDriverDataSource._dbcpPackageName) to be uppercase.

          Show
          Rick Curtis added a comment - One nit... change your constants(ie DBCPDriverDataSource._dbcpPackageName) to be uppercase.
          Hide
          Donald Woods added a comment -

          Code to introduce automatic usage of Commons DBCP for Java SE apps in a non-managed and non-transaction setup, when Commons DBCP is on the class path.
          The default behavior is -
          openjpa.jdbc.DriverDataSource=auto
          but users can force usage of DBCP or fail if it not available by setting -
          openjpa.jdbc.DriverDataSource=dbcp
          or force the old behavior of using the ConnectionDriverName as-is by setting -
          openjpa.jdbc.DriverDataSource=simple

          The openjpa.ConnectionProperties setting can be used to provide Commons DBCP arguments, like -
          MaxActive=10,MaxIdle=0,MinIdle=0,MaxWait=10000
          but the DBCPDriverDataSource will use the following defaults if none are provided -
          MaxActive=10,MaxIdle=1,MinIdle=0

          Show
          Donald Woods added a comment - Code to introduce automatic usage of Commons DBCP for Java SE apps in a non-managed and non-transaction setup, when Commons DBCP is on the class path. The default behavior is - openjpa.jdbc.DriverDataSource=auto but users can force usage of DBCP or fail if it not available by setting - openjpa.jdbc.DriverDataSource=dbcp or force the old behavior of using the ConnectionDriverName as-is by setting - openjpa.jdbc.DriverDataSource=simple The openjpa.ConnectionProperties setting can be used to provide Commons DBCP arguments, like - MaxActive=10,MaxIdle=0,MinIdle=0,MaxWait=10000 but the DBCPDriverDataSource will use the following defaults if none are provided - MaxActive=10,MaxIdle=1,MinIdle=0

            People

            • Assignee:
              Donald Woods
              Reporter:
              Donald Woods
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development