001/* 002 * Copyright 2002-2018 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.namedparam; 018 019import java.sql.PreparedStatement; 020import java.sql.SQLException; 021 022import org.springframework.jdbc.core.BatchPreparedStatementSetter; 023import org.springframework.jdbc.core.JdbcOperations; 024 025/** 026 * Generic utility methods for working with JDBC batch statements using named parameters. 027 * Mainly for internal use within the framework. 028 * 029 * @author Thomas Risberg 030 * @author Juergen Hoeller 031 * @since 3.0 032 * @deprecated as of 5.1.3, not used by {@link NamedParameterJdbcTemplate} anymore 033 */ 034@Deprecated 035public abstract class NamedParameterBatchUpdateUtils extends org.springframework.jdbc.core.BatchUpdateUtils { 036 037 public static int[] executeBatchUpdateWithNamedParameters( 038 final ParsedSql parsedSql, final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) { 039 040 if (batchArgs.length == 0) { 041 return new int[0]; 042 } 043 044 String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]); 045 return jdbcOperations.batchUpdate( 046 sqlToUse, 047 new BatchPreparedStatementSetter() { 048 @Override 049 public void setValues(PreparedStatement ps, int i) throws SQLException { 050 Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null); 051 int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]); 052 setStatementParameters(values, ps, columnTypes); 053 } 054 @Override 055 public int getBatchSize() { 056 return batchArgs.length; 057 } 058 }); 059 } 060 061}