1 5 package org.h2.test.db; 6 7 import java.sql.Connection ; 8 import java.sql.ResultSet ; 9 import java.sql.Statement ; 10 11 import org.h2.test.TestBase; 12 13 public class TestSequence extends TestBase { 14 15 public void test() throws Exception { 16 deleteDb("sequence"); 17 Connection conn=getConnection("sequence"); 18 Statement stat = conn.createStatement(); 19 stat.execute("create sequence testseq"); 20 conn.setAutoCommit(false); 21 22 Connection conn2=getConnection("sequence"); 23 Statement stat2 = conn2.createStatement(); 24 conn2.setAutoCommit(false); 25 26 long last = 0; 27 for(int i=0; i<100; i++) { 28 long v1 = getNext(stat); 29 check(v1 > last); 30 last = v1; 31 for(int j=0; j<100; j++) { 32 long v2 = getNext(stat2); 33 check(v2 > last); 34 last = v2; 35 } 36 } 37 38 conn2.close(); 39 conn.close(); 40 } 41 42 private long getNext(Statement stat) throws Exception { 43 ResultSet rs = stat.executeQuery("call next value for testseq"); 44 rs.next(); 45 long value = rs.getLong(1); 46 return value; 47 } 48 } 49 | Popular Tags |