diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/constant/FuncName.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/constant/FuncName.java index 2b2c63ba..a302e432 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/constant/FuncName.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/constant/FuncName.java @@ -144,6 +144,8 @@ public class FuncName { public static final String WEEKOFYEAR = "WEEKOFYEAR"; public static final String YEAR = "YEAR"; public static final String GROUP_CONCAT = "GROUP_CONCAT"; + public static final String STRING_AGG = "STRING_AGG"; + public static final String LISTAGG = "LISTAGG"; private FuncName() { } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbType.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbType.java index 61f5a262..9c880f05 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbType.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbType.java @@ -17,6 +17,7 @@ package com.mybatisflex.core.dialect; import com.mybatisflex.core.util.StringUtil; import java.util.Arrays; +import java.util.List; public enum DbType { @@ -208,4 +209,44 @@ public enum DbType { .findFirst() .orElse(null); } + + /** + * 获取所有数据库类型 + * + * @return 包含所有数据库类型的列表 + */ + public static List all() { + return Arrays.asList(DbType.values()); + } + + /** + * 判断当前数据库语法是否与MySQL属于同一类型 + */ + public boolean mysqlSameType() { + return this == MYSQL || this == MARIADB || this == GBASE || this == OSCAR || this == XUGU || this == CLICK_HOUSE || this == OCEAN_BASE || this == CUBRID || this == SUNDB || this == GOLDENDB || this == YASDB; + } + + /** + * 判断当前数据库语法是否与Oracle属于同一类型 + */ + public boolean oracleSameType() { + return this == ORACLE || this == DM; + } + + /** + * 判断当前数据库语法是否与PostgreSQL属于同一类型 + */ + public boolean postgresqlSameType() { + return this == POSTGRE_SQL || this == H2 || this == LEALONE || this == SQLITE || this == HSQL || this == KINGBASE_ES || this == PHOENIX || this == SAP_HANA || this == IMPALA || this == HIGH_GO || this == VERTICA || this == REDSHIFT || this == GAUSS || this == OPENGAUSS || this == TDENGINE || this == UXDB || this == GBASE_8S_PG || this == GBASE_8C || this == VASTBASE || this == DUCKDB; + } + + /** + * 是否为已兼容的数据库类型 + * 允许的数据库类型包括MySQL系列、Oracle系列和PostgreSQL系列 + * + * @return 如果是允许的数据库类型返回true,否则返回false + */ + public boolean isSupportDb() { + return mysqlSameType() || oracleSameType() || postgresqlSameType(); + } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java index 1ceafbae..6bb58b3a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java @@ -16,6 +16,7 @@ package com.mybatisflex.core.dialect; +import com.mybatisflex.core.FlexGlobalConfig; import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.exception.locale.LocalizedFormats; import com.mybatisflex.core.util.StringUtil; @@ -37,6 +38,20 @@ public class DbTypeUtil { private DbTypeUtil() { } + /** + * 获取当前数据库类型 + *

首先从全局配置中获取数据库类型,如果全局配置中未设置,则尝试从方言工厂中获取线程局部变量设置的数据库类型 + * + * @return 当前数据库类型,可能为null + */ + public static DbType getCurrentDbType() { + DbType dbType = FlexGlobalConfig.getDefaultConfig().getDbType(); + if (dbType == null) { + dbType = DialectFactory.getHintDbType(); + } + return dbType; + } + /** * 获取当前配置的 DbType */ diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryMethods.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryMethods.java index 67f8c08a..caddb467 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryMethods.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryMethods.java @@ -2678,6 +2678,20 @@ public class QueryMethods { return new FunctionQueryColumn(GROUP_CONCAT, columnX); } + /** + * STRING_AGG 聚合函数 + */ + public static QueryColumn stringAgg(QueryColumn columnX, String separator) { + return new FunctionQueryColumn(STRING_AGG, columnX, string(separator)); + } + + /** + * LISTAGG 聚合函数 + */ + public static QueryColumn listAgg(QueryColumn columnX, String separator) { + return new FunctionQueryColumn(LISTAGG, columnX, string(separator)); + } + /** * date 函数 * @return