001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jdbc.core;
018
019import java.sql.PreparedStatement;
020import java.sql.SQLException;
021
022/**
023 * Batch update callback interface used by the {@link JdbcTemplate} class.
024 *
025 * <p>This interface sets values on a {@link java.sql.PreparedStatement} provided
026 * by the JdbcTemplate class, for each of a number of updates in a batch using the
027 * same SQL. Implementations are responsible for setting any necessary parameters.
028 * SQL with placeholders will already have been supplied.
029 *
030 * <p>Implementations <i>do not</i> need to concern themselves with SQLExceptions
031 * that may be thrown from operations they attempt. The JdbcTemplate class will
032 * catch and handle SQLExceptions appropriately.
033 *
034 * @author Rod Johnson
035 * @since March 2, 2003
036 * @see JdbcTemplate#batchUpdate(String, BatchPreparedStatementSetter)
037 * @see InterruptibleBatchPreparedStatementSetter
038 */
039public interface BatchPreparedStatementSetter {
040
041        /**
042         * Set parameter values on the given PreparedStatement.
043         * @param ps the PreparedStatement to invoke setter methods on
044         * @param i index of the statement we're issuing in the batch, starting from 0
045         * @throws SQLException if a SQLException is encountered
046         * (i.e. there is no need to catch SQLException)
047         */
048        void setValues(PreparedStatement ps, int i) throws SQLException;
049
050        /**
051         * Return the size of the batch.
052         * @return the number of statements in the batch
053         */
054        int getBatchSize();
055
056}