1 21 package org.dbunit.database.statement; 22 23 import org.dbunit.dataset.datatype.DataType; 24 import org.dbunit.dataset.datatype.TypeCastException; 25 26 import java.sql.SQLException ; 27 28 33 public class AutomaticPreparedBatchStatement implements IPreparedBatchStatement 34 { 35 private final IPreparedBatchStatement _statement; 36 private int _batchCount = 0; 37 private int _threshold; 38 private int _result = 0; 39 40 public AutomaticPreparedBatchStatement(IPreparedBatchStatement statement, int threshold) 41 { 42 _statement = statement; 43 _threshold = threshold; 44 } 45 46 49 public void addValue(Object value, DataType dataType) throws TypeCastException, 50 SQLException 51 { 52 _statement.addValue(value, dataType); 53 } 54 55 public void addBatch() throws SQLException 56 { 57 _statement.addBatch(); 58 _batchCount++; 59 60 if (_batchCount % _threshold == 0) 61 { 62 _result += _statement.executeBatch(); 63 } 64 } 65 66 public int executeBatch() throws SQLException 67 { 68 _result += _statement.executeBatch(); 69 return _result; 70 } 71 72 public void clearBatch() throws SQLException 73 { 74 _statement.clearBatch(); 75 _batchCount = 0; 76 } 77 78 public void close() throws SQLException 79 { 80 _statement.close(); 81 } 82 } 83 | Popular Tags |