1 package com.imcode.db.benchmark; 2 3 import java.sql.ResultSet; 4 import java.sql.SQLException; 5 6 import org.apache.commons.lang.time.StopWatch; 7 import com.imcode.db.jdbc.CountingResultSet; 8 9 public class BenchmarkResultSet extends CountingResultSet { 10 11 private BenchmarkDatabase benchmarkDatabase; 12 private final String sql; 13 private StopWatch stopWatch = new StopWatch(); 14 15 public BenchmarkResultSet(BenchmarkDatabase benchmarkDatabase, String sql, ResultSet resultSet) { 16 super(resultSet); 17 this.benchmarkDatabase = benchmarkDatabase ; 18 this.sql = sql; 19 } 20 21 public boolean next() throws SQLException { 22 if ( 0 == getRowCount() ) { 23 stopWatch.start() ; 24 } 25 boolean b = super.next(); 26 if ( !b ) { 27 stopWatch.stop(); 28 long time = stopWatch.getTime(); 29 benchmarkDatabase.getAverages(sql).getRowAverage().add(time, getRowCount()) ; 30 } 31 return b; 32 } 33 }