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
ConstructorDescriptionCreate a new instance of theMapDataSourceLookup
class.MapDataSourceLookup
(String dataSourceName, DataSource dataSource) Create a new instance of theMapDataSourceLookup
class.MapDataSourceLookup
(Map<String, DataSource> dataSources) Create a new instance of theMapDataSourceLookup
class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDataSource
(String dataSourceName, DataSource dataSource) Add the suppliedDataSource
to the map ofDataSources
maintained by this object.getDataSource
(String dataSourceName) Retrieve the DataSource identified by the given name.Get theMap
ofDataSources
maintained by this object.void
setDataSources
(@Nullable Map<String, DataSource> dataSources)
-
Constructor Details
-
MapDataSourceLookup
public MapDataSourceLookup()Create a new instance of theMapDataSourceLookup
class. -
MapDataSourceLookup
Create a new instance of theMapDataSourceLookup
class.- Parameters:
dataSources
- theMap
ofDataSources
; the keys areStrings
, the values are actualDataSource
instances.
-
MapDataSourceLookup
Create a new instance of theMapDataSourceLookup
class.- Parameters:
dataSourceName
- the name under which the suppliedDataSource
is to be addeddataSource
- theDataSource
to be added
-
-
Method Details
-
setDataSources
Set theMap
ofDataSources
; the keys areStrings
, the values are actualDataSource
instances.If the supplied
Map
isnull
, then this method call effectively has no effect.- Parameters:
dataSources
- saidMap
ofDataSources
-
getDataSources
- Returns:
- said
Map
ofDataSources
(nevernull
)
-
addDataSource
Add the suppliedDataSource
to the map ofDataSources
maintained by this object.- Parameters:
dataSourceName
- the name under which the suppliedDataSource
is to be addeddataSource
- theDataSource
to be so added
-
getDataSource
Description copied from interface:DataSourceLookup
Retrieve the DataSource identified by the given name.- Specified by:
getDataSource
in interfaceDataSourceLookup
- Parameters:
dataSourceName
- the name of the DataSource- Returns:
- the DataSource (never
null
) - Throws:
DataSourceLookupFailureException
- if the lookup failed
-