Skip to content

Commit

Permalink
disable query dal config
Browse files Browse the repository at this point in the history
  • Loading branch information
qifanwang committed Sep 24, 2024
1 parent 99abb22 commit bdccfaf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ctrip.xpipe.redis.console.ds;

import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import com.ctrip.xpipe.redis.checker.config.impl.CommonConfigBean;
import com.ctrip.xpipe.redis.console.model.ConfigTblDao;
import com.ctrip.xpipe.redis.console.model.ConfigTblEntity;
import com.ctrip.xpipe.spring.AbstractProfile;
Expand All @@ -12,8 +13,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.unidal.dal.jdbc.DalException;
import org.unidal.dal.jdbc.datasource.DataSource;
import org.unidal.dal.jdbc.datasource.DataSourceManager;
import org.unidal.lookup.ContainerLoader;
Expand All @@ -23,8 +24,10 @@
@MapperScan("com.ctrip.xpipe.redis.console.mapper")
@EnableTransactionManagement
public class MybatisDataSourceConfig {

private static final Logger logger = LoggerFactory.getLogger(MybatisDataSourceConfig.class);
private XPipeDataSource dataSource;
private CommonConfigBean commonConfigBean = new CommonConfigBean();

@Bean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() throws Exception {
Expand All @@ -35,13 +38,15 @@ public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() throws Except

@Bean
public javax.sql.DataSource dataSource() throws Exception {
try {
// 强制查询使Xpipe DataSource初始化
ConfigTblDao configTblDao = ContainerLoader.getDefaultContainer().lookup(ConfigTblDao.class);
configTblDao.findByPK(1L, ConfigTblEntity.READSET_FULL);
} catch (ComponentLookupException | DalException e) {
logger.error("[MybatisDataSourceConfig]", e);

if(commonConfigBean.disableDb()) {
// if disableDb is true, datasource is useless, only for autowired
return new SimpleDriverDataSource();
}
// 强制查询使Xpipe DataSource初始化
ConfigTblDao configTblDao = ContainerLoader.getDefaultContainer().lookup(ConfigTblDao.class);
configTblDao.findByPK(1L, ConfigTblEntity.READSET_FULL);

XPipeDataSource dataSource = tryGetXpipeDataSource();
if (dataSource == null) {
logger.info("[mybatisSqlSessionFactoryBean] no xpipe datasource found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class XpipeDataSourceProvider implements DataSourceProvider, LogEnabled,
private String m_baseDirRef;
private String m_defaultBaseDir;
private DataSourceProvider m_delegate;

private org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());

private static final String qconfigDataSourceProviderClass =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public PersistenceCacheWithoutDB(ConsoleConfig config, CheckerConsoleService ser
}

protected String getConsoleAddress() {
return consoleConfig.getConsoleDomain();
return consoleConfig.getConsoleNoDbDomain();
}

}

0 comments on commit bdccfaf

Please sign in to comment.