优化配置中心,增加 ConfigFrameworkDAO 的抽象,进一步解耦 framework
parent
092ec983a3
commit
8e67753a4b
File diff suppressed because one or more lines are too long
@ -0,0 +1,28 @@
|
|||||||
|
package cn.iocoder.dashboard.framework.apollo.internals;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config.InfConfigDO;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置 Framework DAO 接口
|
||||||
|
*/
|
||||||
|
public interface ConfigFrameworkDAO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询是否存在比 maxUpdateTime 更新记录更晚的配置
|
||||||
|
*
|
||||||
|
* @param maxUpdateTime 最大更新时间
|
||||||
|
* @return 是否存在
|
||||||
|
*/
|
||||||
|
boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询配置列表
|
||||||
|
*
|
||||||
|
* @return 配置列表
|
||||||
|
*/
|
||||||
|
List<InfConfigDO> getSysConfigList();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.infra.dal.mysql.dao.config;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.framework.apollo.internals.ConfigFrameworkDAO;
|
||||||
|
import cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config.InfConfigDO;
|
||||||
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConfigFrameworkDAO 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class InfConfigDAOImpl implements ConfigFrameworkDAO {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
public InfConfigDAOImpl(String jdbcUrl, String username, String password) {
|
||||||
|
DataSource dataSource = new DriverManagerDataSource(jdbcUrl, username, password);
|
||||||
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) {
|
||||||
|
return jdbcTemplate.query("SELECT id FROM inf_config WHERE update_time > ? LIMIT 1",
|
||||||
|
ResultSet::next, maxUpdateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<InfConfigDO> getSysConfigList() {
|
||||||
|
return jdbcTemplate.query("SELECT `key`, `value`, update_time, deleted FROM inf_config", new BeanPropertyRowMapper<>(InfConfigDO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue