Skip to content

Commit

Permalink
add filter for DalIgniteValidateLoadConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
qifanwang committed Sep 25, 2024
1 parent 3fad725 commit cbe9827
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
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.jdbc.datasource.AbstractDataSource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.unidal.dal.jdbc.datasource.DataSource;
import org.unidal.dal.jdbc.datasource.DataSourceManager;
import org.unidal.lookup.ContainerLoader;

import java.sql.Connection;
import java.sql.SQLException;

@Configuration
@Profile(AbstractProfile.PROFILE_NAME_PRODUCTION)
@MapperScan("com.ctrip.xpipe.redis.console.mapper")
Expand All @@ -27,6 +30,7 @@ public class MybatisDataSourceConfig {

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

private CommonConfigBean commonConfigBean = new CommonConfigBean();

@Bean
Expand All @@ -40,8 +44,8 @@ public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() throws Except
public javax.sql.DataSource dataSource() throws Exception {

if(commonConfigBean.disableDb()) {
// if disableDb is true, datasource is useless, only for autowired
return new SimpleDriverDataSource();
// if disableDb is true, set a fake datasource, only for autowired.
return makeFakeDataSource();
}
// 强制查询使Xpipe DataSource初始化
ConfigTblDao configTblDao = ContainerLoader.getDefaultContainer().lookup(ConfigTblDao.class);
Expand Down Expand Up @@ -84,4 +88,17 @@ private XPipeDataSource tryGetXpipeDataSource() {
return this.dataSource;
}
}

private javax.sql.DataSource makeFakeDataSource() {
return new AbstractDataSource() {
@Override
public Connection getConnection() throws SQLException {
throw new SQLException("This is a fake datasource");
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
throw new SQLException("This is a fake datasource");
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ctrip.xpipe.redis.console.ds;

import com.ctrip.xpipe.datasource.DataSourceFactory;
import com.ctrip.xpipe.redis.checker.config.impl.CommonConfigBean;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.LogEnabled;
import org.slf4j.Logger;
Expand Down Expand Up @@ -34,6 +35,8 @@ public class XPipeDataSource extends ContainerHolder implements DataSource, LogE
private static final String ctripDalDataSourceFactory =
"com.ctrip.xpipe.service.datasource.CtripDalDataSourceFactory";

private CommonConfigBean commonConfigBean = new CommonConfigBean();

private static boolean ctripDataSourceEnabled =
ClassUtils.isPresent(ctripDalDataSource, XPipeDataSource.class.getClassLoader());

Expand All @@ -52,7 +55,7 @@ public DataSourceDescriptor getDescriptor() {

@Override
public void initialize(DataSourceDescriptor descriptor) {
if (ctripDataSourceEnabled) {
if (ctripDataSourceEnabled && !commonConfigBean.disableDb()) {
try {
m_factory = (DataSourceFactory)(Class.forName(ctripDalDataSourceFactory).newInstance());
Class<?> clazz = Class.forName(ctripDalDataSource);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ctrip.xpipe.redis.console.spring;

import com.ctrip.xpipe.redis.checker.spring.ConsoleDisableDbCondition;
import com.ctrip.xpipe.redis.checker.spring.ConsoleServerMode;
import com.ctrip.xpipe.redis.checker.spring.ConsoleServerModeCondition;
import com.ctrip.xpipe.redis.checker.spring.DisableDbMode;
import com.ctrip.xpipe.spring.AbstractProfile;
import org.springframework.context.annotation.ComponentScan;
Expand All @@ -13,6 +15,7 @@
@DisableDbMode(false)
@ComponentScan(basePackages = {"com.ctrip.xpipe.service.ignite"})
@Profile(AbstractProfile.PROFILE_NAME_PRODUCTION)
@ConsoleServerMode(ConsoleServerModeCondition.SERVER_MODE.CONSOLE)
public class DalIgniteValidateLoadConfig {
// only config not set disable db, then laod com.ctrip.xpipe.service.ignite.DalIgniteValidate
}

0 comments on commit cbe9827

Please sign in to comment.