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

org.tinygroup.tinydb.spring.SqlParamValuesBatchStatementSetterImpl Maven / Gradle / Ivy

The newest version!
/**
 *  Copyright (c) 1997-2013, www.tinygroup.org ([email protected]).
 *
 *  Licensed under the GPL, Version 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.gnu.org/licenses/gpl.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.tinygroup.tinydb.spring;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.SqlParameterValue;
import org.springframework.jdbc.core.StatementCreatorUtils;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

/**
 * 
 * 功能说明: SqlParamValues参数形式批处理
 * 

* 开发人员: renhui
* 开发时间: 2013-11-6
*
*/ public class SqlParamValuesBatchStatementSetterImpl implements BatchPreparedStatementSetter { private List params; public SqlParamValuesBatchStatementSetterImpl( List params) { this.params = params; } public List getParams() { return params; } public void setParams(List params) { this.params = params; } public void setValues(PreparedStatement ps, int i) throws SQLException { SqlParameterValue[] sqlParams = params.get(i); doSetStatementParameters(sqlParams, ps); } public int getBatchSize() { return params.size(); } private void doSetStatementParameters(SqlParameterValue[] values, PreparedStatement ps) throws SQLException { int colIndex = 0; for (SqlParameterValue paramValue : values) { colIndex++; StatementCreatorUtils.setParameterValue(ps, colIndex, paramValue, paramValue.getValue()); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy