Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 78224 invoked from network); 15 Aug 2007 18:53:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Aug 2007 18:53:18 -0000 Received: (qmail 61992 invoked by uid 500); 15 Aug 2007 18:53:16 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 61960 invoked by uid 500); 15 Aug 2007 18:53:16 -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 61949 invoked by uid 99); 15 Aug 2007 18:53:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Aug 2007 11:53:16 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Aug 2007 18:53:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 74E331A981C; Wed, 15 Aug 2007 11:52:57 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r566300 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/ suites/ tests/lang/ Date: Wed, 15 Aug 2007 18:52:57 -0000 To: derby-commits@db.apache.org From: kmarsden@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070815185257.74E331A981C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kmarsden Date: Wed Aug 15 11:52:56 2007 New Revision: 566300 URL: http://svn.apache.org/viewvc?view=rev&rev=566300 Log: DERBY-2995 convert lang/renameIndex.sql to JUnit Contributed by Ravinder Reddy Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameIndexTest.java (with props) Removed: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/renameIndex.out db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/renameIndex.sql db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/renameIndex_derby.properties Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall?view=diff&rev=566300&r1=566299&r2=566300 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall Wed Aug 15 11:52:56 2007 @@ -46,7 +46,6 @@ lang/refActions.sql lang/refActions2.sql lang/refActions3.sql -lang/renameIndex.sql lang/reopenScan.sql lang/setOpPlan.sql lang/specjPlans.sql Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameIndexTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameIndexTest.java?view=auto&rev=566300 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameIndexTest.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameIndexTest.java Wed Aug 15 11:52:56 2007 @@ -0,0 +1,211 @@ +/* + + Derby - Class org.apache.derbyTesting.functionTests.tests.lang.RenameIndexTest + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package org.apache.derbyTesting.functionTests.tests.lang; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import junit.framework.Test; + +import org.apache.derbyTesting.junit.BaseJDBCTestCase; +import org.apache.derbyTesting.junit.JDBC; +import org.apache.derbyTesting.junit.TestConfiguration; + +public class RenameIndexTest extends BaseJDBCTestCase +{ + public RenameIndexTest(String name) { + super(name); + } + public static Test suite() { + + return TestConfiguration.embeddedSuite(RenameIndexTest.class); + } + protected void setUp() throws Exception { + super.setUp(); + getConnection().setAutoCommit(false); + } + protected void tearDown() throws Exception { + super.tearDown(); + } +/** + * Test that We cannot Rename a non-existing Index. + * + * @exception SQLException + */ +public void testRenameNonExistingIndex() throws SQLException { + Statement s = createStatement(); + assertStatementError("42X65" , s , "rename index i1t1 to i1rt1"); +} +/** + * Test that We cannot Rename an Index With an existing Index name. + * + * @exception SQLException + */ +public void testExistingIndexName() throws SQLException { + Statement s = createStatement(); + s.executeUpdate("create table t1(c11 int, c12 int)"); + s.executeUpdate("create index i1t1 on t1(c11)"); + s.executeUpdate("create index i2t1 on t1(c12)"); + assertStatementError("X0Y32" , s , "rename index i1t1 to i2t1"); + s.executeUpdate("drop table t1"); +} +/** + * Test that We cannot Rename a System Table's Index + * + * @exception SQLException + */ +//-- rename a system table's index +public void testRenameSystemTableIndex() throws SQLException { + Statement s = createStatement(); + s.executeUpdate("set schema sys"); + // will fail because it is a system table + assertStatementError("X0Y56" , s , "rename index syscolumns_index1 to newName"); + s.executeUpdate("set schema app"); +} +/** + * Test to RENAME an INDEX when view is on a table. + * + * @exception SQLException + */ +public void testRenameIndexOfView() throws SQLException { + Statement s = createStatement(); + s.executeUpdate("create table t1(c11 int, c12 int)"); + s.executeUpdate("create index t1i1 on t1(c11)"); + s.executeUpdate("create view v1 as select * from t1"); + ResultSet rs = s.executeQuery("select count(*) from v1"); + JDBC.assertSingleValueResultSet(rs , "0"); + //-- this succeeds with no exceptions + assertUpdateCount(s , 0 , "rename index t1i1 to t1i1r"); + rs = s.executeQuery("select count(*) from v1"); + JDBC.assertSingleValueResultSet(rs , "0"); + s.executeUpdate("drop view v1"); + s.executeUpdate("drop table t1"); +} +/** + * Test RENAME INDEX when there is a duplicate INDEX + * + * @exception SQLException + */ +public void testDuplicateIndexWithViews() throws SQLException +{ + //-- another test for views + Statement s = createStatement(); + s.executeUpdate("create table t1(c11 int not null primary key, c12 int)"); + s.executeUpdate("create index i1t1 on t1(c11)"); + s.executeUpdate("create view v1 as select * from t1"); + + assertStatementError("42X65" , s , "rename index i1t1 to i1rt1"); + assertUpdateCount(s , 0 , "drop view v1"); + //-- even though there is no index i1t1 it still doesn't fail + assertUpdateCount(s , 0 , "create view v1 as select * from t1"); + //-- this succeeds with no exceptions + ResultSet rs = s.executeQuery("select count(*) from v1"); + JDBC.assertSingleValueResultSet(rs , "0"); + assertStatementError("42X65" , s , "rename index i1rt1 to i1t1"); + s.executeUpdate("drop view v1"); + s.executeUpdate("drop table t1"); +} +/* + * -- cannot rename an index when there is an open cursor on it + * + * @exception SQLException + */ +public void testRenameIndexWithOpenCursor() throws SQLException { + Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY , ResultSet.CONCUR_UPDATABLE); + s.executeUpdate("create table t1(c11 int , c12 int)"); + s.executeUpdate("create index i1 on t1(c11)"); + s.executeUpdate("insert into t1 values(2 , 3)"); + s.executeUpdate("insert into t1 values(3 , 4)"); + ResultSet rs = s.executeQuery("select * from t1"); + rs.next(); + assertStatementError("X0X95" , createStatement() , "rename index i1 to i1r"); + rs.close(); + //-- following rename should pass because cursor c1 has been closed + assertUpdateCount(s , 0 , "rename index i1 to i1r"); + s.executeUpdate("drop table t1"); +} +/** + * Test RENAME INDEX With Prepared Statement. + * + * @exception SQLException + */ +//-- creating a prepared statement on a table +public void testWithPreparedStatement() throws SQLException { + Statement s = createStatement(); + s.executeUpdate("create table t1(c11 int not null primary key, c12 int)"); + //-- bug 5685 + s.executeUpdate("create index i1 on t1(c11)"); + PreparedStatement pstmt = prepareStatement("select * from t1 where c11 > ?"); + pstmt.setInt(1 , 1); + ResultSet rs = pstmt.executeQuery(); + rs.next(); + rs.close(); + assertStatementError("42X65" , s , "rename index i1 to i1r"); + //-- statement passes + pstmt.setInt(1 , 1); + rs = pstmt.executeQuery(); + rs.next(); + rs.close(); + pstmt.close(); + s.executeUpdate("drop table t1"); +} +/** + * column with an index on it can be renamed + * + * @exception SQLException + */ +public void testRenameColumnWithIndex() throws SQLException { + Statement s = createStatement(); + s.executeUpdate("create table t3(c31 int not null primary key, c32 int)"); + s.executeUpdate("create index i1_t3 on t3(c32)"); + s.executeUpdate("rename index i1_t3 to i1_3r"); + //-- make sure that i1_t3 did get renamed. Following rename should fail, to prove that. + assertStatementError("42X65" , s , "rename index i1_t3 to i1_3r"); + s.executeUpdate("drop table t3"); +} +/** + * Test the another feature with PreparedStatement. + * + * @exception SQLException + */ +//-- creating a prepared statement on a table +public void testDuplicateIndexWithPreparedStatement() throws SQLException { + Statement s = createStatement(); + s.executeUpdate("create table t3(c31 int not null primary key, c32 int)"); + s.executeUpdate("create index i1_t3 on t3(c32)"); + PreparedStatement pstmt = prepareStatement("select * from t3 where c31 > ?"); + pstmt.setInt(1 , 1); + ResultSet rs = pstmt.executeQuery(); + rs.close(); + //-- can rename with no errors + assertUpdateCount(s , 0 , "rename index i1_t3 to i1_t3r"); + //execute p3 using 'values (1)'; + pstmt.setInt(1 , 1); + rs = pstmt.executeQuery(); + rs.close(); + assertUpdateCount(s , 0 , "rename index i1_t3r to i1_t3"); + pstmt.close(); + s.executeUpdate("drop table t3"); + } +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameIndexTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?view=diff&rev=566300&r1=566299&r2=566300 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Wed Aug 15 11:52:56 2007 @@ -115,6 +115,7 @@ suite.addTest(DeclareGlobalTempTableJavaTest.suite()); suite.addTest(PrimaryKeyTest.suite()); suite.addTest(RenameTableTest.suite()); + suite.addTest(RenameIndexTest.suite()); // Add the XML tests, which exist as a separate suite // so that users can "run all XML tests" easily.