|
@@ -15,12 +15,10 @@
|
|
|
*/
|
|
|
package com.baomidou.mybatisplus.core.injector;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Assert;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Constants;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.*;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
|
import org.apache.ibatis.executor.keygen.KeyGenerator;
|
|
@@ -55,18 +53,31 @@ public abstract class AbstractMethod implements Constants {
|
|
|
protected Configuration configuration;
|
|
|
protected LanguageDriver languageDriver;
|
|
|
protected MapperBuilderAssistant builderAssistant;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 方法名称
|
|
|
- * @since 3.4.4
|
|
|
+ * @since 3.5.0
|
|
|
+ */
|
|
|
+ protected final String methodName;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see AbstractMethod#AbstractMethod(java.lang.String)
|
|
|
+ * @since 3.5.0
|
|
|
*/
|
|
|
- protected final String name;
|
|
|
-
|
|
|
- protected AbstractMethod(String name) {
|
|
|
- Assert.notNull(name,"方法名不能为空");
|
|
|
- this.name = name;
|
|
|
+ @Deprecated
|
|
|
+ public AbstractMethod() {
|
|
|
+ methodName = "";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param methodName 方法名
|
|
|
+ * @since 3.5.0
|
|
|
+ */
|
|
|
+ protected AbstractMethod(String methodName) {
|
|
|
+ Assert.notNull(methodName, "方法名不能为空");
|
|
|
+ this.methodName = methodName;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 注入自定义方法
|
|
|
*/
|
|
@@ -310,6 +321,14 @@ public abstract class AbstractMethod implements Constants {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询
|
|
|
+ * @since 3.5.0
|
|
|
+ */
|
|
|
+ protected MappedStatement addSelectMappedStatementForTable(Class<?> mapperClass, SqlSource sqlSource, TableInfo table) {
|
|
|
+ return addSelectMappedStatementForTable(mapperClass, this.methodName, sqlSource, table);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询
|
|
|
*/
|
|
@@ -319,6 +338,15 @@ public abstract class AbstractMethod implements Constants {
|
|
|
null, resultType, NoKeyGenerator.INSTANCE, null, null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询
|
|
|
+ *
|
|
|
+ * @since 3.5.0
|
|
|
+ */
|
|
|
+ protected MappedStatement addSelectMappedStatementForOther(Class<?> mapperClass, SqlSource sqlSource, Class<?> resultType) {
|
|
|
+ return addSelectMappedStatementForOther(mapperClass, this.methodName, sqlSource, resultType);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 插入
|
|
|
*/
|
|
@@ -329,6 +357,17 @@ public abstract class AbstractMethod implements Constants {
|
|
|
Integer.class, keyGenerator, keyProperty, keyColumn);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 插入
|
|
|
+ * @since 3.5.0
|
|
|
+ */
|
|
|
+ protected MappedStatement addInsertMappedStatement(Class<?> mapperClass, Class<?> parameterType,
|
|
|
+ SqlSource sqlSource, KeyGenerator keyGenerator,
|
|
|
+ String keyProperty, String keyColumn) {
|
|
|
+ return addInsertMappedStatement(mapperClass, parameterType, this.methodName, sqlSource, keyGenerator, keyProperty, keyColumn);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 删除
|
|
|
*/
|
|
@@ -337,6 +376,13 @@ public abstract class AbstractMethod implements Constants {
|
|
|
null, Integer.class, NoKeyGenerator.INSTANCE, null, null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @since 3.5.0
|
|
|
+ */
|
|
|
+ protected MappedStatement addDeleteMappedStatement(Class<?> mapperClass, SqlSource sqlSource) {
|
|
|
+ return addDeleteMappedStatement(mapperClass, this.methodName, sqlSource);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 更新
|
|
|
*/
|
|
@@ -346,6 +392,16 @@ public abstract class AbstractMethod implements Constants {
|
|
|
Integer.class, NoKeyGenerator.INSTANCE, null, null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新
|
|
|
+ *
|
|
|
+ * @since 3.5.0
|
|
|
+ */
|
|
|
+ protected MappedStatement addUpdateMappedStatement(Class<?> mapperClass, Class<?> parameterType,
|
|
|
+ SqlSource sqlSource) {
|
|
|
+ return addUpdateMappedStatement(mapperClass, parameterType, this.methodName, sqlSource);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 添加 MappedStatement 到 Mybatis 容器
|
|
|
*/
|
|
@@ -366,6 +422,16 @@ public abstract class AbstractMethod implements Constants {
|
|
|
configuration.getDatabaseId(), languageDriver, null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @since 3.5.0
|
|
|
+ */
|
|
|
+ protected MappedStatement addMappedStatement(Class<?> mapperClass, SqlSource sqlSource,
|
|
|
+ SqlCommandType sqlCommandType, Class<?> parameterType,
|
|
|
+ String resultMap, Class<?> resultType, KeyGenerator keyGenerator,
|
|
|
+ String keyProperty, String keyColumn) {
|
|
|
+ return addMappedStatement(mapperClass, this.methodName, sqlSource, sqlCommandType, parameterType, resultMap, resultType, keyGenerator, keyProperty, keyColumn);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 注入自定义 MappedStatement
|
|
|
*
|
|
@@ -375,5 +441,19 @@ public abstract class AbstractMethod implements Constants {
|
|
|
* @return MappedStatement
|
|
|
*/
|
|
|
public abstract MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo);
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取自定义方法名,未设置采用默认方法名
|
|
|
+ * https://gitee.com/baomidou/mybatis-plus/pulls/88
|
|
|
+ *
|
|
|
+ * @return method
|
|
|
+ * @author 义陆无忧
|
|
|
+ * @see AbstractMethod#AbstractMethod(java.lang.String)
|
|
|
+ * @deprecated 3.5.0
|
|
|
+ */
|
|
|
+ @Deprecated
|
|
|
+ public String getMethod(SqlMethod sqlMethod) {
|
|
|
+ return StringUtils.isBlank(methodName) ? sqlMethod.getMethod() : this.methodName;
|
|
|
+ }
|
|
|
+
|
|
|
}
|