|
| 1 | +/* |
| 2 | + * Copyright 2016-2020 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 | + * http://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 org.apache.ibatis.annotations.InsertProvider; |
| 19 | +import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider; |
| 20 | +import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider; |
| 21 | +import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider; |
| 22 | +import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider; |
| 23 | +import org.mybatis.dynamic.sql.util.SqlProviderAdapter; |
| 24 | + |
| 25 | +/** |
| 26 | + * This is a general purpose mapper for executing various types of insert statement. |
| 27 | + * |
| 28 | + * @param <T> the type of record associated with this mapper |
| 29 | + */ |
| 30 | +public interface CommonInsertMapper<T> { |
| 31 | + /** |
| 32 | + * Execute an insert statement with input fields mapped to values in a POJO. |
| 33 | + * |
| 34 | + * @param insertStatement the insert statement |
| 35 | + * @return the number of rows affected |
| 36 | + */ |
| 37 | + @InsertProvider(type = SqlProviderAdapter.class, method = "insert") |
| 38 | + int insert(InsertStatementProvider<T> insertStatement); |
| 39 | + |
| 40 | + /** |
| 41 | + * Execute an insert statement with input fields supplied directly. |
| 42 | + * |
| 43 | + * @param insertStatement the insert statement |
| 44 | + * @return the number of rows affected |
| 45 | + */ |
| 46 | + @InsertProvider(type = SqlProviderAdapter.class, method = "generalInsert") |
| 47 | + int generalInsert(GeneralInsertStatementProvider insertStatement); |
| 48 | + |
| 49 | + /** |
| 50 | + * Execute an insert statement with input fields supplied by a select statement. |
| 51 | + * |
| 52 | + * @param insertSelectStatement the insert statement |
| 53 | + * @return the number of rows affected |
| 54 | + */ |
| 55 | + @InsertProvider(type = SqlProviderAdapter.class, method = "insertSelect") |
| 56 | + int insertSelect(InsertSelectStatementProvider insertSelectStatement); |
| 57 | + |
| 58 | + /** |
| 59 | + * Execute an insert statement that inserts multiple rows. The row values are supplied by mapping |
| 60 | + * to values in a List of POJOs. |
| 61 | + * |
| 62 | + * @param insertStatement the insert statement |
| 63 | + * @return the number of rows affected |
| 64 | + */ |
| 65 | + @InsertProvider(type = SqlProviderAdapter.class, method = "insertMultiple") |
| 66 | + int insertMultiple(MultiRowInsertStatementProvider<T> insertStatement); |
| 67 | +} |
0 commit comments