db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1442474 - /db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
Date Tue, 05 Feb 2013 05:14:02 GMT
Author: mamta
Date: Tue Feb  5 05:14:01 2013
New Revision: 1442474

URL: http://svn.apache.org/viewvc?rev=1442474&view=rev
Log:
DERBY-6053(Client should use a prepared statement rather than regular statement for Connection.setTransactionIsolation)

Use prepared statements rather than regular statement to change the isolation level in client
server mode. This will be better for performance and will also avoid possible garbage collection
issues.


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java?rev=1442474&r1=1442473&r2=1442474&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java Tue Feb  5
05:14:01 2013
@@ -91,8 +91,9 @@ public abstract class Connection
     // Used to get the public key and encrypt password and/or userid
     protected EncryptionManager encryptionManager_;
 
-    // used to set transaction isolation level
-    private Statement setTransactionIsolationStmt = null;
+    //prepared statements associated with isolation level change are stored 
+    // in isolationLevelPreparedStmts
+    private Hashtable isolationLevelPreparedStmts = new Hashtable();
     
     // used to get transaction isolation level
     private Statement getTransactionIsolationStmt = null;
@@ -789,14 +790,24 @@ public abstract class Connection
         
         resetConnectionAtFirstSql_ = false; // unset indicator of deferred reset
         SQLException accumulatedExceptions = null;
-        if (setTransactionIsolationStmt != null) {
-            try {
-                setTransactionIsolationStmt.close();
-            } catch (SQLException se) {
-                accumulatedExceptions = se;
+
+        //Close prepared statements associated with isolation level change
+        if (isolationLevelPreparedStmts != null) {
+            PreparedStatement ps;
+            for (Iterator<PreparedStatement> it = isolationLevelPreparedStmts.keySet().iterator();
+                    it.hasNext(); ) {
+                try {
+                    Object key = it.next();
+                    ps = (PreparedStatement)isolationLevelPreparedStmts.get(key);
+                    ps.close();
+                    ps = null;
+                } catch (SQLException se) {
+                    accumulatedExceptions = Utils.accumulateSQLException(
+                            se, accumulatedExceptions);
+                }
             }
+            isolationLevelPreparedStmts.clear();
         }
-        setTransactionIsolationStmt = null;
         if (getTransactionIsolationStmt != null) {
             try {
                 getTransactionIsolationStmt.close();
@@ -1008,18 +1019,22 @@ public abstract class Connection
                 new ClientMessageId (SQLState.UNIMPLEMENTED_ISOLATION_LEVEL),
                 level);
         }
-        if (setTransactionIsolationStmt == null  ||
-                !(setTransactionIsolationStmt.openOnClient_ &&
-                        setTransactionIsolationStmt.openOnServer_)) {
-            setTransactionIsolationStmt =
-                    createStatementX(java.sql.ResultSet.TYPE_FORWARD_ONLY,
-                            java.sql.ResultSet.CONCUR_READ_ONLY,
-                            holdability());
+        //If we do not already have a prepared statement for the requested
+        // isolation level change, then create one
+        PreparedStatement ps = (PreparedStatement)isolationLevelPreparedStmts.get(levelString);
+        if (ps == null  || !ps.openOnClient_) {
+            ps = prepareStatementX(
+                    "SET CURRENT ISOLATION = " + levelString,
+                    java.sql.ResultSet.TYPE_FORWARD_ONLY,
+                    java.sql.ResultSet.CONCUR_READ_ONLY,
+                    holdability(),
+                    java.sql.Statement.NO_GENERATED_KEYS,
+                    null, null);
+            isolationLevelPreparedStmts.put(levelString, ps);
         }
-
+        //Execute the prepared statement to change the isolation level
         try {
-            setTransactionIsolationStmt.executeUpdate(
-                "SET CURRENT ISOLATION = " + levelString);
+            ps.execute();
         } catch (SQLException sqle) {
             throw new SqlException(sqle);
         }



Mime
View raw message