Skip to content

Commit 7d3e833

Browse files
committed
Create a new insert mapper for general inserts
This mapper doesn't include the typed inserts, so it can easily be used without a class that matches a table row.
1 parent 599ca8a commit 7d3e833

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2016-2022 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 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.util.SqlProviderAdapter;
22+
23+
/**
24+
* This is a general purpose mapper for executing various non-typed insert statements (general inserts and insert
25+
* selects). This mapper is appropriate for insert statements that do NOT expect generated keys.
26+
*/
27+
public interface CommonGeneralInsertMapper {
28+
/**
29+
* Execute an insert statement with input fields supplied directly.
30+
*
31+
* @param insertStatement
32+
* the insert statement
33+
*
34+
* @return the number of rows affected
35+
*/
36+
@InsertProvider(type = SqlProviderAdapter.class, method = "generalInsert")
37+
int generalInsert(GeneralInsertStatementProvider insertStatement);
38+
39+
/**
40+
* Execute an insert statement with input fields supplied by a select statement.
41+
*
42+
* @param insertSelectStatement
43+
* the insert statement
44+
*
45+
* @return the number of rows affected
46+
*/
47+
@InsertProvider(type = SqlProviderAdapter.class, method = "insertSelect")
48+
int insertSelect(InsertSelectStatementProvider insertSelectStatement);
49+
}

src/main/java/org/mybatis/dynamic/sql/util/mybatis3/CommonInsertMapper.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import org.apache.ibatis.annotations.Flush;
2121
import org.apache.ibatis.annotations.InsertProvider;
2222
import org.apache.ibatis.executor.BatchResult;
23-
import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider;
24-
import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider;
2523
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
2624
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
2725
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
@@ -33,7 +31,7 @@
3331
* @param <T>
3432
* the type of record associated with this mapper
3533
*/
36-
public interface CommonInsertMapper<T> {
34+
public interface CommonInsertMapper<T> extends CommonGeneralInsertMapper {
3735
/**
3836
* Execute an insert statement with input fields mapped to values in a POJO.
3937
*
@@ -45,28 +43,6 @@ public interface CommonInsertMapper<T> {
4543
@InsertProvider(type = SqlProviderAdapter.class, method = "insert")
4644
int insert(InsertStatementProvider<T> insertStatement);
4745

48-
/**
49-
* Execute an insert statement with input fields supplied directly.
50-
*
51-
* @param insertStatement
52-
* the insert statement
53-
*
54-
* @return the number of rows affected
55-
*/
56-
@InsertProvider(type = SqlProviderAdapter.class, method = "generalInsert")
57-
int generalInsert(GeneralInsertStatementProvider insertStatement);
58-
59-
/**
60-
* Execute an insert statement with input fields supplied by a select statement.
61-
*
62-
* @param insertSelectStatement
63-
* the insert statement
64-
*
65-
* @return the number of rows affected
66-
*/
67-
@InsertProvider(type = SqlProviderAdapter.class, method = "insertSelect")
68-
int insertSelect(InsertSelectStatementProvider insertSelectStatement);
69-
7046
/**
7147
* Execute an insert statement that inserts multiple rows. The row values are supplied by mapping to values in a
7248
* List of POJOs.

0 commit comments

Comments
 (0)