com.transferwise.tasks.helpers.sql.ArgumentPreparedStatementSetter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tw-tasks-core Show documentation
Show all versions of tw-tasks-core Show documentation
Transferwise Tasks Executor - Fire and forget until Alert.
The newest version!
package com.transferwise.tasks.helpers.sql;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.temporal.TemporalAccessor;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.SqlParameterValue;
import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.jdbc.core.StatementCreatorUtils;
public class ArgumentPreparedStatementSetter implements PreparedStatementSetter {
private final Function uuidMapper;
private final Object[] args;
@SuppressFBWarnings("EI_EXPOSE_REP2")
public ArgumentPreparedStatementSetter(Function uuidMapper, Object[] args) {
this.uuidMapper = uuidMapper;
this.args = args;
}
@Override
@SuppressWarnings("unchecked")
public void setValues(PreparedStatement ps) throws SQLException {
int idx = 0;
for (Object arg : args) {
if (arg instanceof Object[]) {
Object[] subArgs = (Object[]) arg;
for (Object subArg : subArgs) {
doSetValue(ps, ++idx, subArg);
}
} else if (arg instanceof List) {
List