1 20 package org.apache.derbyTesting.functionTests.tests.jdbcapi; 21 import org.apache.derbyTesting.functionTests.util.TestUtil; 22 import org.apache.derbyTesting.junit.BaseJDBCTestCase; 23 import org.apache.derbyTesting.junit.JDBC; 24 25 import junit.framework.*; 26 import java.sql.*; 27 28 36 public class URCoveringIndexTest extends BaseJDBCTestCase { 37 38 39 public URCoveringIndexTest(String name) { 40 super(name); 41 } 42 43 46 public void setUp() throws Exception { 47 Connection con = getConnection(); 48 con.setAutoCommit(false); 49 50 String createTableWithPK = "CREATE TABLE tableWithPK (" + 51 "c1 int primary key," + 52 "c2 int)"; 53 String insertData = "INSERT INTO tableWithPK values (1, 1)"; 54 Statement stmt = con.createStatement(); 55 stmt.execute(createTableWithPK); 56 57 stmt.execute(insertData); 58 59 stmt.close(); 60 } 61 62 private void testUpdateUpdatedTupleWithCoveringIndex( 63 boolean scroll, 64 boolean usePositionedUpdate) throws SQLException{ 65 66 SQLWarning w = null; 67 int resultsetType = scroll ? ResultSet.TYPE_SCROLL_INSENSITIVE : 68 ResultSet.TYPE_FORWARD_ONLY; 69 70 Connection con = getConnection(); 71 72 if (!(con.getMetaData().supportsResultSetConcurrency(resultsetType, 73 ResultSet.CONCUR_UPDATABLE))) { 74 return; 75 } 76 77 78 Statement updStmt = con.createStatement(resultsetType, 79 ResultSet.CONCUR_UPDATABLE); 80 Statement roStmt = con.createStatement(); 81 82 ResultSet rs = updStmt.executeQuery("SELECT c1 FROM tableWithPK"); 83 rs.next(); 84 int orig_c1 = rs.getInt(1); 85 roStmt.executeUpdate("UPDATE tableWithPK SET c1 = " + 86 (orig_c1 + 10) + "WHERE c1 = " + rs.getInt(1)); 87 rs.clearWarnings(); 88 if (usePositionedUpdate) { 89 roStmt.executeUpdate("UPDATE tableWithPK set c1 = " + 90 (orig_c1 + 20) + "WHERE CURRENT OF " + 91 rs.getCursorName()); 92 w = roStmt.getWarnings(); 93 } else { 94 rs.updateInt(1, (orig_c1 + 20)); 95 rs.updateRow(); 96 w = rs.getWarnings(); 97 } 98 assertTrue("Update should not produce any warnings ", w == null); 99 rs.close(); 100 101 rs = roStmt.executeQuery("SELECT c1 FROM tableWithPK"); 102 rs.next(); 103 assertEquals("Expecting c1 to be " + orig_c1 + " + 20", 104 rs.getInt(1), (orig_c1 + 20)); 105 rs.close(); 106 roStmt.close(); 107 updStmt.close(); 108 109 } 110 111 115 public void testUpdateUpdatedTupleScrollPostitioned() throws SQLException{ 116 testUpdateUpdatedTupleWithCoveringIndex(true, true); 117 } 118 119 123 public void testUpdateUpdatedTupleScrollUpdateRow() throws SQLException{ 124 testUpdateUpdatedTupleWithCoveringIndex(true, false); 125 } 126 127 131 public void testUpdateUpdatedTupleFOPositioned() throws SQLException{ 132 testUpdateUpdatedTupleWithCoveringIndex(false, true); 133 } 134 135 139 public void testUpdateUpdatedTupleFOUpdateRow() throws SQLException{ 140 testUpdateUpdatedTupleWithCoveringIndex(false, false); 141 } 142 } 143 | Popular Tags |