Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 29449 invoked from network); 27 Jul 2006 03:38:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Jul 2006 03:38:14 -0000 Received: (qmail 61785 invoked by uid 500); 27 Jul 2006 03:38:13 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 61763 invoked by uid 500); 27 Jul 2006 03:38:13 -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 61752 invoked by uid 99); 27 Jul 2006 03:38:13 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Jul 2006 20:38:13 -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; Wed, 26 Jul 2006 20:38:12 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 8BB281A981A; Wed, 26 Jul 2006 20:37:52 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r425941 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang: PrepareExecuteDDL.java build.xml Date: Thu, 27 Jul 2006 03:37:52 -0000 To: derby-commits@db.apache.org From: djd@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060727033752.8BB281A981A@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: djd Date: Wed Jul 26 20:37:51 2006 New Revision: 425941 URL: http://svn.apache.org/viewvc?rev=425941&view=rev Log: Add a PrepareExecuteDDL JUnit test with initial cases that tests preparing statements and then executing DDL before executing the prepared statement. Add support to compile Junit tests in the functionTests/lang package. Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrepareExecuteDDL.java (with props) Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrepareExecuteDDL.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrepareExecuteDDL.java?rev=425941&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrepareExecuteDDL.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrepareExecuteDDL.java Wed Jul 26 20:37:51 2006 @@ -0,0 +1,150 @@ +package org.apache.derbyTesting.functionTests.tests.lang; + +import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase; +import org.apache.derbyTesting.functionTests.util.JDBC; + +import java.sql.*; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test the dependency system for active statements when + * a DDL is executed in a separate connection after the + * prepare but before the execute. + * + */ +public class PrepareExecuteDDL extends BaseJDBCTestCase { + + private Connection conn; + private Connection connDDL; + + /** + * List of statements that are prepared and then executed. + * The testPrepareExecute method prepares each statement + * in this list, executes one DDL, executes each prepared + * statement and then checks the result. + *
+ * The result checking is driven off the initial text + * of the statement. + */ + private static final String[] STMTS = + { + "SELECT * FROM PED001", + "SELECT A, B FROM PED001", + }; + + /** + * All the DDL commands that will be executed, one per + * fixture, as the mutation between the prepare and execute. + */ + private static final String[] DDL = + { + "ALTER TABLE PED001 ADD COLUMN D BIGINT", + "ALTER TABLE PED001 ADD CONSTRAINT PED001_PK PRIMARY KEY (A)", + "ALTER TABLE PED001 LOCKSIZE ROW", + "ALTER TABLE PED001 LOCKSIZE TABLE", + "DROP TABLE PED001", + }; + + /** + * Create a suite of tests, one per statement in DDL. + */ + public static Test suite() { + TestSuite suite = new TestSuite(); + for (int i = 0; i < DDL.length; i++) + suite.addTest(new PrepareExecuteDDL("testPrepareExcute", DDL[i])); + return suite; + } + private final String ddl; + + private PrepareExecuteDDL(String name, String ddl) + { + super(name); + this.ddl = ddl; + } + + public void testPrepareExcute() throws SQLException + { + PreparedStatement[] psa= new PreparedStatement[STMTS.length]; + for (int i = 0; i < STMTS.length; i++) + { + String sql = STMTS[i]; + psa[i] = conn.prepareStatement(sql); + } + + connDDL.createStatement().execute(ddl); + + for (int i = 0; i < STMTS.length; i++) + { + String sql = STMTS[i]; + if (sql.startsWith("SELECT ")) + checkSelect(psa[i], sql); + } + } + + private void checkSelect(PreparedStatement ps, String sql) + throws SQLException + { + assertEquals(true, sql.startsWith("SELECT ")); + + boolean result; + try { + result = ps.execute(); + } catch (SQLException e) { + + //TODO: Use DMD to see if table exists or not. + assertSQLState("42X05", e); + + return; + } + assertTrue(result); + + ResultSet rs = ps.getResultSet(); + + DatabaseMetaData dmd = connDDL.getMetaData(); + JDBC.assertMetaDataMatch(dmd, rs.getMetaData()); + + boolean isSelectStar = sql.startsWith("SELECT * "); + + if (isSelectStar) + ; + + JDBC.assertDrainResults(rs); + } + + /** + * Set the fixture up with a clean, standard table PED001. + */ + protected void setUp() throws SQLException + { + + connDDL = getConnection(); + Statement s = connDDL.createStatement(); + + s.execute( + "CREATE TABLE PED001 (A INT NOT NULL, B DECIMAL(6,4), C VARCHAR(20))"); + + s.close(); + + conn = getConnection(); + } + + /** + * Tear-down the fixture by removing the table (if it still + * exists). + */ + protected void tearDown() throws SQLException + { + Statement s = conn.createStatement(); + try { + s.execute("DROP TABLE PED001"); + } catch (SQLException e) { + assertSQLState("42Y55", e); + } + s.close(); + JDBC.cleanup(conn); + JDBC.cleanup(connDDL); + + } +} \ No newline at end of file Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrepareExecuteDDL.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml?rev=425941&r1=425940&r2=425941&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml Wed Jul 26 20:37:51 2006 @@ -66,6 +66,7 @@ +