BatchResult.java

  1. /*
  2.  *    Copyright 2009-2023 the original author or authors.
  3.  *
  4.  *    Licensed under the Apache License, Version 2.0 (the "License");
  5.  *    you may not use this file except in compliance with the License.
  6.  *    You may obtain a copy of the License at
  7.  *
  8.  *       https://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  *    Unless required by applicable law or agreed to in writing, software
  11.  *    distributed under the License is distributed on an "AS IS" BASIS,
  12.  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  *    See the License for the specific language governing permissions and
  14.  *    limitations under the License.
  15.  */
  16. package org.apache.ibatis.executor;

  17. import java.util.ArrayList;
  18. import java.util.List;

  19. import org.apache.ibatis.mapping.MappedStatement;

  20. /**
  21.  * @author Jeff Butler
  22.  */
  23. public class BatchResult {

  24.   private final MappedStatement mappedStatement;
  25.   private final String sql;
  26.   private final List<Object> parameterObjects;

  27.   private int[] updateCounts;

  28.   public BatchResult(MappedStatement mappedStatement, String sql) {
  29.     this.mappedStatement = mappedStatement;
  30.     this.sql = sql;
  31.     this.parameterObjects = new ArrayList<>();
  32.   }

  33.   public BatchResult(MappedStatement mappedStatement, String sql, Object parameterObject) {
  34.     this(mappedStatement, sql);
  35.     addParameterObject(parameterObject);
  36.   }

  37.   public MappedStatement getMappedStatement() {
  38.     return mappedStatement;
  39.   }

  40.   public String getSql() {
  41.     return sql;
  42.   }

  43.   @Deprecated
  44.   public Object getParameterObject() {
  45.     return parameterObjects.get(0);
  46.   }

  47.   public List<Object> getParameterObjects() {
  48.     return parameterObjects;
  49.   }

  50.   public int[] getUpdateCounts() {
  51.     return updateCounts;
  52.   }

  53.   public void setUpdateCounts(int[] updateCounts) {
  54.     this.updateCounts = updateCounts;
  55.   }

  56.   public void addParameterObject(Object parameterObject) {
  57.     this.parameterObjects.add(parameterObject);
  58.   }

  59. }