db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r647931 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Mon, 14 Apr 2008 18:48:17 GMT
Author: kmarsden
Date: Mon Apr 14 11:48:13 2008
New Revision: 647931

URL: http://svn.apache.org/viewvc?rev=647931&view=rev
Log:
DERBY-3574 With client, attempting to get the lob length after commit or connection close
if there was a call to length() before commit does not throw an exception

Contributed by Tiago R. Espinha (tiago at espinhas dot net)


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Lob.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java?rev=647931&r1=647930&r2=647931&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Blob.java Mon Apr 14 11:48:13
2008
@@ -30,9 +30,7 @@
 
 public class Blob extends Lob implements java.sql.Blob {
     
-    //This boolean variable indicates whether the Blob object has
-    //been invalidated by calling free() on it
-    private boolean isValid = true;
+    
     
     //-----------------------------state------------------------------------------
 
@@ -608,11 +606,12 @@
         throws SQLException {
         
         //calling free() on a already freed object is treated as a no-op
-        if (!isValid) return;
+        if (!isValid_) return;
         
         //now that free has been called the Blob object is no longer
         //valid
-        isValid = false;
+        
+        isValid_ = false;
         try {            
             synchronized (agent_.connection_) {
                 if (agent_.loggingEnabled()) {
@@ -736,18 +735,7 @@
         return true;
     }
     
-    /**
-     * Checks is isValid is true. If it is not true throws 
-     * a SQLException stating that a method has been called on
-     * an invalid LOB object
-     *
-     * @throws SQLException if isValid is not true
-     */
-    private void checkValidity() throws SQLException{
-        if(!isValid)
-            throw new SqlException(null,new ClientMessageId(SQLState.LOB_OBJECT_INVALID))
-                                                  .getSQLException();
-    }
+    
     
 
     /**

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java?rev=647931&r1=647930&r2=647931&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java Mon Apr 14 11:48:13
2008
@@ -48,16 +48,17 @@
 
     protected String encoding_ = "UNICODE";
 
-    //This boolean variable indicates whether the Clob object has
-    //been invalidated by calling free() on it
-    private boolean isValid = true;
+ 
 
+    
+    
     //---------------------constructors/finalizer---------------------------------
     public Clob(Agent agent, String string) {
 
         this(agent,
              false);
 
+                
         string_ = string;
         setSqlLength(string_.length());
         dataType_ |= STRING;
@@ -240,6 +241,7 @@
         }
     }
 
+    
   /**
    * Returns a copy of the specified substring
    * in the <code>CLOB</code> value
@@ -816,11 +818,11 @@
         throws SQLException {
 
         //calling free() on a already freed object is treated as a no-op
-        if (!isValid) return;
+        if (!isValid_) return;
 
         //now that free has been called the Blob object is no longer
         //valid
-        isValid = false;
+        isValid_ = false;
 
         try {
             synchronized (agent_.connection_) {
@@ -1021,18 +1023,7 @@
     }
 
 
-    /*
-     * Checks is isValid is true. If it is not true throws
-     * a SQLException stating that a method has been called on
-     * an invalid LOB object
-     *
-     * throws SQLException if isvalid is not true.
-     */
-    private void checkValidity() throws SQLException{
-        if(!isValid)
-            throw new SqlException(null,new ClientMessageId(SQLState.LOB_OBJECT_INVALID))
-                                                  .getSQLException();
-    }
+
 
     /**
      * Materialize the stream used for input to the database.

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=647931&r1=647930&r2=647931&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 Mon Apr 14
11:48:13 2008
@@ -117,6 +117,8 @@
     private boolean accumulated440ForMessageProcFailure_ = false;
     private boolean accumulated444ForMessageProcFailure_ = false;
 
+    private int transactionID_ = 0;
+    
     //---------------------XA-----------------------------------------------------
 
     protected boolean isXAConnection_ = false; // Indicates an XA connection
@@ -559,7 +561,7 @@
             // internal code will call commitX which will ignore the commit request
             // while in a Global transaction
             checkForInvalidXAStateOnCommitOrRollback();
-            flowCommit();
+            flowCommit();            
         }
         catch ( SqlException se )
         {
@@ -1104,6 +1106,14 @@
     }
   
     /**
+     * Returns the ID of the active transaction for this connection.
+     * @return the ID of the active transaction
+     */
+    public int getTransactionID(){
+    	return transactionID_;
+    }
+    
+    /**
      * Returns the current schema (the schema that would be used for
      * compilation. This is not part of the java.sql.Connection interface, and
      * is only intended for use with statement caching.
@@ -1973,6 +1983,7 @@
             listener.completeLocalCommit(i);
         }
         inUnitOfWork_ = false;
+        transactionID_++;
     }
 
     public abstract void writeLocalRollback_() throws SqlException;
@@ -1989,6 +2000,7 @@
             listener.completeLocalRollback(i);
         }
         inUnitOfWork_ = false;
+        transactionID_++;
     }
     
     /**

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Lob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Lob.java?rev=647931&r1=647930&r2=647931&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Lob.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Lob.java Mon Apr 14 11:48:13
2008
@@ -53,6 +53,12 @@
     private long sqlLength_;// length of the LOB value, as defined by the server
     private boolean lengthObtained_;
     
+    /**
+     * This boolean variable indicates whether the Lob object has been
+     * invalidated by calling free() on it
+     */
+    protected boolean isValid_ = true;
+    
     final private boolean willBeLayerBStreamed_;
     
         
@@ -66,6 +72,11 @@
     //limit imposed.
     private long updateCount;
 
+    /**
+     * This integer identifies which transaction the Lob is associated with
+     */
+    private int transactionID_;
+    
     //-----------------------------messageId------------------------------------------
     final static protected ClientMessageId LOB_OBJECT_LENGTH_UNKNOWN_YET =
         new ClientMessageId( SQLState.LOB_OBJECT_LENGTH_UNKNOWN_YET );
@@ -77,6 +88,7 @@
         agent_ = agent;
         lengthObtained_ = false;
         willBeLayerBStreamed_ = willBeLayerBStreamed;
+        transactionID_ = agent_.connection_.getTransactionID();
     }
 
     protected void finalize() throws java.lang.Throwable {
@@ -98,7 +110,7 @@
      */
     long sqlLength() throws SqlException 
     {
-        if (lengthObtained_) return sqlLength_;
+    	if (lengthObtained_) return sqlLength_;
         
         if (isLocator()) {
             sqlLength_ = getLocatorLength();
@@ -372,5 +384,29 @@
         //the locator associated with the underlying LOB is not
         //valid
         sqlLength();
+    }
+    
+    /**
+     * Checks is isValid is true and whether the transaction that
+     * created the Lob is still active. If any of which is not true throws 
+     * a SQLException stating that a method has been called on
+     * an invalid LOB object
+     *
+     * @throws SQLException if isValid is not true
+     */
+    protected void checkValidity() throws SQLException{
+    	
+    	/**
+    	 * If there isn't an open connection, the Lob is invalid.
+    	 */
+    	try{
+    		agent_.connection_.checkForClosedConnection();
+    	}catch(SqlException se){
+    		throw se.getSQLException();
+    	}
+    	
+        if(!isValid_ || transactionID_ != agent_.connection_.getTransactionID())
+            throw new SqlException(null,new ClientMessageId(SQLState.LOB_OBJECT_INVALID))
+                                                  .getSQLException();
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java?rev=647931&r1=647930&r2=647931&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
Mon Apr 14 11:48:13 2008
@@ -1359,6 +1359,14 @@
             if (clobLength == 26)
                 shortClob = rs.getClob(1);
         }
+        
+        /**
+         * We call it before the commit(); to cache the result
+         * DERBY-3574
+         */
+        clob.length();
+        shortClob.length();
+        
         rs.close();
         stmt.close();
         commit();



Mime
View raw message