1 24 25 package org.objectweb.cjdbc.scenario.raidb1.driver; 26 27 import java.sql.Connection ; 28 import java.sql.PreparedStatement ; 29 import java.sql.ResultSet ; 30 import java.util.ArrayList ; 31 import java.util.HashMap ; 32 33 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet; 34 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread; 35 import org.objectweb.cjdbc.scenario.templates.Raidb1Template; 36 import org.objectweb.cjdbc.scenario.tools.util.PrivilegedAccessor; 37 38 44 public class SetFetchSizeScenario extends Raidb1Template 45 { 46 47 54 public void testFetchSize() throws Exception 55 { 56 final int fetchsize = 5; 57 Connection con = getCJDBCConnection(); 58 con.setAutoCommit(false); 59 String sql = "Select * from ADDRESS,DOCUMENT,PRODUCT"; 60 PreparedStatement ps = con.prepareStatement(sql); 61 ps.setFetchSize(fetchsize); 62 ResultSet rs = ps.executeQuery(); 63 ArrayList activeThreads = mainVdb.getActiveThreads(); 64 VirtualDatabaseWorkerThread vt = (VirtualDatabaseWorkerThread) activeThreads 65 .get(0); 66 HashMap streamedResultSet = (HashMap ) PrivilegedAccessor.getValue(vt, 67 "streamedResultSet"); 68 String key = (String ) streamedResultSet.keySet().iterator().next(); 69 ControllerResultSet resultSet = (ControllerResultSet) streamedResultSet 70 .get(key); 71 72 int count = 0; 73 ArrayList data = new ArrayList (); 74 while (rs.next()) 75 { 76 if ((count++) % fetchsize == 0) 78 assertNotSame(data, resultSet.getData()); 79 data = resultSet.getData(); 80 if (count > 10000) 81 break; 82 } 83 assertEquals("Invalid fetch size from resultset", fetchsize, rs 84 .getFetchSize()); 85 } 86 } | Popular Tags |