You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2008/08/06 17:32:26 UTC

svn commit: r683298 - in /openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc: kernel/AbstractJDBCSeq.java sql/DBDictionary.java

Author: mikedd
Date: Wed Aug  6 08:32:26 2008
New Revision: 683298

URL: http://svn.apache.org/viewvc?rev=683298&view=rev
Log:
OPENJPA-676 close connection used for CONTIGUOUS or TRANSACTIONAL sequences

Modified:
    openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractJDBCSeq.java
    openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java

Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractJDBCSeq.java?rev=683298&r1=683297&r2=683298&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractJDBCSeq.java (original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractJDBCSeq.java Wed Aug  6 08:32:26 2008
@@ -25,6 +25,7 @@
 import javax.transaction.TransactionManager;
 
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.kernel.JDBCStoreManager.RefCountConnection;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.schema.SchemaGroup;
 import org.apache.openjpa.jdbc.sql.SQLExceptions;
@@ -156,8 +157,10 @@
      */
     protected Connection getConnection(JDBCStore store)
         throws SQLException {
-        if (type == TYPE_TRANSACTIONAL || type == TYPE_CONTIGUOUS)
+        if (type == TYPE_TRANSACTIONAL || type == TYPE_CONTIGUOUS) {
+            // Also increments ref count.
             return store.getConnection();
+        }
         else {
             JDBCConfiguration conf = store.getConfiguration();
             DataSource ds = conf.getDataSource2(store.getContext());
@@ -171,13 +174,24 @@
     /**
      * Close the current connection. If the sequence is
      * <code>TYPE_TRANSACTIONAL</code> or <code>TYPE_CONTIGUOUS</code>
-     * nothing will be done. Otherwise the connection will be closed.
+     * we will decrement the ref count. Otherwise the connection will be
+     * committed and then closed. 
      */
     protected void closeConnection(Connection conn) {
         if (conn == null)
             return;
         if (type == TYPE_TRANSACTIONAL || type == TYPE_CONTIGUOUS) {
-            // do nothing; this seq is part of the business transaction
+            // The seq is part of the business transaction however we need
+            // to decrement the ref count so that the connection may be 
+            // closed appropriately.
+            if(conn instanceof RefCountConnection) { 
+            	try { 
+            		((RefCountConnection)conn).close();
+            	}
+            	catch(SQLException se) { 
+            		throw SQLExceptions.getStore(se);
+            	}
+            }
             return;
         }
         else {

Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=683298&r1=683297&r2=683298&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java Wed Aug  6 08:32:26 2008
@@ -329,7 +329,7 @@
     public String sequenceSchemaSQL = null;
     public String sequenceNameSQL = null;
     // most native sequences can be run inside the business transaction
-    public int nativeSequenceType= Seq.TYPE_CONTIGUOUS;
+    public int nativeSequenceType= Seq.TYPE_TRANSACTIONAL;
 
     protected JDBCConfiguration conf = null;
     protected Log log = null;