You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2008/05/26 15:29:53 UTC
svn commit: r660187 - in /db/derby/code/branches/10.4/java:
client/org/apache/derby/client/am/
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Author: kristwaa
Date: Mon May 26 06:29:50 2008
New Revision: 660187
URL: http://svn.apache.org/viewvc?rev=660187&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.
Merged revisions 647931, 648012 and 648180 from trunk to 10.4.
These changes also fix DERBY-3469.
Patches contributed by Tiago R. Espinha (whitespace changes by Knut Anders Hatlen).
Modified:
db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Blob.java
db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Clob.java
db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Connection.java
db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Lob.java
db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
Modified: db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Blob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Blob.java?rev=660187&r1=660186&r2=660187&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Blob.java (original)
+++ db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Blob.java Mon May 26 06:29:50 2008
@@ -29,11 +29,7 @@
import org.apache.derby.shared.common.reference.SQLState;
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------------------------------------------
byte[] binaryString_ = null;
@@ -608,11 +604,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_) {
if (agent_.loggingEnabled()) {
@@ -735,20 +731,6 @@
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();
- }
-
/**
* Materialize the stream used for input to the database.
Modified: db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Clob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Clob.java?rev=660187&r1=660186&r2=660187&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Clob.java (original)
+++ db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Clob.java Mon May 26 06:29:50 2008
@@ -48,10 +48,6 @@
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) {
@@ -816,11 +812,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 +1017,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/branches/10.4/java/client/org/apache/derby/client/am/Connection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Connection.java?rev=660187&r1=660186&r2=660187&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Connection.java (original)
+++ db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Connection.java Mon May 26 06:29:50 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
@@ -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/branches/10.4/java/client/org/apache/derby/client/am/Lob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Lob.java?rev=660187&r1=660186&r2=660187&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Lob.java (original)
+++ db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Lob.java Mon May 26 06:29:50 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 {
@@ -373,4 +385,27 @@
//valid
sqlLength();
}
+
+ /**
+ * Checks if 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 or the transaction that
+ * created the Lob is not active
+ */
+ 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/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java?rev=660187&r1=660186&r2=660187&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java (original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java Mon May 26 06:29:50 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();
@@ -1451,6 +1459,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();
@@ -2412,6 +2428,14 @@
if (blobLength == 26)
shortBlob = rs.getBlob(1);
}
+
+ /*
+ * We call it before the commit(); to cache the result
+ * DERBY-3574
+ */
+ blob.length();
+ shortBlob.length();
+
rs.close();
stmt.close();
commit();
@@ -2479,6 +2503,14 @@
if (blobLength == 26)
shortBlob = rs.getBlob(1);
}
+
+ /*
+ * We call it before the commit(); to cache the result
+ * DERBY-3574
+ */
+ blob.length();
+ shortBlob.length();
+
rs.close();
rollback();
getConnection().close();