@Override public void logBeforeExecution(StatementContext context) { attributes.add(context.getAttributes()); context.getBinding().findForPosition(0).ifPresent(a -> bindings.add(a.toString())); }
@Override public void logException(StatementContext context, SQLException ex) { attributes.add(context.getAttributes()); context.getBinding().findForPosition(0).ifPresent(a -> bindings.add(a.toString())); }
@Override public void logAfterExecution(StatementContext context) { attributes.add(context.getAttributes()); context.getBinding().findForPosition(0).ifPresent(a -> bindings.add(a.toString())); }
private static void bindPositional(ParsedParameters params, Binding binding, PreparedStatement statement, StatementContext context) { // best effort: just try +1 (unless we expose a method to get the full binding count) boolean moreArgumentsProvidedThanDeclared = binding.findForPosition(params.getParameterCount()).isPresent(); if (moreArgumentsProvidedThanDeclared && !context.getConfig(SqlStatements.class).isUnusedBindingAllowed()) { throw new UnableToCreateStatementException("Superfluous positional param at (0 based) position " + params.getParameterCount(), context); } for (int i = 0; i < params.getParameterCount(); i++) { final int index = i; try { binding.findForPosition(i) .orElseThrow(() -> new UnableToCreateStatementException("Missing positional param at (0 based) position " + index, context)) .apply(i + 1, statement, context); } catch (SQLException e) { throw new UnableToCreateStatementException("Exception while binding positional param at (0 based) position " + i, e, context); } } }
@Override public void logBeforeExecution(StatementContext context) { context.getBinding().findForPosition(0).ifPresent(value -> positional = Objects.toString(value)); context.getBinding().findForName(NAME, context).ifPresent(value -> named = Objects.toString(value)); } });
private static void bindPositional(int size, Binding binding, PreparedStatement statement, StatementContext context) { for (int i = 0; i < size; i++) { try { Argument argument = binding.findForPosition(i).orElse(null); if (argument != null) { argument.apply(i + 1, statement, context); } // any missing positional parameters could be return parameters } catch (SQLException e) { throw new UnableToExecuteStatementException( "Exception while binding positional param at (0 based) position " + i, e, context); } } }