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
019/**
020 * Extension of the {@link BatchPreparedStatementSetter} interface,
021 * adding a batch exhaustion check.
022 *
023 * <p>This interface allows you to signal the end of a batch rather than
024 * having to determine the exact batch size upfront. Batch size is still
025 * being honored but it is now the maximum size of the batch.
026 *
027 * <p>The {@link #isBatchExhausted} method is called after each call to
028 * {@link #setValues} to determine whether there were some values added,
029 * or if the batch was determined to be complete and no additional values
030 * were provided during the last call to {@code setValues}.
031 *
032 * <p>Consider extending the
033 * {@link org.springframework.jdbc.core.support.AbstractInterruptibleBatchPreparedStatementSetter}
034 * base class instead of implementing this interface directly, using a single
035 * {@code setValuesIfAvailable} callback method that checks for available
036 * values and sets them, returning whether values have actually been provided.
037 *
038 * @author Thomas Risberg
039 * @author Juergen Hoeller
040 * @since 2.0
041 * @see JdbcTemplate#batchUpdate(String, BatchPreparedStatementSetter)
042 * @see org.springframework.jdbc.core.support.AbstractInterruptibleBatchPreparedStatementSetter
043 */
044public interface InterruptibleBatchPreparedStatementSetter extends BatchPreparedStatementSetter {
045
046        /**
047         * Return whether the batch is complete, that is, whether there were no
048         * additional values added during the last {@code setValues} call.
049         * <p><b>NOTE:</b> If this method returns {@code true}, any parameters
050         * that might have been set during the last {@code setValues} call will
051         * be ignored! Make sure that you set a corresponding internal flag if you
052         * detect exhaustion <i>at the beginning</i> of your {@code setValues}
053         * implementation, letting this method return {@code true} based on the flag.
054         * @param i index of the statement we're issuing in the batch, starting from 0
055         * @return whether the batch is already exhausted
056         * @see #setValues
057         * @see org.springframework.jdbc.core.support.AbstractInterruptibleBatchPreparedStatementSetter#setValuesIfAvailable
058         */
059        boolean isBatchExhausted(int i);
060
061}