Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 40408 invoked from network); 10 Jul 2006 11:42:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Jul 2006 11:42:19 -0000 Received: (qmail 24613 invoked by uid 500); 10 Jul 2006 11:42:18 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 24548 invoked by uid 500); 10 Jul 2006 11:42:18 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 24537 invoked by uid 99); 10 Jul 2006 11:42:18 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jul 2006 04:42:18 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jul 2006 04:42:16 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 21C601A981A; Mon, 10 Jul 2006 04:41:56 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r420497 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java Date: Mon, 10 Jul 2006 11:41:55 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060710114156.21C601A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: kahatlen Date: Mon Jul 10 04:41:55 2006 New Revision: 420497 URL: http://svn.apache.org/viewvc?rev=420497&view=rev Log: DERBY-1417: Add new, lengthless overloads to the streaming api 'derby-1417-2a-rstest-refactor.diff' refactors and rewrites parts of jdbc4/ResultSetTest.junit. A few utility methods have been introduced, and a TestSetup-class (anonymous) was used to create the table once. This was done because the previous implementation could cause other tests to fail if one test failed. The utility methods follow a pattern that will also be used by a number of tests written for the new lengthless overloads. Patch contributed by Kristian Waagan. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java?rev=420497&r1=420496&r2=420497&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java Mon Jul 10 04:41:55 2006 @@ -21,6 +21,7 @@ package org.apache.derbyTesting.functionTests.tests.jdbc4; import javax.xml.transform.Result; +import junit.extensions.TestSetup; import junit.framework.*; import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase; @@ -30,16 +31,38 @@ /** * Tests of JDBC4 features in ResultSet. + * + * Some utility methods have been introduced for the updateXXX test-methods. + * This test also makes use of a TestSetup wrapper to perform one-time + * setup and teardown for the whole suite. */ public class ResultSetTest extends BaseJDBCTestCase { + private static final byte[] BYTES1 = { + 0x65, 0x66, 0x67, 0x68, 0x69, + 0x69, 0x68, 0x67, 0x66, 0x65 + }; + + private static final byte[] BYTES2 = { + 0x69, 0x68, 0x67, 0x66, 0x65, + 0x65, 0x66, 0x67, 0x68, 0x69 + }; + + /** + * Key used to identify inserted rows. + * Use method requestKey to obtain it. + **/ + private static int insertKey = 0; + /** Default connection used by the tests. */ private Connection con = null; /** Statement used to obtain default resultset. */ private Statement stmt = null; /** Default resultset used by the tests. */ private ResultSet rs = null; + /** Default row identifier used by the tests. */ + private int key = -1; /** * Create test with given name. @@ -52,6 +75,7 @@ public void setUp() throws SQLException { + key = requestKey(); con = getConnection(); stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); @@ -262,23 +286,6 @@ public void testUpdateBinaryStream() throws Exception { - //create the table - stmt.execute("create table UpdateTestTable_ResultSet (sno int, " + - "datacol LONG VARCHAR FOR BIT DATA)"); - //Initial set of bytes used to create the Binary Stream that has to - //be inserted - byte[] bytes = new byte[] { - 0x65, 0x66, 0x67, 0x68, 0x69, - 0x69, 0x68, 0x67, 0x66, 0x65 - }; - - //Bytes that are used to create the BinaryStream that will be used in - //the updateAsciiStream method - byte[] bytes_for_update = new byte[] { - 0x69, 0x68, 0x67, 0x66, 0x65, - 0x65, 0x66, 0x67, 0x68, 0x69 - }; - //Byte array in which the returned bytes from //the Database after the update are stored. This //array is then checked to determine if it @@ -288,17 +295,16 @@ byte[] bytes_ret = new byte[10]; //Input Stream inserted initially - InputStream is = new java.io.ByteArrayInputStream(bytes); + InputStream is = new java.io.ByteArrayInputStream(BYTES1); //InputStream that is used for update InputStream is_for_update = new - java.io.ByteArrayInputStream(bytes_for_update); + java.io.ByteArrayInputStream(BYTES2); //Prepared Statement used to insert the data - PreparedStatement ps_sb = con.prepareStatement - ("insert into UpdateTestTable_ResultSet values(?,?)"); - ps_sb.setInt(1,1); - ps_sb.setBinaryStream(2,is,bytes.length); + PreparedStatement ps_sb = prep(con, "dLongBit"); + ps_sb.setInt(1,key); + ps_sb.setBinaryStream(2,is,BYTES1.length); ps_sb.executeUpdate(); ps_sb.close(); @@ -306,10 +312,9 @@ //use a different ResultSet variable so that the //other tests can go on unimpacted - ResultSet rs1 = stmt.executeQuery - ("select * from UpdateTestTable_ResultSet for update"); + ResultSet rs1 = fetchUpd(con, "dLongBit", key); rs1.next(); - rs1.updateBinaryStream(2,is_for_update,(int)bytes_for_update.length); + rs1.updateBinaryStream(1,is_for_update,(int)BYTES2.length); rs1.updateRow(); rs1.close(); @@ -317,20 +322,17 @@ //using the updateBinaryStream method is the same //data that we expected - rs1 = stmt.executeQuery - ("select * from UpdateTestTable_ResultSet"); + rs1 = fetch(con, "dLongBit", key); rs1.next(); - InputStream is_ret = rs1.getBinaryStream(2); + InputStream is_ret = rs1.getBinaryStream(1); is_ret.read(bytes_ret); is_ret.close(); - for(int i=0;iResultSet with zero or one row, depending on + * the key used + */ + private static ResultSet fetchUpd(Connection con, String colName, int key) + throws SQLException { + Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE); + return stmt.executeQuery("select " + colName + + " from UpdateTestTableResultSet where sno = " + key + + " for update"); + } + + /** + * Fetch the specified row. + * + * @param con connection to database + * @param colName name of the column to fetch + * @param key identifier for row to fetch + * @return a ResultSet with zero or one row, depending on + * the key used + */ + private static ResultSet fetch(Connection con, String colName, int key) + throws SQLException { + Statement stmt = con.createStatement(); + return stmt.executeQuery("select " + colName + + " from UpdateTestTableResultSet where sno = " + key); } }