db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r557033 - in /db/derby/code/branches/10.3/java: drda/org/apache/derby/impl/drda/ engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ testing/org/apache/derbyTest...
Date Tue, 17 Jul 2007 19:23:41 GMT
Author: kmarsden
Date: Tue Jul 17 12:23:40 2007
New Revision: 557033

URL: http://svn.apache.org/viewvc?view=rev&rev=557033
Log:
DERBY-2941 With 10.2, Closing a resultset after retrieving a large > 32665 bytes value
with Network Server does not release locks

Verified LargeDataLocksTest with 10.2 client 10.3 server


Added:
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LargeDataLocksTest.java
      - copied, changed from r554073, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LargeDataLocksTest.java
Modified:
    db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineResultSet.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/Utilities.java

Modified: db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?view=diff&rev=557033&r1=557032&r2=557033
==============================================================================
--- db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Tue
Jul 17 12:23:40 2007
@@ -6656,7 +6656,7 @@
 
 					if (SanityManager.DEBUG)
 						trace("!!drdaType = " + java.lang.Integer.toHexString(drdaType) + 
-					 			 "precision = " + precision +" scale = " + scale);
+					 			 " precision=" + precision +" scale = " + scale);
 					switch (ndrdaType)
 					{
 						case DRDAConstants.DRDA_TYPE_NLOBBYTES:
@@ -6664,7 +6664,7 @@
 							EXTDTAInputStream extdtaStream=  
 								EXTDTAInputStream.getEXTDTAStream(rs, i, drdaType);
 							writeFdocaVal(i,extdtaStream, drdaType,
-										  precision,scale,rs.wasNull(),stmt);
+										  precision,scale,extdtaStream.isNull(),stmt);
 							break;
 						case DRDAConstants.DRDA_TYPE_NINTEGER:
 							int ival = rs.getInt(i);
