【代码优化】全局:数据库 findInSet 兼容

This commit is contained in:
YunaiV 2024-07-07 09:31:27 +08:00
parent 87c6c90a47
commit f5ed040943
2 changed files with 16 additions and 4 deletions

View File

@ -11,10 +11,13 @@ import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* 针对 MyBatis Plus {@link DbType} 增强补充更多信息
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum DbTypeEnum { public enum DbTypeEnum {
/** /**
* MySQL * MySQL
*/ */
@ -27,6 +30,8 @@ public enum DbTypeEnum {
/** /**
* PostgreSQL * PostgreSQL
*
* 华为 openGauss 使用 ProductName PostgreSQL 相同
*/ */
POSTGRE_SQL(DbType.POSTGRE_SQL,"PostgreSQL", "POSITION('#{value}' IN #{column}) <> 0"), POSTGRE_SQL(DbType.POSTGRE_SQL,"PostgreSQL", "POSITION('#{value}' IN #{column}) <> 0"),
@ -44,8 +49,6 @@ public enum DbTypeEnum {
* 人大金仓 * 人大金仓
*/ */
KINGBASE_ES(DbType.KINGBASE_ES, "KingbaseES", "POSITION('#{value}' IN #{column}) <> 0"), KINGBASE_ES(DbType.KINGBASE_ES, "KingbaseES", "POSITION('#{value}' IN #{column}) <> 0"),
// 华为openGauss 使用ProductName PostgreSQL相同
; ;
public static final Map<String, DbTypeEnum> MAP_BY_NAME = Arrays.stream(values()) public static final Map<String, DbTypeEnum> MAP_BY_NAME = Arrays.stream(values())
@ -54,9 +57,17 @@ public enum DbTypeEnum {
public static final Map<DbType, DbTypeEnum> MAP_BY_MP = Arrays.stream(values()) public static final Map<DbType, DbTypeEnum> MAP_BY_MP = Arrays.stream(values())
.collect(Collectors.toMap(DbTypeEnum::getMpDbType, Function.identity())); .collect(Collectors.toMap(DbTypeEnum::getMpDbType, Function.identity()));
/**
* MyBatis Plus 类型
*/
private final DbType mpDbType; private final DbType mpDbType;
/**
* 数据库产品名
*/
private final String productName; private final String productName;
/**
* SQL FIND_IN_SET 模板
*/
private final String findInSetTemplate; private final String findInSetTemplate;
public static DbType find(String databaseProductName) { public static DbType find(String databaseProductName) {

View File

@ -102,4 +102,5 @@ public class MyBatisUtils {
.replace("#{column}", column) .replace("#{column}", column)
.replace("#{value}", StrUtil.toString(value)); .replace("#{value}", StrUtil.toString(value));
} }
} }