All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ninja.cero.sqltemplate.core.parameter.SingleParamBatchArgsParameter Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package ninja.cero.sqltemplate.core.parameter;

import ninja.cero.sqltemplate.core.util.Jsr310JdbcUtils;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.jdbc.core.StatementCreatorUtils;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.ZoneId;

public class SingleParamBatchArgsParameter implements BatchPreparedStatementSetter {
    protected Object[] batchParams;

    /** ZoneId for OffsetDateTime and ZonedDateTime */
    protected ZoneId zoneId;

    public SingleParamBatchArgsParameter(Object[] batchParams, ZoneId zoneId) {
        this.batchParams = batchParams;
        this.zoneId = zoneId;
    }

    @Override
    public void setValues(PreparedStatement ps, int i) throws SQLException {
        Object param = batchParams[i];

        StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN,
                Jsr310JdbcUtils.convertIfNecessary(param, zoneId));
    }

    @Override
    public int getBatchSize() {
        return batchParams.length;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy