/** * 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; }
private static void bindNamed(ParsedParameters params, Binding binding, PreparedStatement statement, StatementContext context) { List<String> paramNames = params.getParameterNames(); // best effort: compare empty to non-empty because we can't list the individual binding names (unless we expose a method to do so) boolean argumentsProvidedButNoneDeclared = paramNames.isEmpty() && !binding.isEmpty(); if (argumentsProvidedButNoneDeclared && !context.getConfig(SqlStatements.class).isUnusedBindingAllowed()) { throw new UnableToCreateStatementException(String.format( "Superfluous named parameters provided while the query " + "declares none: '%s'. This check may be disabled by calling " + "getConfig(SqlStatements.class).setUnusedBindingAllowed(true) " + "or using @AllowUnusedBindings in SQL object.", binding), context); } for (int i = 0; i < paramNames.size(); i++) { final String name = paramNames.get(i); try { binding.findForName(name, context) .orElseThrow(() -> new UnableToCreateStatementException(String.format("Missing named parameter '%s'.", name), context)) .apply(i + 1, statement, context); } catch (SQLException e) { throw new UnableToCreateStatementException(String.format("Exception while binding named parameter '%s'", name), e, context); } } } }
private ExecutedBatch internalBatchExecute() { if (!getBinding().isEmpty()) { add();
private ExecutedBatch internalBatchExecute() { if (!getBinding().isEmpty()) { add();