1 5 package org.h2.test.synth; 6 7 import java.sql.Connection ; 8 import java.sql.PreparedStatement ; 9 import java.sql.ResultSet ; 10 import java.sql.SQLException ; 11 12 public class TestMultiNewsSimple extends TestMultiThread { 13 14 Connection conn; 15 16 static int newsCount = 10000; 17 static int getNewsCount() { 18 return newsCount; 19 } 20 21 TestMultiNewsSimple(TestMulti base) throws SQLException { 22 super(base); 23 conn = base.getConnection(); 24 } 25 26 void first() throws SQLException { 27 Connection conn = base.getConnection(); 28 conn.createStatement().execute("create table news(fid identity, fstate int default 0, text varchar default '')"); 29 PreparedStatement prep = conn.prepareStatement("insert into news() values()"); 30 for(int i=0; i<newsCount; i++) { 31 prep.executeUpdate(); 32 } 33 conn.createStatement().execute("update news set text = 'Text' || fid"); 34 conn.close(); 35 } 36 37 void begin() throws SQLException { 38 } 39 40 void end() throws SQLException { 41 conn.close(); 42 } 43 44 void operation() throws SQLException { 45 if(random.nextInt(10)==0) { 46 conn.setAutoCommit(random.nextBoolean()); 47 } else if(random.nextInt(10)==0) { 48 if(random.nextBoolean()) { 49 conn.commit(); 50 } else { 51 } 53 } else { 54 if(random.nextBoolean()) { 55 PreparedStatement prep = conn.prepareStatement("update news set fstate = ? where fid = ?"); 56 prep.setInt(1, random.nextInt(getNewsCount())); 57 prep.setInt(2, random.nextInt(10)); 58 prep.execute(); 59 } else { 60 PreparedStatement prep = conn.prepareStatement("select * from news where fid = ?"); 61 prep.setInt(1, random.nextInt(getNewsCount())); 62 ResultSet rs = prep.executeQuery(); 63 if(!rs.next()) { 64 System.out.println("No row found"); 65 } 67 if(rs.next()) { 68 System.out.println("Multiple rows found"); 69 } 71 } 72 } 73 } 74 75 void finalTest() throws SQLException { 76 78 } 79 80 } 81 | Popular Tags |