public ResultIterator<Integer> executeAndGetModCount() { StatementContext ctx = getContext(); final int[] modCount = execute(); return new ResultIterator<Integer>() { int pos = 0; @Override public boolean hasNext() { return pos < modCount.length; } @Override public Integer next() { if (!hasNext()) { throw new NoSuchElementException(); } return modCount[pos++]; } @Override public StatementContext getContext() { return ctx; } @Override public void close() { ctx.close(); } }; }
/** * Add the current binding as a saved batch and clear the binding. * @return this */ public PreparedBatch add() { final Binding currentBinding = getBinding(); if (currentBinding.isEmpty()) { throw new IllegalStateException("Attempt to add() an empty batch, you probably didn't mean to do this " + "- call add() *after* setting batch parameters"); } bindings.add(currentBinding); getContext().setBinding(new Binding()); return this; }
/** * Executes the batch, returning the result obtained from the given {@link ResultProducer}. * * @param <R> the type of the result * @param producer the result producer. * @return value returned by the result producer. */ public <R> R execute(ResultProducer<R> producer) { try { return producer.produce(() -> internalBatchExecute().stmt, getContext()); } catch (SQLException e) { try { close(); } catch (Exception e1) { e.addSuppressed(e1); } throw new UnableToProduceResultException("Exception producing batch result", e, getContext()); } }
.render(getSql(), getContext()); getContext().setRenderedSql(renderedSql); .parse(renderedSql, getContext()); String sql = parsedSql.getSql(); ParsedParameters parsedParameters = parsedSql.getParameters(); getContext().setParsedSql(parsedSql); @SuppressWarnings("PMD.CloseResource") Connection connection = getHandle().getConnection(); stmt = statementBuilder.create(connection, sql, getContext()); throw new UnableToCreateStatementException(e, getContext()); getContext().setBinding(binding); ArgumentBinder.bind(parsedParameters, binding, stmt, getContext()); stmt.addBatch(); throw new UnableToExecuteStatementException("Exception while binding parameters", e, getContext()); final int[] rs = SqlLoggerUtil.wrap(stmt::executeBatch, getContext(), getConfig(SqlStatements.class).getSqlLogger()); getContext().setBinding(new Binding()); throw new UnableToExecuteStatementException(Batch.mungeBatchException(e), getContext());
} else { batchIntermediate = batch -> batch.executeAndReturnGeneratedKeys(columnNames) .mapTo(magic.elementType(batch.getContext())) .iterator();
public ResultIterator<Integer> executeAndGetModCount() { StatementContext ctx = getContext(); final int[] modCount = execute(); return new ResultIterator<Integer>() { int pos = 0; @Override public boolean hasNext() { return pos < modCount.length; } @Override public Integer next() { if (!hasNext()) { throw new NoSuchElementException(); } return modCount[pos++]; } @Override public StatementContext getContext() { return ctx; } @Override public void close() { } }; }
/** * Add the current binding as a saved batch and clear the binding. * @return this */ public PreparedBatch add() { bindings.add(getBinding()); getContext().setBinding(new Binding()); return this; }
/** * Executes the batch, returning the result obtained from the given {@link ResultProducer}. * * @param <R> the type of the result * @param producer the result producer. * @return value returned by the result producer. */ public <R> R execute(ResultProducer<R> producer) { try { return producer.produce(() -> internalBatchExecute().stmt, getContext()); } catch (SQLException e) { try { close(); } catch (Exception e1) { e.addSuppressed(e1); } throw new UnableToProduceResultException("Exception producing batch result", e, getContext()); } }
.render(getSql(), getContext()); getContext().setRenderedSql(renderedSql); .parse(renderedSql, getContext()); String sql = parsedSql.getSql(); ParsedParameters parsedParameters = parsedSql.getParameters(); getContext().setParsedSql(sql); StatementBuilder statementBuilder = getHandle().getStatementBuilder(); Connection connection = getHandle().getConnection(); stmt = statementBuilder.create(connection, sql, getContext()); addCleanable(() -> statementBuilder.close(connection, sql, stmt)); throw new UnableToCreateStatementException(e, getContext()); ArgumentBinder.bind(parsedParameters, binding, stmt, getContext()); stmt.addBatch(); throw new UnableToExecuteStatementException("Exception while binding parameters", e, getContext()); final long elapsedTime = System.nanoTime() - start; LOG.trace("Prepared batch of {} parts executed in {}ms", bindings.size(), elapsedTime / 1000000L, parsedSql); getConfig(SqlStatements.class).getTimingCollector().collect(elapsedTime, getContext()); throw new UnableToExecuteStatementException(Batch.mungeBatchException(e), getContext());