Skip to content

Commit 94eee6a

Browse files
committed
Provide access to AbstractRoutingDataSource's resolved target DataSources
Closes gh-25544
1 parent 96a4e11 commit 94eee6a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.sql.Connection;
2020
import java.sql.SQLException;
21+
import java.util.Collections;
2122
import java.util.HashMap;
2223
import java.util.Map;
2324

@@ -164,6 +165,29 @@ else if (dataSource instanceof String) {
164165
}
165166
}
166167

168+
/**
169+
* Return the resolved target DataSources that this router manages.
170+
* @return an unmodifiable map of resolved lookup keys and DataSources
171+
* @throws IllegalStateException if the target DataSources are not resolved yet
172+
* @since 5.2.9
173+
* @see #setTargetDataSources
174+
*/
175+
public Map<Object, DataSource> getResolvedDataSources() {
176+
Assert.state(this.resolvedDataSources != null, "DataSources not resolved yet - call afterPropertiesSet");
177+
return Collections.unmodifiableMap(this.resolvedDataSources);
178+
}
179+
180+
/**
181+
* Return the resolved default target DataSource, if any.
182+
* @return the default DataSource, or {@code null} if none or not resolved yet
183+
* @since 5.2.9
184+
* @see #setDefaultTargetDataSource
185+
*/
186+
@Nullable
187+
public DataSource getResolvedDefaultDataSource() {
188+
return this.resolvedDefaultDataSource;
189+
}
190+
167191

168192
@Override
169193
public Connection getConnection() throws SQLException {

0 commit comments

Comments
 (0)