适配 Oracle 数据库

1. 修复配置中心的 DAO 查询报错
2. 适配 LIMIT 1 的查询
pull/2/head
YunaiV 2022-05-01 17:55:13 +08:00
parent 7db1a58bfc
commit 6f18adb54a
8 changed files with 56 additions and 21 deletions

View File

@ -15,12 +15,12 @@ import java.util.List;
public interface ConfigFrameworkDAO { public interface ConfigFrameworkDAO {
/** /**
* maxUpdateTime * maxUpdateTime
* *
* @param maxUpdateTime * @param maxUpdateTime
* @return * @return
*/ */
boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime); int selectCountByUpdateTimeGt(Date maxUpdateTime);
/** /**
* *

View File

@ -24,7 +24,6 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Predicate;
@Slf4j @Slf4j
public class DBConfigRepository extends AbstractConfigRepository { public class DBConfigRepository extends AbstractConfigRepository {
@ -172,7 +171,7 @@ public class DBConfigRepository extends AbstractConfigRepository {
if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据
log.info("[loadConfigIfUpdate][首次加载全量配置]"); log.info("[loadConfigIfUpdate][首次加载全量配置]");
} else { // 判断数据库中是否有更新的配置 } else { // 判断数据库中是否有更新的配置
if (!configFrameworkDAO.selectExistsByUpdateTimeAfter(maxUpdateTime)) { if (configFrameworkDAO.selectCountByUpdateTimeGt(maxUpdateTime) == 0) {
return null; return null;
} }
log.info("[loadConfigIfUpdate][增量加载全量配置]"); log.info("[loadConfigIfUpdate][增量加载全量配置]");

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.mybatis.config;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.util.collection.SetUtils; 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 cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
@ -41,6 +42,9 @@ public class IdTypeEnvironmentPostProcessor implements EnvironmentPostProcessor
// TODO 芋艿:暂时没有找到特别合适的地方,先放在这里 // TODO 芋艿:暂时没有找到特别合适的地方,先放在这里
setJobStoreDriverIfPresent(environment, dbType); setJobStoreDriverIfPresent(environment, dbType);
// 初始化 SQL 静态变量
SqlConstants.init(dbType);
// 如果非 NONE则不进行处理 // 如果非 NONE则不进行处理
IdType idType = getIdType(environment); IdType idType = getIdType(environment);
if (idType != IdType.NONE) { if (idType != IdType.NONE) {

View File

@ -1,12 +1,21 @@
package cn.iocoder.yudao.framework.mybatis.core.enums; package cn.iocoder.yudao.framework.mybatis.core.enums;
import com.baomidou.mybatisplus.annotation.DbType;
/** /**
* SQL * SQL
* *
* @author * @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;
}
} }

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.framework.mybatis.core.query; 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.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils; import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@ -124,4 +126,24 @@ public class QueryWrapperX<T> extends QueryWrapper<T> {
return this; 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;
}
} }

View File

@ -2,12 +2,10 @@ package cn.iocoder.yudao.module.infra.dal.mysql.config;
import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO; import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO;
import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO; import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.sql.ResultSet;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -26,14 +24,18 @@ public class ConfigDAOImpl implements ConfigFrameworkDAO {
} }
@Override @Override
public boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { public int selectCountByUpdateTimeGt(Date maxUpdateTime) {
return jdbcTemplate.query("SELECT id FROM infra_config WHERE update_time > ? LIMIT 1", return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM infra_config WHERE update_time > ?",
ResultSet::next, maxUpdateTime); Integer.class, maxUpdateTime);
} }
@Override @Override
public List<ConfigRespDTO> selectList() { public List<ConfigRespDTO> selectList() {
return jdbcTemplate.query("SELECT `key`, `value`, update_time, deleted FROM infra_config", new BeanPropertyRowMapper<>(ConfigRespDTO.class)); return jdbcTemplate.query("SELECT config_key, value, update_time, deleted FROM infra_config",
(rs, rowNum) -> new ConfigRespDTO().setKey(rs.getString("config_key"))
.setValue(rs.getString("value"))
.setUpdateTime(rs.getDate("update_time"))
.setDeleted(rs.getBoolean("deleted")));
} }
} }

View File

@ -9,7 +9,7 @@ tenant-id: {{appTenentId}}
} }
### 请求 /send-sms-code 接口 => 成功 ### 请求 /send-sms-code 接口 => 成功
POST {{appApi}}/member/send-sms-code POST {{appApi}}/member/auth/send-sms-code
Content-Type: application/json Content-Type: application/json
tenant-id: {{appTenentId}} tenant-id: {{appTenentId}}

View File

@ -1,8 +1,7 @@
package cn.iocoder.yudao.module.system.dal.mysql.sms; package cn.iocoder.yudao.module.system.dal.mysql.sms;
import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsCodeDO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsCodeDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -18,12 +17,12 @@ public interface SmsCodeMapper extends BaseMapperX<SmsCodeDO> {
* @return * @return
*/ */
default SmsCodeDO selectLastByMobile(String mobile, String code, Integer scene) { default SmsCodeDO selectLastByMobile(String mobile, String code, Integer scene) {
return selectOne(new LambdaQueryWrapperX<SmsCodeDO>() return selectOne(new QueryWrapperX<SmsCodeDO>()
.eq(SmsCodeDO::getCode, mobile) .eq("mobile", mobile)
.eqIfPresent(SmsCodeDO::getScene, scene) .eqIfPresent("scene", scene)
.eqIfPresent(SmsCodeDO::getCode, code) .eqIfPresent("code", code)
.orderByDesc(SmsCodeDO::getId) .orderByDesc("id")
.last(SqlConstants.LIMIT1)); .limit1());
} }
} }