mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-13 18:45:06 +08:00
适配 Oracle 数据库
1. 修复配置中心的 DAO 查询报错 2. 适配 LIMIT 1 的查询
This commit is contained in:
@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.mybatis.config;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
@ -41,6 +42,9 @@ public class IdTypeEnvironmentPostProcessor implements EnvironmentPostProcessor
|
||||
// TODO 芋艿:暂时没有找到特别合适的地方,先放在这里
|
||||
setJobStoreDriverIfPresent(environment, dbType);
|
||||
|
||||
// 初始化 SQL 静态变量
|
||||
SqlConstants.init(dbType);
|
||||
|
||||
// 如果非 NONE,则不进行处理
|
||||
IdType idType = getIdType(environment);
|
||||
if (idType != IdType.NONE) {
|
||||
|
@ -1,12 +1,21 @@
|
||||
package cn.iocoder.yudao.framework.mybatis.core.enums;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
|
||||
/**
|
||||
* SQL相关常量类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface SqlConstants {
|
||||
public class SqlConstants {
|
||||
|
||||
String LIMIT1 = "LIMIT 1";
|
||||
/**
|
||||
* 数据库的类型
|
||||
*/
|
||||
public static DbType DB_TYPE;
|
||||
|
||||
public static void init(DbType dbType) {
|
||||
DB_TYPE = dbType;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.framework.mybatis.core.query;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
@ -124,4 +126,24 @@ public class QueryWrapperX<T> extends QueryWrapper<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置只返回最后一条
|
||||
*
|
||||
* TODO 芋艿:不是完美解,需要在思考下。如果使用多数据源,并且数据源是多种类型时,可能会存在问题:实现之返回一条的语法不同
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public QueryWrapperX<T> limit1() {
|
||||
Assert.notNull(SqlConstants.DB_TYPE, "获取不到数据库的类型");
|
||||
switch (SqlConstants.DB_TYPE) {
|
||||
case ORACLE:
|
||||
case ORACLE_12C:
|
||||
super.eq("ROWNUM", 1);
|
||||
break;
|
||||
default:
|
||||
super.last("LIMIT 1");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user