View Javadoc
1   /*
2    *    Copyright 2016-2025 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.mybatis.dynamic.sql.util.mybatis3;
17  
18  import java.util.List;
19  
20  import org.apache.ibatis.annotations.Flush;
21  import org.apache.ibatis.annotations.InsertProvider;
22  import org.apache.ibatis.executor.BatchResult;
23  import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
24  import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
25  import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
26  
27  /**
28   * This is a general purpose mapper for executing various types of insert statements. This mapper is appropriate for
29   * insert statements that do NOT expect generated keys.
30   *
31   * @param <T>
32   *            the type of row associated with this mapper
33   */
34  public interface CommonInsertMapper<T> extends CommonGeneralInsertMapper {
35      /**
36       * Execute an insert statement with input fields mapped to values in a POJO.
37       *
38       * @param insertStatement
39       *            the insert statement
40       *
41       * @return the number of rows affected
42       */
43      @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
44      int insert(InsertStatementProvider<T> insertStatement);
45  
46      /**
47       * Execute an insert statement that inserts multiple rows. The row values are supplied by mapping to values in a
48       * List of POJOs.
49       *
50       * @param insertStatement
51       *            the insert statement
52       *
53       * @return the number of rows affected
54       */
55      @InsertProvider(type = SqlProviderAdapter.class, method = "insertMultiple")
56      int insertMultiple(MultiRowInsertStatementProvider<T> insertStatement);
57  
58      /**
59       * Flush batched insert statements and return details of the current batch. This is useful when there is no direct
60       * access to the @link({@link org.apache.ibatis.session.SqlSession}.
61       *
62       * @return details about the current batch including update counts, etc.
63       */
64      @Flush
65      List<BatchResult> flush();
66  }