1 24 package org.objectweb.cjdbc.scenario.raidb1.driver; 25 26 import java.sql.Connection ; 27 import java.sql.ResultSet ; 28 import java.sql.Statement ; 29 import java.util.Hashtable ; 30 31 import org.objectweb.cjdbc.scenario.templates.Raidb1Template; 32 33 39 public class ReadWriteScenario extends Raidb1Template 40 { 41 42 46 public void testReadWrite() throws Exception 47 { 48 Connection con = getCJDBCConnection(); 49 Statement stmt = con.createStatement(); 50 String tableName = "test"+ System.currentTimeMillis(); 51 stmt.executeUpdate("create table "+tableName+" (id INTEGER)"); 52 stmt.executeUpdate("delete from "+tableName); 53 Hashtable ht = new Hashtable (); 54 for (int i = 1; i < 100; i++) 55 { 56 int counter = 1; 57 stmt.executeUpdate("insert into "+tableName+" (id) values (" + i + ")"); 58 while (counter < 50) 59 { 60 ResultSet rs = stmt.executeQuery("select max(id) as id from "+tableName); 61 rs.next(); 62 if (rs.getInt("id") != i) 63 fail( 64 "Read after write broken: id value (" 65 + rs.getInt("id") 66 + ") different from expected value (" 67 + i 68 + ")"); 69 rs.close(); 70 counter++; 71 } 72 Integer tot = (Integer ) ht.get(new Integer (counter)); 73 if (tot == null) 74 { 75 tot = new Integer (1); 76 ht.put(new Integer (counter), tot); 77 } 78 else 79 { 80 ht.put(new Integer (counter), new Integer (tot.intValue() + 1)); 81 } 82 } 83 con.createStatement().executeUpdate("drop table "+tableName); 84 con.close(); 85 } 86 87 } 88 | Popular Tags |