Class MapDataSourceLookup
java.lang.Object
org.springframework.jdbc.datasource.lookup.MapDataSourceLookup
- All Implemented Interfaces:
DataSourceLookup
Simple
DataSourceLookup implementation that relies on a map for doing lookups.
Useful for testing environments or applications that need to match arbitrary
String names to target DataSource objects.
- Since:
- 2.0
- Author:
- Costin Leau, Juergen Hoeller, Rick Evans
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance of theMapDataSourceLookupclass.MapDataSourceLookup(String dataSourceName, DataSource dataSource) Create a new instance of theMapDataSourceLookupclass.MapDataSourceLookup(Map<String, DataSource> dataSources) Create a new instance of theMapDataSourceLookupclass. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataSource(String dataSourceName, DataSource dataSource) Add the suppliedDataSourceto the map ofDataSourcesmaintained by this object.getDataSource(String dataSourceName) Retrieve the DataSource identified by the given name.Get theMapofDataSourcesmaintained by this object.voidsetDataSources(@Nullable Map<String, DataSource> dataSources)
-
Constructor Details
-
MapDataSourceLookup
public MapDataSourceLookup()Create a new instance of theMapDataSourceLookupclass. -
MapDataSourceLookup
Create a new instance of theMapDataSourceLookupclass.- Parameters:
dataSources- theMapofDataSources; the keys areStrings, the values are actualDataSourceinstances.
-
MapDataSourceLookup
Create a new instance of theMapDataSourceLookupclass.- Parameters:
dataSourceName- the name under which the suppliedDataSourceis to be addeddataSource- theDataSourceto be added
-
-
Method Details
-
setDataSources
Set theMapofDataSources; the keys areStrings, the values are actualDataSourceinstances.If the supplied
Mapisnull, then this method call effectively has no effect.- Parameters:
dataSources- saidMapofDataSources
-
getDataSources
- Returns:
- said
MapofDataSources(nevernull)
-
addDataSource
Add the suppliedDataSourceto the map ofDataSourcesmaintained by this object.- Parameters:
dataSourceName- the name under which the suppliedDataSourceis to be addeddataSource- theDataSourceto be so added
-
getDataSource
Description copied from interface:DataSourceLookupRetrieve the DataSource identified by the given name.- Specified by:
getDataSourcein interfaceDataSourceLookup- Parameters:
dataSourceName- the name of the DataSource- Returns:
- the DataSource (never
null) - Throws:
DataSourceLookupFailureException- if the lookup failed
-