/** * Create a new arg-type-based PreparedStatementSetter using the args and types passed in. * <p>By default, we'll create an {@link ArgumentTypePreparedStatementSetter}. * This method allows for the creation to be overridden by subclasses. * @param args object array with arguments * @param argTypes int array of SQLTypes for the associated arguments * @return the new PreparedStatementSetter to use */ protected PreparedStatementSetter newArgTypePreparedStatementSetter(Object[] args, int[] argTypes) { return new ArgumentTypePreparedStatementSetter(args, argTypes); }
@Override public void setValues(PreparedStatement ps) throws SQLException { int parameterPosition = 1; if (this.args != null && this.argTypes != null) { for (int i = 0; i < this.args.length; i++) { Object arg = this.args[i]; if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) { Collection<?> entries = (Collection<?>) arg; for (Object entry : entries) { if (entry instanceof Object[]) { Object[] valueArray = ((Object[]) entry); for (Object argValue : valueArray) { doSetValue(ps, parameterPosition, this.argTypes[i], argValue); parameterPosition++; } } else { doSetValue(ps, parameterPosition, this.argTypes[i], entry); parameterPosition++; } } } else { doSetValue(ps, parameterPosition, this.argTypes[i], arg); parameterPosition++; } } } }
/** * Configures a {@link PreparedStatementSetter} that will use the Object [] as the * values to be set on the query to be executed for this reader. The int[] will * provide the types ({@link java.sql.Types}) for each of the values provided. * * @param args values to set on the query * @param types the type for each value in the args array * @return this instance for method chaining */ public JdbcCursorItemReaderBuilder<T> queryArguments(Object[] args, int[] types) { this.preparedStatementSetter = new ArgumentTypePreparedStatementSetter(args, types); return this; }
@Override public void setValues(PreparedStatement ps) throws SQLException { int parameterPosition = 1; if (this.args != null && this.argTypes != null) { for (int i = 0; i < this.args.length; i++) { Object arg = this.args[i]; if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) { Collection<?> entries = (Collection<?>) arg; for (Object entry : entries) { if (entry instanceof Object[]) { Object[] valueArray = ((Object[]) entry); for (Object argValue : valueArray) { doSetValue(ps, parameterPosition, this.argTypes[i], argValue); parameterPosition++; } } else { doSetValue(ps, parameterPosition, this.argTypes[i], entry); parameterPosition++; } } } else { doSetValue(ps, parameterPosition, this.argTypes[i], arg); parameterPosition++; } } } }
/** * Create a new arg-type-based PreparedStatementSetter using the args and types passed in. * <p>By default, we'll create an {@link ArgumentTypePreparedStatementSetter}. * This method allows for the creation to be overridden by subclasses. * @param args object array with arguments * @param argTypes int array of SQLTypes for the associated arguments * @return the new PreparedStatementSetter to use */ protected PreparedStatementSetter newArgTypePreparedStatementSetter(Object[] args, int[] argTypes) { return new ArgumentTypePreparedStatementSetter(args, argTypes); }
/** * Configures a {@link PreparedStatementSetter} that will use the Object [] as the * values to be set on the query to be executed for this reader. The int[] will * provide the types ({@link java.sql.Types}) for each of the values provided. * * @param args values to set on the query * @param types the type for each value in the args array * @return this instance for method chaining */ public JdbcCursorItemReaderBuilder<T> queryArguments(Object[] args, int[] types) { this.preparedStatementSetter = new ArgumentTypePreparedStatementSetter(args, types); return this; }