@@ -7946,7 +7946,9 @@
 		Object o  = extdtaValues.get(i);
         if (o instanceof EXTDTAInputStream) {
 			EXTDTAInputStream stream = (EXTDTAInputStream) o;
+                        
 			try{
+                        stream.initInputStream();
 			writer.writeScalarStream (chainedWithSameCorrelator,
 									  CodePoint.EXTDTA,
 									  stream,

Modified: db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java?view=diff&rev=557033&r1=557032&r2=557033
==============================================================================
--- db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java
(original)
+++ db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java
Tue Jul 17 12:23:40 2007
@@ -23,11 +23,13 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.BufferedInputStream;
+import java.io.Reader;
 import java.sql.ResultSet;
 import java.sql.Blob;
 import java.sql.Clob;
 import java.sql.SQLException;
 
+import org.apache.derby.iapi.jdbc.EngineResultSet;
 import org.apache.derby.iapi.reference.DRDAConstants;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.impl.jdbc.Util;
@@ -45,35 +47,33 @@
 class EXTDTAInputStream extends InputStream {
 
     private InputStream binaryInputStream = null;
-
-    private boolean isEmptyStream;
-	
-    private ResultSet dataResultSet = null;
-    private Blob blob = null;
-    private Clob clob = null;
+ 
+    
+    /** ResultSet that contains the stream*/
+    EngineResultSet rs;
+    /** Column index starting with 1 */
+    int columnNumber;
+    /** DRDA Type of column */
+    int ndrdaType;
+      
 	
 	private EXTDTAInputStream(ResultSet rs,
 				  int columnNumber,
 				  int ndrdaType) 
-	    throws SQLException, IOException
     {
 	
-	    this.dataResultSet = rs;
-	    this.isEmptyStream = ! initInputStream(rs,
-						   columnNumber,
-						   ndrdaType);
-		
-	}
+        this.rs = (EngineResultSet) rs;
+	    this.columnNumber = columnNumber;
+	    this.ndrdaType = ndrdaType;
+        }
 
     
-    
 	/**
-	 * Retrieve stream from the ResultSet and column specified.  Create an
-	 * input stream for the large object being retrieved. Do not hold
-	 * locks until end of transaction. DERBY-255.
-	 * 
+	 * Create a new EXTDTAInputStream.  Before read the stream must be 
+     * initialized by the user with {@link #initInputStream()} 
 	 * 
-	 * See DDMWriter.writeScalarStream
+	 * @see DDMWriter#writeScalarStream
+     * @see #initInputStream()
 	 * 
 	 * @param rs
 	 *            result set from which to retrieve the lob
@@ -92,61 +92,25 @@
 	 * @throws SQLException
 	 */
 	public static EXTDTAInputStream getEXTDTAStream(ResultSet rs, int column, int drdaType)

-			throws SQLException {
- 	    try{
+		{
+ 	    
 		int ndrdaType = drdaType | 1; //nullable drdaType
 			
 		return new EXTDTAInputStream(rs,
 					     column,
 					     ndrdaType);
 		
- 	    }catch(IOException e){
- 		throw new SQLException(e.getMessage());
-		}
-		
 	}
 
 	
-	/**
-	 * Get the length of the InputStream 
-	 * This method is currently not used because there seems to be no way to 
-	 * reset the she stream.
-	 *   
-	 * @param binaryInputStream
-	 *            an InputStream whose length needs to be calclulated
-	 * @return length of stream
-	 */
-	private static long getInputStreamLength(InputStream binaryInputStream)
-			throws SQLException {
-		long length = 0;
-		if (binaryInputStream == null)
-			return length;
-		
-		try {
-			for (;;) {
-				int avail = binaryInputStream.available();
-				binaryInputStream.skip(avail);
-				if (avail == 0)
-					break;
-				length += avail;
-				
-			}
-			//binaryInputStream.close();
-		} catch (IOException ioe) {
-			throw Util.javaException(ioe);
-		}
-
-		return length;
-
-	}
-	
 	
 	/**
-	 * 
+	 * Requires {@link #initInputStream()} be called before we can read from the stream
 	 * 
 	 * @see java.io.InputStream#read()
 	 */
 	public int read() throws IOException {
+                       
 		return binaryInputStream.read();
 	}
 
@@ -166,17 +130,9 @@
 	 */
 	public void close() throws IOException {
 	    
-	    try{
 		if (binaryInputStream != null)
 			binaryInputStream.close();	
 		binaryInputStream = null;
-
-	    }finally{
-		
-		blob = null;
-		clob = null;
-		dataResultSet = null;
-	    }
 	    
 	}
 
@@ -256,60 +212,51 @@
 	}
 
 
-    protected boolean isEmptyStream(){
-	return isEmptyStream;
-    }
+    protected boolean isEmptyStream() throws SQLException{
+            return (rs.getLength(columnNumber) == 0);
+        
+        }
     
     
     /**
      * This method takes information of ResultSet and 
-     * initialize binaryInputStream variable of this object with not empty stream and return
true.
-     * If the stream was empty, this method remain binaryInputStream null and return false.
+     * initializes the binaryInputStream variable of this object with not empty stream 
+     * by calling getBinaryStream or getCharacterStream() as appropriate.
+     * The Reader returned from getCharacterStream() will be encoded in binarystream.
      *
-     * @param rs        ResultSet object to get stream from.
-     * @param column    index number of column in ResultSet to get stream.
-     * @param ndrdaType describe type column to get stream.
-     *
-     * @return          true if the stream was not empty, false if the stream was empty.
      *
      */
-    private boolean initInputStream(ResultSet rs,
-				    int column,
-				    int ndrdaType)
-	throws SQLException,
-	       IOException
+    public  void initInputStream()
+	throws SQLException
     {
 
 	InputStream is = null;
-	try{
-	    // BLOBS
-	    if (ndrdaType == DRDAConstants.DRDA_TYPE_NLOBBYTES) 
-		{
-		    blob = rs.getBlob(column);
-		    if(blob == null){
-			return false;
-		    }
-		    
-		    is = blob.getBinaryStream();
-		    
-		}
+	Reader r = null;
+	// BLOBS
+	if (ndrdaType == DRDAConstants.DRDA_TYPE_NLOBBYTES) 
+	{ 	    	
+	    is = this.rs.getBinaryStream(this.columnNumber);
+	    if (is == null) 
+              return;
+	}
 	    // CLOBS
-	    else if (ndrdaType ==  DRDAConstants.DRDA_TYPE_NLOBCMIXED)
-		{	
-		    try {
-			clob = rs.getClob(column);
-			
-			if(clob == null){
-			    return false;
-			}
+	else if (ndrdaType ==  DRDAConstants.DRDA_TYPE_NLOBCMIXED)
+	{	
+	    try {
+	        
+	        r = this.rs.getCharacterStream(this.columnNumber);
+		    	
+	        if(r == null){	            
+                    return;
+	        }
 
-			is = new ReEncodedInputStream(clob.getCharacterStream());
+			is = new ReEncodedInputStream(r);
 			
 		    }catch (java.io.UnsupportedEncodingException e) {
-			throw new SQLException (e.getMessage());
+			throw Util.javaException(e);
 			
 		    }catch (IOException e){
-			throw new SQLException (e.getMessage());
+			throw Util.javaException(e);
 			
 		    }
 		    
@@ -322,74 +269,29 @@
 						      " not valid EXTDTA object type");
 			}
 		}
-	    
-	    boolean exist = is.read() > -1;
-	    
-	    is.close();
-	    is = null;
-	    
-	    if(exist){
-		openInputStreamAgain();
-	    }
-
-	    return exist;
-	    
-	}catch(IllegalStateException e){
-	    throw Util.javaException(e);
-
-	}finally{
-	    if(is != null)
-		is.close();
-	    
-	}
-	
-    }
-    
-    
-    /**
-     *
-     * This method is called from initInputStream and 
-     * opens inputstream again to stream actually.
-     *
-     */
-    private void openInputStreamAgain() throws IllegalStateException,SQLException {
-	
-	if(this.binaryInputStream != null){
-	    return;
-	}
-		
-	InputStream is = null;
-	try{
-	    
-	    if(SanityManager.DEBUG){
-		SanityManager.ASSERT( ( blob != null && clob == null ) ||
-				      ( clob != null && blob == null ),
-				      "One of blob or clob must be non-null.");
-	    }
-
-	    if(blob != null){
-		is = blob.getBinaryStream();
-		
-	    }else if(clob != null){
-		is = new ReEncodedInputStream(clob.getCharacterStream());
+	if (! is.markSupported()) {
+	    is = new BufferedInputStream(is);
 	    }
 	    
-	}catch(IOException e){
-	    throw new IllegalStateException(e.getMessage());
-	}
-	
-	if(! is.markSupported() ){
-	    is = new BufferedInputStream(is);
-	}
-
-	this.binaryInputStream = is;
-
+ 	this.binaryInputStream=is;
     }
     
-    
+        
     protected void finalize() throws Throwable{
 	close();
 	}
 
-
+    /**
+     * Is the value null?  Null status is obtained from the underlying 
+     * EngineResultSet, so that it can be determined before the stream
+     * is retrieved.
+     * 
+     * @return true if this value is null
+     * 
+     */
+    public boolean isNull() throws SQLException
+    {
+        return this.rs.isNull(columnNumber);
+     
+    }
 }

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineResultSet.java?view=diff&rev=557033&r1=557032&r2=557033
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineResultSet.java
Tue Jul 17 12:23:40 2007
@@ -21,6 +21,9 @@
 package org.apache.derby.iapi.jdbc;
 
 import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.derby.iapi.error.StandardException;
 /**
  * Additional methods the embedded engine exposes on its ResultSet object
  * implementations. An internal api only, mainly for the network
@@ -32,4 +35,26 @@
      * Is this result set from a select for update statement?
      */
     public boolean isForUpdate();
+    
+    /**
+     * Is the designated columnIndex a null data value?
+     * This is used by EXTDTAInputStream to get the null value without 
+     * retrieving the underlying data value.
+     * @param columnIndex
+     * @return true if the data value at columnIndex for the current row is null 
+     * @throws SQLException 
+     */
+    public boolean isNull(int columnIndex) throws SQLException;
+    
+    /**
+     * Return the length of the designated columnIndex data value.
+     * Implementation is type dependent.
+     * 
+     * @param columnIndex  column to access
+     * @return length of data value
+     * @throws SQLException
+     * @see org.apache.derby.iapi.types.DataValueDescriptor#getLength() 
+     */
+    public int getLength(int columnIndex) throws SQLException;
+    
 }

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?view=diff&rev=557033&r1=557032&r2=557033
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
Tue Jul 17 12:23:40 2007
@@ -5051,4 +5051,26 @@
        checkIfClosed("updateClob");
        updateClob(findColumnName(columnName), x);
     }
+    
+    /* 
+     * @see org.apache.derby.iapi.jdbc.EngineResultSet#isNull(int)
+     */
+    public boolean isNull(int columnIndex) throws SQLException{
+        try {
+            DataValueDescriptor dvd = getColumn(columnIndex);
+            return dvd.isNull();
+        } catch (StandardException t) {
+                throw noStateChangeException(t);
+        }
+    }
+    
+    public int getLength(int columnIndex) throws SQLException {
+        try {
+            DataValueDescriptor dvd = getColumn(columnIndex);
+            return dvd.getLength();            
+        } catch (StandardException t) {
+                throw noStateChangeException(t);
+        }
+    }
+    
 }

