List of usage examples for org.springframework.jdbc.core InterruptibleBatchPreparedStatementSetter getBatchSize
int getBatchSize();
From source file:com.github.ferstl.spring.jdbc.oracle.BatchingPreparedStatementCallbackTest.java
private void doInPreparedStatementWithIpss(int sendBatchSize, final int effectiveBatchSize, int pssBatchSize) throws SQLException { InterruptibleBatchPreparedStatementSetter ipss = mock(InterruptibleBatchPreparedStatementSetter.class); when(ipss.getBatchSize()).thenReturn(pssBatchSize); when(ipss.isBatchExhausted(anyInt())).thenAnswer(new Answer<Boolean>() { @Override/*from w w w . j av a2 s. c o m*/ public Boolean answer(InvocationOnMock invocation) throws Throwable { return effectiveBatchSize <= (int) invocation.getArguments()[0]; } }); BatchingPreparedStatementCallback psc = new BatchingPreparedStatementCallback(sendBatchSize, ipss); int[] result = psc.doInPreparedStatement(this.ops); int usedBatchSize = effectiveBatchSize < pssBatchSize ? effectiveBatchSize : pssBatchSize; assertThat(result, matchesRowCounts(sendBatchSize, usedBatchSize)); verifyPreparedStatementCalls(usedBatchSize, ipss); }
From source file:com.github.ferstl.spring.jdbc.oracle.BatchingPreparedStatementCallback.java
private void executeUpdate(OraclePreparedStatement ops, InterruptibleBatchPreparedStatementSetter ipss, List<Integer> rowCounts) throws SQLException { ops.setExecuteBatch(this.sendBatchSize); int i = 0;/*from www.j av a 2 s . co m*/ while (i < ipss.getBatchSize()) { ipss.setValues(ops, i); if (ipss.isBatchExhausted(i)) { break; } rowCounts.add(ops.executeUpdate()); i++; } if (i > 0 && i % this.sendBatchSize != 0) { rowCounts.set(rowCounts.size() - 1, ops.sendBatch()); } }