db-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1388139 - in /db/derby/code/branches/10.6: ./ java/client/org/apache/derby/client/am/LogicalConnection.java
Date Thu, 20 Sep 2012 17:56:38 GMT
Author: mamta
Date: Thu Sep 20 17:56:37 2012
New Revision: 1388139

URL: http://svn.apache.org/viewvc?rev=1388139&view=rev
Log:
DERBY-5561(Race conditions in LogicalConnection checking for a null physical connection )

Backporting to 10.6 codeline from trunk


Modified:
    db/derby/code/branches/10.6/   (props changed)
    db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/LogicalConnection.java

Propchange: db/derby/code/branches/10.6/
------------------------------------------------------------------------------
  Merged /db/derby/code/branches/10.7:r1383996
  Merged /db/derby/code/trunk:r1333305,1334919

Modified: db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/LogicalConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/LogicalConnection.java?rev=1388139&r1=1388138&r2=1388139&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/LogicalConnection.java
(original)
+++ db/derby/code/branches/10.6/java/client/org/apache/derby/client/am/LogicalConnection.java
Thu Sep 20 17:56:37 2012
@@ -24,17 +24,26 @@ import org.apache.derby.shared.common.re
 
 import java.sql.SQLException;
 
-
-// A simple delegation wrapper handle for a physical connection.
-// All methods are forwarded to the underlying physical connection except for close() and
isClosed().
-// When a physical connection is wrapped, it is non-null, when the logical connection
-// is closed, the wrapped physical connection is always set to null.
-// Both the finalizer and close() methods will always set the physical connection to null.
-// After the physical conneciton is set to null,
-// only the Pooled Connection instance will maintain a handle to the physical connection.
-
+/**
+ * A simple delegation wrapper handle for a physical connection.
+ * <p>
+ * All methods of the {@code Connection} interface are forwarded to the
+ * underlying physical connection, except for {@link #close()} and
+ * {@link #isClosed()}. When a physical connection is wrapped, it is non-null,
+ * when the logical connection is closed, the wrapped physical connection is
+ * always set to {@code null}.
+ * Both the finalizer and the {@code close}-methods will always set the 
+ * physical connection to {@code null}. After the physical connection has been
+ * nulled out, only the {@code PooledConnection} instance will maintain a
+ * handle to the physical connection.
+ */
 public class LogicalConnection implements java.sql.Connection {
-    protected Connection physicalConnection_ = null; // reset to null when the logical connection
is closed.
+    /**
+     * Underlying physical connection for this logical connection.
+     * <p>
+     * Set to {@code null} when this logical connection is closed.
+     */
+    Connection physicalConnection_;
     private org.apache.derby.client.ClientPooledConnection pooledConnection_ = null;
     /**
      * Logical database metadata object created on demand and then cached.
@@ -129,10 +138,17 @@ public class LogicalConnection implement
 
     // --------------------------- helper methods --------------------------------
 
-    // this method doesn't wrap in the standard way, because it went out without a throws
clause.
-    // Unlike all other LogicalConnection methods, if the physical connection is null, it
won't throw an exception, but will return false.
-
-    protected void checkForNullPhysicalConnection() throws SQLException {
+    /**
+     * Verifies that there is an underlying physical connection for this
+     * logical connection.
+     * <p>
+     * If the physical connection has been nulled out it means that this
+     * logical connection has been closed.
+     *
+     * @throws SQLException if this logical connection has been closed
+     */
+    protected final void checkForNullPhysicalConnection()
+            throws SQLException {
         if (physicalConnection_ == null) {
             SqlException se = new SqlException(null, 
                 new ClientMessageId(SQLState.NO_CURRENT_CONNECTION));
@@ -141,14 +157,14 @@ public class LogicalConnection implement
     }
 
     /**
-     * This method checks if the physcial connection underneath is null and
-     * if yes, then it simply returns.
-     * Otherwise, if the severity of exception is greater than equal to
-     * ExceptionSeverity.SESSION_SEVERITY, then we will send 
-     * connectionErrorOccurred event to all the registered listeners.
+     * Notifies listeners about exceptions of session level severity or higher.
+     * <p>
+     * The exception, even if the severity is sufficiently high, is ignored if
+     * the underlying physical connection has been nulled out. Otherwise a 
+     * {@code connectionErrorOccurred}-event is sent to all the registered
+     * listeners.
      * 
-     * @param sqle SQLException An event will be sent to the listeners if the
-     * exception's severity is >= ExceptionSeverity.SESSION_SEVERITY.
+     * @param sqle the cause of the notification
      */
 	final void notifyException(SQLException sqle) {
         if (physicalConnection_ != null) 
@@ -197,7 +213,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public String nativeSQL(String sql) throws SQLException {
+    synchronized public String nativeSQL(String sql) throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.nativeSQL(sql);
@@ -217,7 +233,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public boolean getAutoCommit() throws SQLException {
+    synchronized public boolean getAutoCommit() throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.getAutoCommit();
@@ -257,7 +273,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public int getTransactionIsolation() throws SQLException {
+    synchronized public int getTransactionIsolation() throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.getTransactionIsolation();
@@ -267,7 +283,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.sql.SQLWarning getWarnings() throws SQLException {
+    synchronized public java.sql.SQLWarning getWarnings() throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.getWarnings();
@@ -363,7 +379,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public boolean isReadOnly() throws SQLException {
+    synchronized public boolean isReadOnly() throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.isReadOnly();
@@ -383,7 +399,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public String getCatalog() throws SQLException {
+    synchronized public String getCatalog() throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.getCatalog();
@@ -428,7 +444,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.util.Map getTypeMap() throws SQLException {
+    synchronized public java.util.Map getTypeMap() throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.getTypeMap();
@@ -448,7 +464,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency,
+    synchronized public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency,
                                               int resultSetHoldability) throws SQLException
{
 		try {
 	        checkForNullPhysicalConnection();
@@ -459,7 +475,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.sql.CallableStatement prepareCall(String sql, int resultSetType,
+    synchronized public java.sql.CallableStatement prepareCall(String sql, int resultSetType,
                                                   int resultSetConcurrency,
                                                   int resultSetHoldability) throws SQLException
{
 		try {
@@ -471,7 +487,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.sql.PreparedStatement prepareStatement(String sql, int resultSetType,
+    synchronized public java.sql.PreparedStatement prepareStatement(String sql, int resultSetType,
                                                        int resultSetConcurrency, int resultSetHoldability)
             throws SQLException {
 		try {
@@ -484,7 +500,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.sql.PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
+    synchronized public java.sql.PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
             throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
@@ -495,7 +511,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.sql.PreparedStatement prepareStatement(String sql, int columnIndexes[])
+    synchronized public java.sql.PreparedStatement prepareStatement(String sql, int columnIndexes[])
             throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
@@ -506,7 +522,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.sql.PreparedStatement prepareStatement(String sql, String columnNames[])
+    synchronized public java.sql.PreparedStatement prepareStatement(String sql, String columnNames[])
             throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
@@ -517,7 +533,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public void setHoldability(int holdability) throws SQLException {
+    synchronized public void setHoldability(int holdability) throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        physicalConnection_.setHoldability(holdability);
@@ -527,7 +543,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public int getHoldability() throws SQLException {
+    synchronized public int getHoldability() throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.getHoldability();
@@ -537,7 +553,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.sql.Savepoint setSavepoint() throws SQLException {
+    synchronized public java.sql.Savepoint setSavepoint() throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.setSavepoint();
@@ -547,7 +563,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public java.sql.Savepoint setSavepoint(String name) throws SQLException {
+    synchronized public java.sql.Savepoint setSavepoint(String name) throws SQLException
{
 		try {
 	        checkForNullPhysicalConnection();
 	        return physicalConnection_.setSavepoint(name);
@@ -557,7 +573,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public void rollback(java.sql.Savepoint savepoint) throws SQLException {
+    synchronized public void rollback(java.sql.Savepoint savepoint) throws SQLException {
 		try {
 	        checkForNullPhysicalConnection();
 	        physicalConnection_.rollback(savepoint);
@@ -567,7 +583,7 @@ public class LogicalConnection implement
 		}
     }
 
-    public void releaseSavepoint(java.sql.Savepoint savepoint) throws SQLException {
+    synchronized public void releaseSavepoint(java.sql.Savepoint savepoint) throws SQLException
{
 		try {
 	        checkForNullPhysicalConnection();
 	        physicalConnection_.releaseSavepoint(savepoint);



Mime
View raw message