Skip to content

Commit

Permalink
forceSwitch support to create null config dataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
taochen committed Aug 27, 2019
1 parent 8d89189 commit 6ae84c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dal-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ctrip.platform</groupId>
<artifactId>dal-client</artifactId>
<version>1.17.6</version>
<version>1.17.7</version>
<properties>
<ver.version>${project.version}</ver.version>
<javax-persistence-version>1.0.2</javax-persistence-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public interface IDataSourceConfigureProvider {
// get datasource configure from local cache
IDataSourceConfigure getDataSourceConfigure() throws Exception;
IDataSourceConfigure getDataSourceConfigure();

// load datasource configure from configure center
IDataSourceConfigure forceLoadDataSourceConfigure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ public class DataSourceLocator {

private DataSourceConfigureProvider provider;

private boolean isForceSwitch = false;

public DataSourceLocator(DataSourceConfigureProvider provider) {
this.provider = provider;
}

public DataSourceLocator(DataSourceConfigureProvider provider, boolean isForceSwitch) {
this.provider = provider;
this.isForceSwitch = isForceSwitch;
}

// to be refactored
public static boolean containsKey(String name) {
return cache.containsKey(name);
Expand Down Expand Up @@ -75,7 +82,7 @@ public DataSource getDataSource(String name) throws Exception {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
public class ModifyDataSourceConfigureProvider implements IDataSourceConfigureProvider {
@Override
public IDataSourceConfigure getDataSourceConfigure() throws Exception {
throw new Exception();
public IDataSourceConfigure getDataSourceConfigure() {
throw new RuntimeException();
}

@Override
Expand Down

0 comments on commit 6ae84c6

Please sign in to comment.