Skip to content

Commit 6ae84c6

Browse files
author
taochen
committed
forceSwitch support to create null config dataSource
1 parent 8d89189 commit 6ae84c6

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

dal-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.ctrip.platform</groupId>
66
<artifactId>dal-client</artifactId>
7-
<version>1.17.6</version>
7+
<version>1.17.7</version>
88
<properties>
99
<ver.version>${project.version}</ver.version>
1010
<javax-persistence-version>1.0.2</javax-persistence-version>

dal-client/src/main/java/com/ctrip/platform/dal/dao/configure/IDataSourceConfigureProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public interface IDataSourceConfigureProvider {
44
// get datasource configure from local cache
5-
IDataSourceConfigure getDataSourceConfigure() throws Exception;
5+
IDataSourceConfigure getDataSourceConfigure();
66

77
// load datasource configure from configure center
88
IDataSourceConfigure forceLoadDataSourceConfigure();

dal-client/src/main/java/com/ctrip/platform/dal/dao/datasource/DataSourceLocator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@ public class DataSourceLocator {
2525

2626
private DataSourceConfigureProvider provider;
2727

28+
private boolean isForceSwitch = false;
29+
2830
public DataSourceLocator(DataSourceConfigureProvider provider) {
2931
this.provider = provider;
3032
}
3133

34+
public DataSourceLocator(DataSourceConfigureProvider provider, boolean isForceSwitch) {
35+
this.provider = provider;
36+
this.isForceSwitch = isForceSwitch;
37+
}
38+
3239
// to be refactored
3340
public static boolean containsKey(String name) {
3441
return cache.containsKey(name);
@@ -75,7 +82,7 @@ public DataSource getDataSource(String name) throws Exception {
7582

7683
private DataSource createDataSource(String name) throws SQLException {
7784
IDataSourceConfigure config = provider.getDataSourceConfigure(name);
78-
if (config == null) {
85+
if (config == null && !isForceSwitch) {
7986
throw new SQLException("Can not find connection configure for " + name);
8087
}
8188

dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/ModifyDataSourceConfigureProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010
public class ModifyDataSourceConfigureProvider implements IDataSourceConfigureProvider {
1111
@Override
12-
public IDataSourceConfigure getDataSourceConfigure() throws Exception {
13-
throw new Exception();
12+
public IDataSourceConfigure getDataSourceConfigure() {
13+
throw new RuntimeException();
1414
}
1515

1616
@Override

0 commit comments

Comments
 (0)