Copied: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LargeDataLocksTest.java
(from r554073, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LargeDataLocksTest.java)
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LargeDataLocksTest.java?view=diff&rev=557033&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LargeDataLocksTest.java&r1=554073&p2=db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LargeDataLocksTest.java&r2=557033
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LargeDataLocksTest.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/LargeDataLocksTest.java
Tue Jul 17 12:23:40 2007
@@ -23,150 +23,141 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.sql.Clob;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.apache.derbyTesting.functionTests.tests.lang.ScrollCursors1Test;
-import org.apache.derbyTesting.functionTests.tests.lang.UpdateCursorTest;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
-import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
-import org.apache.derbyTesting.junit.JDBC;
-import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
-import org.apache.derbyTesting.junit.Utilities;
 import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.Utilities;
 
 public class LargeDataLocksTest extends BaseJDBCTestCase {
 
-	
     public LargeDataLocksTest(String name) {
         super(name);
     }
-    
-   
- /**
- * Test that ResultSet.getCharacterStream does not hold locks after the
- * ResultSet is closed
- * @throws SQLException
- * @throws IOException
- */
-public void testGetCharacterStream() throws SQLException, IOException {
-	   // getCharacterStream() no locks expected after retrieval
-		int numChars = 0;
-		Statement stmt=createStatement();		
-		String sql = "SELECT bc from t1";
-		// First with getCharacterStream
-		ResultSet rs = stmt.executeQuery(sql);
-		rs.next();
-		java.io.Reader characterStream = rs.getCharacterStream(1);
-		// Extract all the characters
-		int read = characterStream.read();
-		while (read != -1) {
-			read = characterStream.read();
-			numChars ++;
-		}
-		assertEquals(38000,numChars);
-		rs.close();
-		assertEquals(0,countLocks());
-		commit();		
-   }
-  
-/**
- * Verify that getBytes does not hold locks after ResultSet is closed.
- * @throws SQLException
- */
-public void testGetBytes() throws SQLException {
-	// getBytes() no locks expected after retrieval
-	Statement stmt=createStatement();		
-	String sql = "SELECT bincol from t1" ;
-	ResultSet rs = stmt.executeQuery(sql);
-	rs.next();
-	byte[] value = rs.getBytes(1);
-	assertEquals(38000,value.length);
-	rs.close();
-	assertEquals(0,countLocks());
-	commit();
-	
-}
 
- /**
- * Verify that getBinaryStream() does not hold locks after retrieval
- * @throws SQLException
- * @throws IOException 
- */
-public void testGetBinaryStream() throws SQLException, IOException {
-		int numBytes = 0;
-	  Statement stmt=createStatement();		
-		String sql = "SELECT bincol from t1" ;
-		ResultSet rs = stmt.executeQuery(sql);
-		rs.next();
-		InputStream stream = rs.getBinaryStream(1);
-		int read = stream.read();
-		while (read != -1) {
-			read = stream.read();
-			numBytes ++;
-		}
-		assertEquals(38000,numBytes);
-		rs.close();
-		assertEquals(0,countLocks());
-		commit(); 	  
-  }
-  
- /**
- * Test that ResultSet.getString() does not hold locks after the ResultSet is closed
- * @throws SQLException
- * @throws IOException
- */
-public void testGetString() throws SQLException, IOException {
-	   // getString() no locks expected after retrieval
-		Statement stmt=createStatement();		
-		String sql = "SELECT bc from t1" ;
-		ResultSet rs = stmt.executeQuery(sql);
-		rs.next();
-		String value = rs.getString(1);
-		assertEquals(38000,value.length());
-		rs.close();
-		assertEquals(0,countLocks());
-		commit();		
-   }
-   
-   
-   
-   
- /**
-  * Create a new connection and count the number of locks held.
- * @return  number of locks held
- * 
- * @throws SQLException
- */
-public int countLocks() throws SQLException
-   {
-	   		Connection conn = openDefaultConnection();
-			String sql;
-			Statement stmt = conn.createStatement();
-				
-			sql = "Select count(*) from new org.apache.derby.diag.LockTable() as LT";
-			ResultSet lockrs = stmt.executeQuery(sql);
-			lockrs.next();
-			int count = lockrs.getInt(1);
-			lockrs.close();
-			stmt.close();
-			conn.close();
-			return count;
-		}
-   
-	
+    /**
+     * Test that ResultSet.getCharacterStream does not hold locks after the
+     * ResultSet is closed
+     * 
+     * @throws SQLException
+     * @throws IOException
+     */
+    public void testGetCharacterStream() throws SQLException, IOException {
+        // getCharacterStream() no locks expected after retrieval
+        int numChars = 0;
+        Statement stmt = createStatement();
+        String sql = "SELECT bc from t1";
+        // First with getCharacterStream
+        ResultSet rs = stmt.executeQuery(sql);
+        rs.next();
+        java.io.Reader characterStream = rs.getCharacterStream(1);
+        // Extract all the characters
+        int read = characterStream.read();
+        while (read != -1) {
+            read = characterStream.read();
+            numChars++;
+        }
+        assertEquals(38000, numChars);
+        rs.close();
+        assertEquals(0, countLocks());
+        commit();
+    }
+
+    /**
+     * Verify that getBytes does not hold locks after ResultSet is closed.
+     * 
+     * @throws SQLException
+     */
+    public void testGetBytes() throws SQLException {
+        // getBytes() no locks expected after retrieval
+        Statement stmt = createStatement();
+        String sql = "SELECT bincol from t1";
+        ResultSet rs = stmt.executeQuery(sql);
+        rs.next();
+        byte[] value = rs.getBytes(1);
+        assertEquals(38000, value.length);
+        rs.close();
+        assertEquals(0, countLocks());
+        commit();
+
+    }
+
+    /**
+     * Verify that getBinaryStream() does not hold locks after retrieval
+     * 
+     * @throws SQLException
+     * @throws IOException
+     */
+    public void testGetBinaryStream() throws SQLException, IOException {
+        int numBytes = 0;
+        getConnection().setAutoCommit(false);
+        Statement stmt = createStatement();
+        String sql = "SELECT bincol from t1";
+        ResultSet rs = stmt.executeQuery(sql);
+        rs.next();
+        InputStream stream = rs.getBinaryStream(1);
+        int read = stream.read();
+        while (read != -1) {
+            read = stream.read();
+            numBytes++;
+        }
+        assertEquals(38000, numBytes);
+        rs.close();
+        assertEquals(0, countLocks());
+        commit();
+    }
+
+    /**
+     * Test that ResultSet.getString() does not hold locks after the ResultSet
+     * is closed
+     * 
+     * @throws SQLException
+     * @throws IOException
+     */
+    public void testGetString() throws SQLException, IOException {
+        // getString() no locks expected after retrieval
+        Statement stmt = createStatement();
+        String sql = "SELECT bc from t1";
+        ResultSet rs = stmt.executeQuery(sql);
+        rs.next();
+        String value = rs.getString(1);
+        assertEquals(38000, value.length());
+        rs.close();
+        assertEquals(0, countLocks());
+        commit();
+    }
+
+    /**
+     * Create a new connection and count the number of locks held.
+     * 
+     * @return number of locks held
+     * 
+     * @throws SQLException
+     */
+    public int countLocks() throws SQLException {
+        Connection conn = openDefaultConnection();
+        String sql;
+        Statement stmt = conn.createStatement();
+
+        sql = "Select count(*) from new org.apache.derby.diag.LockTable() as LT";
+        ResultSet lockrs = stmt.executeQuery(sql);
+        lockrs.next();
+        int count = lockrs.getInt(1);
+        lockrs.close();
+        stmt.close();
+        conn.close();
+        return count;
+    }
 
-    
-	public static Test baseSuite(String name) {
+    public static Test baseSuite(String name) {
 
         TestSuite suite = new TestSuite(name);
         suite.addTestSuite(LargeDataLocksTest.class);
@@ -179,26 +170,25 @@
              * @see org.apache.derbyTesting.junit.CleanDatabaseTestSetup#decorateSQL(java.sql.Statement)
              */
             protected void decorateSQL(Statement s) throws SQLException {
-            	Connection conn = getConnection();
-    			conn.setAutoCommit(false);
-    	   		PreparedStatement ps = null;
-    			String sql;
-    			
-    			
-    			sql = "CREATE TABLE t1 (bc CLOB(1M), bincol BLOB(1M), datalen int)";
-    			s.executeUpdate(sql);
-    			
-    			// Insert big and little values
-    			sql = "INSERT into t1 values(?,?,?)";		
-    			ps = conn.prepareStatement(sql);
-
-    			ps.setCharacterStream(1, new
-    				java.io.StringReader(Utilities.repeatChar("a",38000)),38000);
-    			ps.setBytes(2,Utilities.repeatChar("a",38000).getBytes());
-    			ps.setInt(3,38000);
-    			ps.executeUpdate();
-    			ps.close();
-    			conn.commit();
+                Connection conn = getConnection();
+                conn.setAutoCommit(false);
+                PreparedStatement ps = null;
+                String sql;
+
+                sql = "CREATE TABLE t1 (bc CLOB(1M), bincol BLOB(1M), datalen int)";
+                s.executeUpdate(sql);
+
+                // Insert big and little values
+                sql = "INSERT into t1 values(?,?,?)";
+                ps = conn.prepareStatement(sql);
+
+                ps.setCharacterStream(1, new java.io.StringReader(Utilities
+                        .repeatChar("a", 38000)), 38000);
+                ps.setBytes(2, Utilities.repeatChar("a", 38000).getBytes());
+                ps.setInt(3, 38000);
+                ps.executeUpdate();
+                ps.close();
+                conn.commit();
             }
         };
     }
@@ -206,10 +196,10 @@
     public static Test suite() {
         TestSuite suite = new TestSuite("LargeDataLocksTest");
         suite.addTest(baseSuite("LargeDataLocksTest:embedded"));
-        suite.addTest(TestConfiguration.clientServerDecorator(baseSuite("LargeDataLocksTest:client")));
+        // Disable for client until DERBY-2892 is fixed
+        //suite.addTest(TestConfiguration.clientServerDecorator(baseSuite("LargeDataLocksTest:client")));
         return suite;
 
     }
 
 }
