1 24 25 package org.objectweb.cjdbc.scenario.tools.testlet; 26 27 import java.sql.Connection ; 28 import java.sql.ResultSet ; 29 30 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 31 32 39 public class UpdateTestLet extends AbstractConnectionTestLet 40 { 41 42 private int totalExecute; 43 44 49 public UpdateTestLet(Connection con) 50 { 51 super(con); 52 config.put(TABLE_NAME, "PRODUCT"); 53 config.put(COLUMN_NAME, "NAME"); 54 config.put(UPDATED_COLUMN_VALUE, "horizontalTest"); 55 config.put(SELECTED_COLUMNS, "*"); 56 config.put(USE_PREPARED_STATEMENT, "false"); 57 config.put(USE_TRANSACTIONS,"false"); 58 } 59 60 63 public void execute() throws Exception 64 { 65 String selectQuery = "Select " + config.get(SELECTED_COLUMNS) + " from " 66 + config.get(TABLE_NAME); 67 String updateQuery = "update " + config.get(TABLE_NAME) + " set " 68 + config.get(COLUMN_NAME) + "='" + config.get(UPDATED_COLUMN_VALUE)+(totalExecute++) 69 + "'"; 70 boolean usePrepared = Boolean.valueOf((String )config.get(USE_PREPARED_STATEMENT)).booleanValue(); 71 72 ResultSet rs1,rs2; 73 if(usePrepared) 74 { 75 if(useTransaction()) 76 jdbcConnection.setAutoCommit(false); 77 rs1 = jdbcConnection.prepareStatement(selectQuery).executeQuery(); 78 jdbcConnection.prepareStatement(updateQuery).executeUpdate(); 79 rs2 = jdbcConnection.prepareStatement(selectQuery).executeQuery(); 80 if(useTransaction()) 81 jdbcConnection.commit(); 82 } 83 else 84 { 85 if(useTransaction()) 86 jdbcConnection.setAutoCommit(false); 87 rs1 = jdbcConnection.createStatement().executeQuery(selectQuery); 88 jdbcConnection.createStatement().executeUpdate(updateQuery); 89 rs2 = jdbcConnection.createStatement().executeQuery(selectQuery); 90 if(useTransaction()) 91 jdbcConnection.commit(); 92 } 93 94 assertNotNull("ResultSet before update is null", rs1); 95 assertNotNull("ResultSet after update is null", rs2); 96 assertFalse(ScenarioUtility.checkEquals(rs1, rs2)); 97 } 98 } | Popular Tags |