mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
Merge branch 'main' of https://github.com/mybatis-flex/mybatis-flex
This commit is contained in:
commit
531152e1d4
@ -42,7 +42,7 @@ public class GlobalConfig implements Serializable {
|
|||||||
|
|
||||||
private final FileType fileType;
|
private final FileType fileType;
|
||||||
|
|
||||||
// === 必须配置 ===
|
//region === 必须配置 ===
|
||||||
|
|
||||||
public GlobalConfig() {
|
public GlobalConfig() {
|
||||||
this(FileType.JAVA);
|
this(FileType.JAVA);
|
||||||
@ -52,8 +52,9 @@ public class GlobalConfig implements Serializable {
|
|||||||
private final PackageConfig packageConfig;
|
private final PackageConfig packageConfig;
|
||||||
private final StrategyConfig strategyConfig;
|
private final StrategyConfig strategyConfig;
|
||||||
private final TemplateConfig templateConfig;
|
private final TemplateConfig templateConfig;
|
||||||
|
//endregion === 必须配置 ===
|
||||||
|
|
||||||
// === 可选配置 ===
|
//region === 可选配置 ===
|
||||||
|
|
||||||
private EntityConfig entityConfig;
|
private EntityConfig entityConfig;
|
||||||
private MapperConfig mapperConfig;
|
private MapperConfig mapperConfig;
|
||||||
@ -62,11 +63,13 @@ public class GlobalConfig implements Serializable {
|
|||||||
private ControllerConfig controllerConfig;
|
private ControllerConfig controllerConfig;
|
||||||
private TableDefConfig tableDefConfig;
|
private TableDefConfig tableDefConfig;
|
||||||
private MapperXmlConfig mapperXmlConfig;
|
private MapperXmlConfig mapperXmlConfig;
|
||||||
|
//endregion === 可选配置 ===
|
||||||
|
|
||||||
// === 其他自定义配置 ===
|
//region === 其他自定义配置 ===
|
||||||
private Map<String, Object> customConfig = new HashMap<>();
|
private Map<String, Object> customConfig = new HashMap<>();
|
||||||
|
//endregion === 其他自定义配置 ===
|
||||||
|
|
||||||
// === 是否启用生成 ===
|
//region === 是否启用生成 ===
|
||||||
|
|
||||||
private boolean entityGenerateEnable;
|
private boolean entityGenerateEnable;
|
||||||
private boolean mapperGenerateEnable;
|
private boolean mapperGenerateEnable;
|
||||||
@ -122,8 +125,9 @@ public class GlobalConfig implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//endregion === 是否启用生成 ===
|
||||||
|
|
||||||
// === 分类配置 ===
|
//region === 分类配置 ===
|
||||||
|
|
||||||
public JavadocConfig getJavadocConfig() {
|
public JavadocConfig getJavadocConfig() {
|
||||||
return javadocConfig;
|
return javadocConfig;
|
||||||
@ -189,8 +193,9 @@ public class GlobalConfig implements Serializable {
|
|||||||
}
|
}
|
||||||
return mapperXmlConfig;
|
return mapperXmlConfig;
|
||||||
}
|
}
|
||||||
|
//endregion === 分类配置 ===
|
||||||
|
|
||||||
// === 启用配置 ===
|
//region === 启用配置 ===
|
||||||
|
|
||||||
public EntityConfig enableEntity() {
|
public EntityConfig enableEntity() {
|
||||||
entityGenerateEnable = true;
|
entityGenerateEnable = true;
|
||||||
@ -230,8 +235,9 @@ public class GlobalConfig implements Serializable {
|
|||||||
public void enablePackageInfo() {
|
public void enablePackageInfo() {
|
||||||
packageInfoGenerateEnable = true;
|
packageInfoGenerateEnable = true;
|
||||||
}
|
}
|
||||||
|
//endregion === 启用配置 ===
|
||||||
|
|
||||||
// === 禁用配置 ===
|
//region === 禁用配置 ===
|
||||||
|
|
||||||
public void disableEntity() {
|
public void disableEntity() {
|
||||||
entityGenerateEnable = false;
|
entityGenerateEnable = false;
|
||||||
@ -264,9 +270,9 @@ public class GlobalConfig implements Serializable {
|
|||||||
public void disablePackageInfo() {
|
public void disablePackageInfo() {
|
||||||
packageInfoGenerateEnable = false;
|
packageInfoGenerateEnable = false;
|
||||||
}
|
}
|
||||||
|
//endregion === 禁用配置 ===
|
||||||
|
|
||||||
|
//region === 自定义配置 ===
|
||||||
// === 自定义配置 ===
|
|
||||||
|
|
||||||
public Object getCustomConfig(String key) {
|
public Object getCustomConfig(String key) {
|
||||||
return customConfig.get(key);
|
return customConfig.get(key);
|
||||||
@ -283,7 +289,9 @@ public class GlobalConfig implements Serializable {
|
|||||||
public void setCustomConfig(Map<String, Object> customConfig) {
|
public void setCustomConfig(Map<String, Object> customConfig) {
|
||||||
this.customConfig = customConfig;
|
this.customConfig = customConfig;
|
||||||
}
|
}
|
||||||
// === 分项配置 ===
|
//endregion === 自定义配置 ===
|
||||||
|
|
||||||
|
//region === 分项配置 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see JavadocConfig#getAuthor()
|
* @see JavadocConfig#getAuthor()
|
||||||
@ -1566,5 +1574,5 @@ public class GlobalConfig implements Serializable {
|
|||||||
public void setPackageInfoGenerateEnable(boolean packageInfoGenerateEnable) {
|
public void setPackageInfoGenerateEnable(boolean packageInfoGenerateEnable) {
|
||||||
this.packageInfoGenerateEnable = packageInfoGenerateEnable;
|
this.packageInfoGenerateEnable = packageInfoGenerateEnable;
|
||||||
}
|
}
|
||||||
|
//endregion === 分项配置 ===
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,6 +93,10 @@ public class Column {
|
|||||||
this.property = buildPropertyName();
|
this.property = buildPropertyName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProperty(String property) {
|
||||||
|
this.property = property;
|
||||||
|
}
|
||||||
|
|
||||||
public String getProperty() {
|
public String getProperty() {
|
||||||
return property;
|
return property;
|
||||||
}
|
}
|
||||||
@ -110,12 +114,58 @@ public class Column {
|
|||||||
if (!columnConfig.getPropertyType().contains(".")) {
|
if (!columnConfig.getPropertyType().contains(".")) {
|
||||||
return columnConfig.getPropertyType();
|
return columnConfig.getPropertyType();
|
||||||
}
|
}
|
||||||
return StringUtil.substringAfterLast(columnConfig.getPropertyType(), ".");
|
return convertToSimpleGenericType(columnConfig.getPropertyType());
|
||||||
} else {
|
} else {
|
||||||
return StringUtil.substringAfterLast(propertyType, ".");
|
return convertToSimpleGenericType(propertyType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String convertToSimpleGenericType(String fullType) {
|
||||||
|
if (fullType == null || fullType.isEmpty()) {
|
||||||
|
return fullType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果不包含泛型,直接处理
|
||||||
|
if (!fullType.contains("<") && !fullType.endsWith(">")) {
|
||||||
|
return StringUtil.substringAfterLast(fullType, ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (i < fullType.length()) {
|
||||||
|
char c = fullType.charAt(i);
|
||||||
|
|
||||||
|
if (c == '<' || c == ',' || c == '>') {
|
||||||
|
result.append(c);
|
||||||
|
if (c == ',' || c == '<') {
|
||||||
|
// 跳过空格
|
||||||
|
while (i + 1 < fullType.length() && fullType.charAt(i + 1) == ' ') {
|
||||||
|
i++;
|
||||||
|
result.append(' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
// 提取类型名称
|
||||||
|
int start = i;
|
||||||
|
while (i < fullType.length() && fullType.charAt(i) != '<' &&
|
||||||
|
fullType.charAt(i) != ',' && fullType.charAt(i) != '>') {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
String typeName = fullType.substring(start, i).trim();
|
||||||
|
if (!typeName.isEmpty()) {
|
||||||
|
// 转换为简单类名
|
||||||
|
String simpleType = StringUtil.substringAfterLast(typeName, ".");
|
||||||
|
result.append(simpleType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public void setPropertyType(String propertyType) {
|
public void setPropertyType(String propertyType) {
|
||||||
this.propertyType = propertyType;
|
this.propertyType = propertyType;
|
||||||
}
|
}
|
||||||
@ -197,8 +247,8 @@ public class Column {
|
|||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
return "/**\n" +
|
return "/**\n" +
|
||||||
" * " + comment + "\n" +
|
" * " + comment + "\n" +
|
||||||
" */";
|
" */";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,16 +262,41 @@ public class Column {
|
|||||||
*/
|
*/
|
||||||
private static void addImportClass(Set<String> importClasses, String importClass) {
|
private static void addImportClass(Set<String> importClasses, String importClass) {
|
||||||
importClass = importClass.trim();
|
importClass = importClass.trim();
|
||||||
|
extractAllTypes(importClasses, importClass);
|
||||||
|
}
|
||||||
|
|
||||||
// java.util.List<String> >>>>> java.util.List
|
private static void extractAllTypes(Set<String> importClasses, String typeString) {
|
||||||
if (importClass.contains("<") && importClass.endsWith(">")) {
|
if (typeString == null || typeString.isEmpty()) {
|
||||||
importClass = importClass.substring(0, importClass.indexOf("<"));
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 不包含“.”则认为是原始类型,不需要import
|
int i = 0;
|
||||||
// lang 包不需要显式导入
|
while (i < typeString.length()) {
|
||||||
if (importClass.contains(".") && !importClass.startsWith("java.lang.")) {
|
// 跳过非字母字符
|
||||||
importClasses.add(importClass);
|
while (i < typeString.length() && !Character.isLetter(typeString.charAt(i))
|
||||||
|
&& typeString.charAt(i) != '_') {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i >= typeString.length()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取类名
|
||||||
|
int start = i;
|
||||||
|
while (i < typeString.length() &&
|
||||||
|
(Character.isLetterOrDigit(typeString.charAt(i)) ||
|
||||||
|
typeString.charAt(i) == '_' ||
|
||||||
|
typeString.charAt(i) == '.')) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
String className = typeString.substring(start, i);
|
||||||
|
|
||||||
|
// 检查是否包含包路径且不是java.lang包
|
||||||
|
if (className.contains(".") && !className.startsWith("java.lang.")) {
|
||||||
|
importClasses.add(className);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +309,7 @@ public class Column {
|
|||||||
public String buildAnnotations() {
|
public String buildAnnotations() {
|
||||||
StringBuilder annotations = new StringBuilder();
|
StringBuilder annotations = new StringBuilder();
|
||||||
|
|
||||||
//@Id 的注解
|
// @Id 的注解
|
||||||
if (isPrimaryKey || columnConfig.isPrimaryKey()) {
|
if (isPrimaryKey || columnConfig.isPrimaryKey()) {
|
||||||
annotations.append("@Id(");
|
annotations.append("@Id(");
|
||||||
|
|
||||||
@ -259,14 +334,13 @@ public class Column {
|
|||||||
needComma = true;
|
needComma = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (entityConfig != null && entityConfig.isColumnCommentEnable() && StringUtil.hasText(comment)) {
|
if (entityConfig != null && entityConfig.isColumnCommentEnable() && StringUtil.hasText(comment)) {
|
||||||
addComma(annotations, needComma);
|
addComma(annotations, needComma);
|
||||||
annotations.append("comment = \"")
|
annotations.append("comment = \"")
|
||||||
.append(this.comment.replace("\n", "")
|
.append(this.comment.replace("\n", "")
|
||||||
.replace("\"", "\\\"")
|
.replace("\"", "\\\"")
|
||||||
.trim())
|
.trim())
|
||||||
.append("\"");
|
.append("\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (annotations.length() == 4) {
|
if (annotations.length() == 4) {
|
||||||
@ -281,25 +355,25 @@ public class Column {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean needGenColumnAnnotation = (entityConfig != null && entityConfig.isAlwaysGenColumnAnnotation())
|
boolean needGenColumnAnnotation = (entityConfig != null && entityConfig.isAlwaysGenColumnAnnotation())
|
||||||
|| !name.equalsIgnoreCase(StringUtil.camelToUnderline(property))
|
|| !name.equalsIgnoreCase(StringUtil.camelToUnderline(property))
|
||||||
|| (entityConfig != null && entityConfig.isColumnCommentEnable() && StringUtil.hasText(this.comment) && annotations.length() == 0);
|
|| (entityConfig != null && entityConfig.isColumnCommentEnable() && StringUtil.hasText(this.comment)
|
||||||
|
&& annotations.length() == 0);
|
||||||
|
|
||||||
StringBuilder columnAnnotation = new StringBuilder("@Column(");
|
StringBuilder columnAnnotation = new StringBuilder("@Column(");
|
||||||
|
|
||||||
//@Column 注解
|
// @Column 注解
|
||||||
if (columnConfig.getOnInsertValue() != null
|
if (columnConfig.getOnInsertValue() != null
|
||||||
|| columnConfig.getOnUpdateValue() != null
|
|| columnConfig.getOnUpdateValue() != null
|
||||||
|| columnConfig.getLarge() != null
|
|| columnConfig.getLarge() != null
|
||||||
|| columnConfig.getLogicDelete() != null
|
|| columnConfig.getLogicDelete() != null
|
||||||
|| columnConfig.getVersion() != null
|
|| columnConfig.getVersion() != null
|
||||||
|| columnConfig.getJdbcType() != null
|
|| columnConfig.getJdbcType() != null
|
||||||
|| columnConfig.getTypeHandler() != null
|
|| columnConfig.getTypeHandler() != null
|
||||||
|| columnConfig.getTenantId() != null
|
|| columnConfig.getTenantId() != null
|
||||||
|| needGenColumnAnnotation
|
|| needGenColumnAnnotation) {
|
||||||
) {
|
|
||||||
boolean needComma = false;
|
boolean needComma = false;
|
||||||
if (entityConfig != null && entityConfig.isAlwaysGenColumnAnnotation()
|
if (entityConfig != null && entityConfig.isAlwaysGenColumnAnnotation()
|
||||||
|| !name.equalsIgnoreCase(StringUtil.camelToUnderline(property))) {
|
|| !name.equalsIgnoreCase(StringUtil.camelToUnderline(property))) {
|
||||||
columnAnnotation.append("value = \"").append(name).append("\"");
|
columnAnnotation.append("value = \"").append(name).append("\"");
|
||||||
needComma = true;
|
needComma = true;
|
||||||
}
|
}
|
||||||
@ -336,7 +410,8 @@ public class Column {
|
|||||||
}
|
}
|
||||||
if (columnConfig.getTypeHandler() != null) {
|
if (columnConfig.getTypeHandler() != null) {
|
||||||
addComma(columnAnnotation, needComma);
|
addComma(columnAnnotation, needComma);
|
||||||
columnAnnotation.append("typeHandler = ").append(columnConfig.getTypeHandler().getSimpleName()).append(".class");
|
columnAnnotation.append("typeHandler = ").append(columnConfig.getTypeHandler().getSimpleName())
|
||||||
|
.append(".class");
|
||||||
needComma = true;
|
needComma = true;
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(columnConfig.getTenantId())) {
|
if (Boolean.TRUE.equals(columnConfig.getTenantId())) {
|
||||||
@ -347,10 +422,10 @@ public class Column {
|
|||||||
if (entityConfig != null && entityConfig.isColumnCommentEnable() && StringUtil.hasText(comment)) {
|
if (entityConfig != null && entityConfig.isColumnCommentEnable() && StringUtil.hasText(comment)) {
|
||||||
addComma(columnAnnotation, needComma);
|
addComma(columnAnnotation, needComma);
|
||||||
columnAnnotation.append("comment = \"")
|
columnAnnotation.append("comment = \"")
|
||||||
.append(this.comment.replace("\n", "")
|
.append(this.comment.replace("\n", "")
|
||||||
.replace("\"", "\\\"")
|
.replace("\"", "\\\"")
|
||||||
.trim())
|
.trim())
|
||||||
.append("\"");
|
.append("\"");
|
||||||
}
|
}
|
||||||
columnAnnotation.append(")");
|
columnAnnotation.append(")");
|
||||||
|
|
||||||
@ -418,19 +493,19 @@ public class Column {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean needGenColumnAnnotation = (entityConfig != null && entityConfig.isAlwaysGenColumnAnnotation())
|
boolean needGenColumnAnnotation = (entityConfig != null && entityConfig.isAlwaysGenColumnAnnotation())
|
||||||
|| !name.equalsIgnoreCase(StringUtil.camelToUnderline(property))
|
|| !name.equalsIgnoreCase(StringUtil.camelToUnderline(property))
|
||||||
|| (entityConfig != null && entityConfig.isColumnCommentEnable() && StringUtil.hasText(this.comment));
|
|| (entityConfig != null && entityConfig.isColumnCommentEnable()
|
||||||
|
&& StringUtil.hasText(this.comment));
|
||||||
|
|
||||||
if (columnConfig.getOnInsertValue() != null
|
if (columnConfig.getOnInsertValue() != null
|
||||||
|| columnConfig.getOnUpdateValue() != null
|
|| columnConfig.getOnUpdateValue() != null
|
||||||
|| columnConfig.getLarge() != null
|
|| columnConfig.getLarge() != null
|
||||||
|| columnConfig.getLogicDelete() != null
|
|| columnConfig.getLogicDelete() != null
|
||||||
|| columnConfig.getVersion() != null
|
|| columnConfig.getVersion() != null
|
||||||
|| columnConfig.getJdbcType() != null
|
|| columnConfig.getJdbcType() != null
|
||||||
|| columnConfig.getTypeHandler() != null
|
|| columnConfig.getTypeHandler() != null
|
||||||
|| Boolean.TRUE.equals(columnConfig.getTenantId())
|
|| Boolean.TRUE.equals(columnConfig.getTenantId())
|
||||||
|| needGenColumnAnnotation
|
|| needGenColumnAnnotation) {
|
||||||
) {
|
|
||||||
addImportClass(importClasses, com.mybatisflex.annotation.Column.class.getName());
|
addImportClass(importClasses, com.mybatisflex.annotation.Column.class.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -450,11 +525,11 @@ public class Column {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Column{" +
|
return "Column{" +
|
||||||
"name='" + name + '\'' +
|
"name='" + name + '\'' +
|
||||||
", className='" + propertyType + '\'' +
|
", className='" + propertyType + '\'' +
|
||||||
", remarks='" + comment + '\'' +
|
", remarks='" + comment + '\'' +
|
||||||
", isAutoIncrement=" + isAutoIncrement +
|
", isAutoIncrement=" + isAutoIncrement +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,7 +74,7 @@ public interface BaseMapper<T> {
|
|||||||
*/
|
*/
|
||||||
int DEFAULT_BATCH_SIZE = 1000;
|
int DEFAULT_BATCH_SIZE = 1000;
|
||||||
|
|
||||||
// === 增(insert) ===
|
//region === 增(insert) ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入实体类数据,不忽略 {@code null} 值。
|
* 插入实体类数据,不忽略 {@code null} 值。
|
||||||
@ -253,8 +253,9 @@ public interface BaseMapper<T> {
|
|||||||
return update(entity, ignoreNulls);
|
return update(entity, ignoreNulls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//endregion === 增(insert) ===
|
||||||
|
|
||||||
// === 删(delete) ===
|
//region === 删(delete) ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据实体主键来删除数据。
|
* 根据实体主键来删除数据。
|
||||||
@ -343,8 +344,9 @@ public interface BaseMapper<T> {
|
|||||||
*/
|
*/
|
||||||
@DeleteProvider(type = EntitySqlProvider.class, method = "deleteByQuery")
|
@DeleteProvider(type = EntitySqlProvider.class, method = "deleteByQuery")
|
||||||
int deleteByQuery(@Param(FlexConsts.QUERY) QueryWrapper queryWrapper);
|
int deleteByQuery(@Param(FlexConsts.QUERY) QueryWrapper queryWrapper);
|
||||||
|
//endregion === 删(delete) ===
|
||||||
|
|
||||||
// === 改(update) ===
|
//region === 改(update) ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据主键来更新数据,若实体类属性数据为 {@code null},该属性不会更新到数据库。
|
* 根据主键来更新数据,若实体类属性数据为 {@code null},该属性不会更新到数据库。
|
||||||
@ -439,9 +441,9 @@ public interface BaseMapper<T> {
|
|||||||
*/
|
*/
|
||||||
@UpdateProvider(type = EntitySqlProvider.class, method = "updateByQuery")
|
@UpdateProvider(type = EntitySqlProvider.class, method = "updateByQuery")
|
||||||
int updateByQuery(@Param(FlexConsts.ENTITY) T entity, @Param(FlexConsts.IGNORE_NULLS) boolean ignoreNulls, @Param(FlexConsts.QUERY) QueryWrapper queryWrapper);
|
int updateByQuery(@Param(FlexConsts.ENTITY) T entity, @Param(FlexConsts.IGNORE_NULLS) boolean ignoreNulls, @Param(FlexConsts.QUERY) QueryWrapper queryWrapper);
|
||||||
|
//endregion === 改(update) ===
|
||||||
|
|
||||||
|
//region === 改(update) ===
|
||||||
// === 查(select) ===
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据实体主键查询数据。
|
* 根据实体主键查询数据。
|
||||||
@ -1264,5 +1266,5 @@ public interface BaseMapper<T> {
|
|||||||
}
|
}
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
//endregion === 改(update) ===
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public class Mappers {
|
|||||||
private Mappers() {
|
private Mappers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<Class<?>, Object> MAPPER_OBJECTS = new ConcurrentHashMap<>();
|
private static final Map<String, Map<Class<?>, Object>> MAPPER_OBJECTS_OF_ENV = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static final Map<Class<?>, Class<?>> ENTITY_MAPPER_MAP = new ConcurrentHashMap<>();
|
private static final Map<Class<?>, Class<?>> ENTITY_MAPPER_MAP = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@ -79,14 +79,16 @@ public class Mappers {
|
|||||||
* @return {@link BaseMapper} 对象
|
* @return {@link BaseMapper} 对象
|
||||||
*/
|
*/
|
||||||
public static <M> M ofMapperClass(Class<M> mapperClass) {
|
public static <M> M ofMapperClass(Class<M> mapperClass) {
|
||||||
Object mapperObject = MapUtil.computeIfAbsent(MAPPER_OBJECTS, mapperClass, clazz ->
|
Map<Class<?>, Object> mapperObjects = MapUtil.computeIfAbsent(MAPPER_OBJECTS_OF_ENV, "default", envId -> new ConcurrentHashMap<>());
|
||||||
|
Object mapperObject = MapUtil.computeIfAbsent(mapperObjects, mapperClass, clazz ->
|
||||||
Proxy.newProxyInstance(mapperClass.getClassLoader()
|
Proxy.newProxyInstance(mapperClass.getClassLoader()
|
||||||
, new Class[]{mapperClass}
|
, new Class[]{mapperClass}
|
||||||
, new MapperHandler(mapperClass)));
|
, new MapperHandler(mapperClass)));
|
||||||
return (M) mapperObject;
|
return (M) mapperObject;
|
||||||
}
|
}
|
||||||
public static <M> M ofMapperClass(String environmentId, Class<M> mapperClass) {
|
public static <M> M ofMapperClass(String environmentId, Class<M> mapperClass) {
|
||||||
Object mapperObject = MapUtil.computeIfAbsent(MAPPER_OBJECTS, mapperClass, clazz ->
|
Map<Class<?>, Object> mapperObjects = MapUtil.computeIfAbsent(MAPPER_OBJECTS_OF_ENV, environmentId, envId -> new ConcurrentHashMap<>());
|
||||||
|
Object mapperObject = MapUtil.computeIfAbsent(mapperObjects, mapperClass, clazz ->
|
||||||
Proxy.newProxyInstance(mapperClass.getClassLoader()
|
Proxy.newProxyInstance(mapperClass.getClassLoader()
|
||||||
, new Class[]{mapperClass}
|
, new Class[]{mapperClass}
|
||||||
, new MapperHandler(environmentId, mapperClass)));
|
, new MapperHandler(environmentId, mapperClass)));
|
||||||
|
|||||||
@ -35,7 +35,7 @@ public class QueryMethods {
|
|||||||
private QueryMethods() {
|
private QueryMethods() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// === 数学函数 ===
|
//region === 数学函数 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回 x 的绝对值。
|
* 返回 x 的绝对值。
|
||||||
@ -680,8 +680,9 @@ public class QueryMethods {
|
|||||||
public static <T> QueryColumn cot(LambdaGetter<T> columnX) {
|
public static <T> QueryColumn cot(LambdaGetter<T> columnX) {
|
||||||
return new FunctionQueryColumn(COT, LambdaUtil.getQueryColumn(columnX));
|
return new FunctionQueryColumn(COT, LambdaUtil.getQueryColumn(columnX));
|
||||||
}
|
}
|
||||||
|
//endregion === 数学函数 ===
|
||||||
|
|
||||||
// === 字符串函数 ===
|
//region === 字符串函数 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回字符串 s 的字符数。
|
* 返回字符串 s 的字符数。
|
||||||
@ -1181,8 +1182,9 @@ public class QueryMethods {
|
|||||||
public static <S1, S2> QueryColumn findInSet(LambdaGetter<S1> columnS1, LambdaGetter<S2> columnS2) {
|
public static <S1, S2> QueryColumn findInSet(LambdaGetter<S1> columnS1, LambdaGetter<S2> columnS2) {
|
||||||
return new FunctionQueryColumn(FIND_IN_SET, LambdaUtil.getQueryColumn(columnS1), LambdaUtil.getQueryColumn(columnS2));
|
return new FunctionQueryColumn(FIND_IN_SET, LambdaUtil.getQueryColumn(columnS1), LambdaUtil.getQueryColumn(columnS2));
|
||||||
}
|
}
|
||||||
|
//endregion === 字符串函数 ===
|
||||||
|
|
||||||
// === 日期时间函数 ===
|
//region === 日期时间函数 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回当前日期。
|
* 返回当前日期。
|
||||||
@ -1884,8 +1886,9 @@ public class QueryMethods {
|
|||||||
public static <T, S> QueryColumn getFormat(LambdaGetter<T> columnType, LambdaGetter<S> columnS) {
|
public static <T, S> QueryColumn getFormat(LambdaGetter<T> columnType, LambdaGetter<S> columnS) {
|
||||||
return new FunctionQueryColumn(GET_FORMAT, LambdaUtil.getQueryColumn(columnType), LambdaUtil.getQueryColumn(columnS));
|
return new FunctionQueryColumn(GET_FORMAT, LambdaUtil.getQueryColumn(columnType), LambdaUtil.getQueryColumn(columnS));
|
||||||
}
|
}
|
||||||
|
//endregion === 日期时间函数 ===
|
||||||
|
|
||||||
// === 系统信息函数 ===
|
//region === 系统信息函数 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回数据库的版本号。
|
* 返回数据库的版本号。
|
||||||
@ -1970,8 +1973,9 @@ public class QueryMethods {
|
|||||||
public static QueryColumn lastInsertId() {
|
public static QueryColumn lastInsertId() {
|
||||||
return new FunctionQueryColumn(LAST_INSERT_ID);
|
return new FunctionQueryColumn(LAST_INSERT_ID);
|
||||||
}
|
}
|
||||||
|
//endregion === 系统信息函数 ===
|
||||||
|
|
||||||
// === 加密函数 ===
|
//region === 加密函数 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对字符串 str 进行加密。
|
* 对字符串 str 进行加密。
|
||||||
@ -2056,8 +2060,9 @@ public class QueryMethods {
|
|||||||
public static <C, P> QueryColumn decode(LambdaGetter<C> columnCryptStr, LambdaGetter<P> columnPswdStr) {
|
public static <C, P> QueryColumn decode(LambdaGetter<C> columnCryptStr, LambdaGetter<P> columnPswdStr) {
|
||||||
return new FunctionQueryColumn(DECODE, LambdaUtil.getQueryColumn(columnCryptStr), LambdaUtil.getQueryColumn(columnPswdStr));
|
return new FunctionQueryColumn(DECODE, LambdaUtil.getQueryColumn(columnCryptStr), LambdaUtil.getQueryColumn(columnPswdStr));
|
||||||
}
|
}
|
||||||
|
//endregion === 加密函数 ===
|
||||||
|
|
||||||
// === 其他函数 ===
|
//region === 其他函数 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化函数,可以将数字 x 进行格式化,将 x 保留到小数点后 n 位,这个过程需要进行四舍五入。
|
* 格式化函数,可以将数字 x 进行格式化,将 x 保留到小数点后 n 位,这个过程需要进行四舍五入。
|
||||||
@ -2226,8 +2231,9 @@ public class QueryMethods {
|
|||||||
public static <T> QueryColumn inetNtoa(LambdaGetter<T> columnN) {
|
public static <T> QueryColumn inetNtoa(LambdaGetter<T> columnN) {
|
||||||
return new FunctionQueryColumn(INET_NTOA, LambdaUtil.getQueryColumn(columnN));
|
return new FunctionQueryColumn(INET_NTOA, LambdaUtil.getQueryColumn(columnN));
|
||||||
}
|
}
|
||||||
|
//endregion === 其他函数 ===
|
||||||
|
|
||||||
// === 聚合函数 ===
|
//region === 聚合函数 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回指定列的最大值。
|
* 返回指定列的最大值。
|
||||||
@ -2312,8 +2318,9 @@ public class QueryMethods {
|
|||||||
public static <T> FunctionQueryColumn sum(LambdaGetter<T> column) {
|
public static <T> FunctionQueryColumn sum(LambdaGetter<T> column) {
|
||||||
return new FunctionQueryColumn(SUM, LambdaUtil.getQueryColumn(column));
|
return new FunctionQueryColumn(SUM, LambdaUtil.getQueryColumn(column));
|
||||||
}
|
}
|
||||||
|
//endregion === 聚合函数 ===
|
||||||
|
|
||||||
// === COUNT ===
|
//region === COUNT ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回指定列的总行数。
|
* 返回指定列的总行数。
|
||||||
@ -2342,9 +2349,9 @@ public class QueryMethods {
|
|||||||
public static <T> FunctionQueryColumn count(LambdaGetter<T> column) {
|
public static <T> FunctionQueryColumn count(LambdaGetter<T> column) {
|
||||||
return new FunctionQueryColumn(COUNT, LambdaUtil.getQueryColumn(column));
|
return new FunctionQueryColumn(COUNT, LambdaUtil.getQueryColumn(column));
|
||||||
}
|
}
|
||||||
|
//endregion === COUNT ===
|
||||||
|
|
||||||
|
//region === DISTINCT ===
|
||||||
// === DISTINCT ===
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对指定列进行去重。
|
* 对指定列进行去重。
|
||||||
@ -2358,8 +2365,9 @@ public class QueryMethods {
|
|||||||
return new DistinctQueryColumn(Arrays.stream(columns)
|
return new DistinctQueryColumn(Arrays.stream(columns)
|
||||||
.map(LambdaUtil::getQueryColumn).toArray(QueryColumn[]::new));
|
.map(LambdaUtil::getQueryColumn).toArray(QueryColumn[]::new));
|
||||||
}
|
}
|
||||||
|
//endregion === DISTINCT ===
|
||||||
|
|
||||||
// === CASE THEN ELSE ===
|
//region === CASE THEN ELSE ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建 case then when 语句。
|
* 构建 case then when 语句。
|
||||||
@ -2374,8 +2382,9 @@ public class QueryMethods {
|
|||||||
public static CaseSearchQueryColumn.Builder case_(QueryColumn column) {
|
public static CaseSearchQueryColumn.Builder case_(QueryColumn column) {
|
||||||
return new CaseSearchQueryColumn.Builder(column);
|
return new CaseSearchQueryColumn.Builder(column);
|
||||||
}
|
}
|
||||||
|
//endregion === CASE THEN ELSE ===
|
||||||
|
|
||||||
// === CONVERT ===
|
//region === CONVERT ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将所给类型类型转换为另一种类型。
|
* 将所给类型类型转换为另一种类型。
|
||||||
@ -2383,8 +2392,9 @@ public class QueryMethods {
|
|||||||
public static StringFunctionQueryColumn convert(String... params) {
|
public static StringFunctionQueryColumn convert(String... params) {
|
||||||
return new StringFunctionQueryColumn(CONVERT, params);
|
return new StringFunctionQueryColumn(CONVERT, params);
|
||||||
}
|
}
|
||||||
|
//endregion === CONVERT ===
|
||||||
|
|
||||||
// === 构建 column 列 ===
|
//region === 构建 column 列 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建 TRUE 常量。
|
* 构建 TRUE 常量。
|
||||||
@ -2494,8 +2504,9 @@ public class QueryMethods {
|
|||||||
}
|
}
|
||||||
return queryColumns;
|
return queryColumns;
|
||||||
}
|
}
|
||||||
|
//endregion === 构建 column 列 ===
|
||||||
|
|
||||||
// === IF 函数 ===
|
//region === IF 函数 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IF 函数。
|
* IF 函数。
|
||||||
@ -2552,9 +2563,9 @@ public class QueryMethods {
|
|||||||
public static <N> QueryColumn ifNull(LambdaGetter<N> nullColumn, String elseColumn) {
|
public static <N> QueryColumn ifNull(LambdaGetter<N> nullColumn, String elseColumn) {
|
||||||
return ifNull(nullColumn, new QueryColumn(elseColumn));
|
return ifNull(nullColumn, new QueryColumn(elseColumn));
|
||||||
}
|
}
|
||||||
|
//endregion === IF 函数 ===
|
||||||
|
|
||||||
|
//region === 构建 QueryCondition 查询条件 ===
|
||||||
// === 构建 QueryCondition 查询条件 ===
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EXIST (SELECT ...)
|
* EXIST (SELECT ...)
|
||||||
@ -2597,8 +2608,9 @@ public class QueryMethods {
|
|||||||
public static QueryCondition bracket(QueryCondition condition) {
|
public static QueryCondition bracket(QueryCondition condition) {
|
||||||
return new Brackets(condition);
|
return new Brackets(condition);
|
||||||
}
|
}
|
||||||
|
//endregion === 构建 QueryCondition 查询条件 ===
|
||||||
|
|
||||||
// === 构建 QueryWrapper 查询 ===
|
//region === 构建 QueryWrapper 查询 ===
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SELECT queryColumns FROM table
|
* SELECT queryColumns FROM table
|
||||||
@ -2673,5 +2685,5 @@ public class QueryMethods {
|
|||||||
public static FunctionQueryColumn date(QueryColumn column) {
|
public static FunctionQueryColumn date(QueryColumn column) {
|
||||||
return new FunctionQueryColumn("DATE", column);
|
return new FunctionQueryColumn("DATE", column);
|
||||||
}
|
}
|
||||||
|
//endregion === 构建 QueryWrapper 查询 ===
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public interface IService<T> {
|
|||||||
*/
|
*/
|
||||||
BaseMapper<T> getMapper();
|
BaseMapper<T> getMapper();
|
||||||
|
|
||||||
// ===== 保存(增)操作 =====
|
//region ===== 保存(增)操作 =====
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>保存实体类对象数据。
|
* <p>保存实体类对象数据。
|
||||||
@ -128,8 +128,9 @@ public interface IService<T> {
|
|||||||
Class<BaseMapper<T>> usefulClass = (Class<BaseMapper<T>>) ClassUtil.getUsefulClass(getMapper().getClass());
|
Class<BaseMapper<T>> usefulClass = (Class<BaseMapper<T>>) ClassUtil.getUsefulClass(getMapper().getClass());
|
||||||
return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::insertOrUpdateSelective));
|
return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::insertOrUpdateSelective));
|
||||||
}
|
}
|
||||||
|
//endregion ===== 保存(增)操作 =====
|
||||||
|
|
||||||
// ===== 删除(删)操作 =====
|
//region ===== 删除(删)操作 =====
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>根据查询条件删除数据。
|
* <p>根据查询条件删除数据。
|
||||||
@ -197,8 +198,9 @@ public interface IService<T> {
|
|||||||
}
|
}
|
||||||
return remove(query().where(query));
|
return remove(query().where(query));
|
||||||
}
|
}
|
||||||
|
//endregion ===== 删除(删)操作 =====
|
||||||
|
|
||||||
// ===== 更新(改)操作 =====
|
//region ===== 更新(改)操作 =====
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>根据数据主键更新数据。
|
* <p>根据数据主键更新数据。
|
||||||
@ -313,8 +315,9 @@ public interface IService<T> {
|
|||||||
Class<BaseMapper<T>> usefulClass = (Class<BaseMapper<T>>) ClassUtil.getUsefulClass(getMapper().getClass());
|
Class<BaseMapper<T>> usefulClass = (Class<BaseMapper<T>>) ClassUtil.getUsefulClass(getMapper().getClass());
|
||||||
return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, (mapper, entity) -> mapper.update(entity, ignoreNulls)));
|
return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, (mapper, entity) -> mapper.update(entity, ignoreNulls)));
|
||||||
}
|
}
|
||||||
|
//endregion ===== 更新(改)操作 =====
|
||||||
|
|
||||||
// ===== 查询(查)操作 =====
|
//region ===== 查询(查)操作 =====
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>根据数据主键查询一条数据。
|
* <p>根据数据主键查询一条数据。
|
||||||
@ -546,8 +549,9 @@ public interface IService<T> {
|
|||||||
default List<T> listByMap(Map<String, Object> query) {
|
default List<T> listByMap(Map<String, Object> query) {
|
||||||
return list(query().where(query));
|
return list(query().where(query));
|
||||||
}
|
}
|
||||||
|
//endregion ===== 查询(查)操作 =====
|
||||||
|
|
||||||
// ===== 数量查询操作 =====
|
//region ===== 数量查询操作 =====
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>根据查询条件判断数据是否存在。
|
* <p>根据查询条件判断数据是否存在。
|
||||||
@ -605,8 +609,9 @@ public interface IService<T> {
|
|||||||
default long count(QueryCondition condition) {
|
default long count(QueryCondition condition) {
|
||||||
return count(query().where(condition));
|
return count(query().where(condition));
|
||||||
}
|
}
|
||||||
|
//endregion ===== 数量查询操作 =====
|
||||||
|
|
||||||
// ===== 分页查询操作 =====
|
//region ===== 分页查询操作 =====
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>分页查询所有数据。
|
* <p>分页查询所有数据。
|
||||||
@ -651,8 +656,9 @@ public interface IService<T> {
|
|||||||
default <R> Page<R> pageAs(Page<R> page, QueryWrapper query, Class<R> asType) {
|
default <R> Page<R> pageAs(Page<R> page, QueryWrapper query, Class<R> asType) {
|
||||||
return getMapper().paginateAs(page, query, asType);
|
return getMapper().paginateAs(page, query, asType);
|
||||||
}
|
}
|
||||||
|
//endregion ===== 分页查询操作 =====
|
||||||
|
|
||||||
// ===== 查询包装器操作 =====
|
//region ===== 查询包装器操作 =====
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认 {@link QueryWrapper} 构建。
|
* 默认 {@link QueryWrapper} 构建。
|
||||||
@ -680,5 +686,5 @@ public interface IService<T> {
|
|||||||
default UpdateChain<T> updateChain() {
|
default UpdateChain<T> updateChain() {
|
||||||
return UpdateChain.create(getMapper());
|
return UpdateChain.create(getMapper());
|
||||||
}
|
}
|
||||||
|
//endregion ===== 查询包装器操作 =====
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user