-    

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java?view=diff&rev=557033&r1=557032&r2=557033
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
Tue Jul 17 12:23:40 2007
@@ -78,6 +78,7 @@
         suite.addTest(ClobTest.suite());
         suite.addTest(BlobUpdatableStreamTest.suite());
         suite.addTest(AIjdbcTest.suite());
+        suite.addTest(LargeDataLocksTest.suite());
 
         // Old harness .java tests that run using the HarnessJavaTest
         // adapter and continue to use a single master file.

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/Utilities.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/Utilities.java?view=diff&rev=557033&r1=557032&r2=557033
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/Utilities.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/junit/Utilities.java
Tue Jul 17 12:23:40 2007
@@ -81,6 +81,27 @@
                 return str.toString() +"'";
         }
 
+    	/**
+    	 * repeatChar is used to create strings of varying lengths.
+    	 * called from various tests to test edge cases and such.
+    	 *
+    	 * @param c             character to repeat
+    	 * @param repeatCount   Number of times to repeat character
+    	 * @return              String of repeatCount characters c
+    	 */
+       public static String repeatChar(String c, int repeatCount)
+       {
+    	   char ch = c.charAt(0);
+
+    	   char[] chArray = new char[repeatCount];
+    	   for (int i = 0; i < repeatCount; i++)
+    	   {
+    		   chArray[i] = ch;
+    	   }
+
+    	   return new String(chArray);
+
+       }
 
         /**
          * Print out resultSet in two dimensional array format, for use by



Mime
View raw message