Top Description Fields Constructors Methods
org.springframework.jdbc.datasource.lookup

public Class MapDataSourceLookup

extends Object
implements DataSourceLookup
Class Inheritance
All Implemented Interfaces
org.springframework.jdbc.datasource.lookup.DataSourceLookup
Imports
java.util.Collections, .HashMap, .Map, javax.sql.DataSource, org.springframework.lang.Nullable, org.springframework.util.Assert

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.

Authors
Costin Leau, Juergen Hoeller, Rick Evans
Since
2.0

Field Summary

Modifier and TypeField and Description
private final Map<String, DataSource>

Constructor Summary

AccessConstructor and Description
public
MapDataSourceLookup()

Create a new instance of the MapDataSourceLookup class.

public
MapDataSourceLookup(Map<String, DataSource>
the Map of DataSources; the keys are Strings, the values are actual DataSource instances.
dataSources
)

Create a new instance of the MapDataSourceLookup class.

public
MapDataSourceLookup(String
the name under which the supplied DataSource is to be added
dataSourceName
,
DataSource
the DataSource to be added
dataSource
)

Create a new instance of the MapDataSourceLookup class.

Method Summary

Modifier and TypeMethod and Description
public void
addDataSource(String
the name under which the supplied DataSource is to be added
dataSourceName
,
DataSource
the DataSource to be so added
dataSource
)

Add the supplied DataSource to the map of DataSources maintained by this object.

public DataSource
getDataSource(String
the name of the DataSource
dataSourceName
)

Implements org.springframework.jdbc.datasource.lookup.DataSourceLookup.getDataSource.

Retrieve the DataSource identified by the given name.

public Map<String, DataSource>

Returns:

said Map of DataSources (never null)
getDataSources
()

Get the Map of DataSources maintained by this object.

public void
setDataSources(Map<String, DataSource> dataSources)

Set the Map of DataSources; the keys are Strings, the values are actual DataSource instances.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dataSourcesback to summary
private final Map<String, DataSource> dataSources

Constructor Detail

MapDataSourceLookupback to summary
public MapDataSourceLookup()

Create a new instance of the MapDataSourceLookup class.

MapDataSourceLookupback to summary
public MapDataSourceLookup(Map<String, DataSource> dataSources)

Create a new instance of the MapDataSourceLookup class.

Parameters
dataSources:Map<String, DataSource>

the Map of DataSources; the keys are Strings, the values are actual DataSource instances.

MapDataSourceLookupback to summary
public MapDataSourceLookup(String dataSourceName, DataSource dataSource)

Create a new instance of the MapDataSourceLookup class.

Parameters
dataSourceName:String

the name under which the supplied DataSource is to be added

dataSource:DataSource

the DataSource to be added

Method Detail

addDataSourceback to summary
public void addDataSource(String dataSourceName, DataSource dataSource)

Add the supplied DataSource to the map of DataSources maintained by this object.

Parameters
dataSourceName:String

the name under which the supplied DataSource is to be added

dataSource:DataSource

the DataSource to be so added

getDataSourceback to summary
public DataSource getDataSource(String dataSourceName) throws DataSourceLookupFailureException

Implements org.springframework.jdbc.datasource.lookup.DataSourceLookup.getDataSource.

Doc from org.springframework.jdbc.datasource.lookup.DataSourceLookup.getDataSource.

Retrieve the DataSource identified by the given name.

Parameters
dataSourceName:String

the name of the DataSource

Returns:DataSource

the DataSource (never null)

Annotations
@Override
Exceptions
DataSourceLookupFailureException:
if the lookup failed
getDataSourcesback to summary
public Map<String, DataSource> getDataSources()

Get the Map of DataSources maintained by this object.

The returned Map is unmodifiable.

Returns:Map<String, DataSource>

said Map of DataSources (never null)

setDataSourcesback to summary
public void setDataSources(Map<String, DataSource> dataSources)

Set the Map of DataSources; the keys are Strings, the values are actual DataSource instances.

If the supplied Map is null, then this method call effectively has no effect.

Parameters
dataSources:Map<String, DataSource>

said Map of DataSources