Class MapDataSourceLookup
- java.lang.Object
- org.springframework.jdbc.datasource.lookup.MapDataSourceLookup
- All Implemented Interfaces:
DataSourceLookup
public class MapDataSourceLookup extends Object implements DataSourceLookup
SimpleDataSourceLookup
implementation that relies on a map for doing lookups.Useful for testing environments or applications that need to match arbitrary
String
names to targetDataSource
objects.- Since:
- 2.0
- Author:
- Costin Leau, Juergen Hoeller, Rick Evans
Constructor Summary
Constructors Constructor Description MapDataSourceLookup()
Create 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDataSource(String dataSourceName, DataSource dataSource)
Add the suppliedDataSource
to the map ofDataSources
maintained by this object.DataSource
getDataSource(String dataSourceName)
Retrieve the DataSource identified by the given name.Map<String,DataSource>
getDataSources()
Get theMap
ofDataSources
maintained by this object.void
setDataSources(Map<String,DataSource> dataSources)
Constructor Detail
MapDataSourceLookup
public MapDataSourceLookup()
Create a new instance of theMapDataSourceLookup
class.
MapDataSourceLookup
public MapDataSourceLookup(Map<String,DataSource> dataSources)
Create a new instance of theMapDataSourceLookup
class.- Parameters:
dataSources
- theMap
ofDataSources
; the keys areStrings
, the values are actualDataSource
instances.
MapDataSourceLookup
public MapDataSourceLookup(String dataSourceName, DataSource dataSource)
Create a new instance of theMapDataSourceLookup
class.- Parameters:
dataSourceName
- the name under which the suppliedDataSource
is to be addeddataSource
- theDataSource
to be added
Method Detail
setDataSources
public void setDataSources(@Nullable Map<String,DataSource> dataSources)
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
public Map<String,DataSource> getDataSources()
- Returns:
- said
Map
ofDataSources
(nevernull
)
addDataSource
public void addDataSource(String dataSourceName, DataSource dataSource)
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
public DataSource getDataSource(String dataSourceName) throws DataSourceLookupFailureException
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