Spring Framework

org.springframework.jdbc.datasource.lookup
Class MapDataSourceLookup

java.lang.Object
  extended by org.springframework.jdbc.datasource.lookup.MapDataSourceLookup
All Implemented Interfaces:
DataSourceLookup

public class MapDataSourceLookup
extends java.lang.Object
implements 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
MapDataSourceLookup()
          Create a new instance of the MapDataSourceLookup class.
MapDataSourceLookup(java.util.Map<java.lang.String,javax.sql.DataSource> dataSources)
          Create a new instance of the MapDataSourceLookup class.
MapDataSourceLookup(java.lang.String dataSourceName, javax.sql.DataSource dataSource)
          Create a new instance of the MapDataSourceLookup class.
 
Method Summary
 void addDataSource(java.lang.String dataSourceName, javax.sql.DataSource dataSource)
          Add the supplied DataSource to the map of DataSources maintained by this object.
 javax.sql.DataSource getDataSource(java.lang.String dataSourceName)
          Retrieve the DataSource identified by the given name.
 java.util.Map<java.lang.String,javax.sql.DataSource> getDataSources()
          Get the Map of DataSources maintained by this object.
 void setDataSources(java.util.Map<java.lang.String,javax.sql.DataSource> dataSources)
          Set the Map of DataSources; the keys are Strings, the values are actual DataSource instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapDataSourceLookup

public MapDataSourceLookup()
Create a new instance of the MapDataSourceLookup class.


MapDataSourceLookup

public MapDataSourceLookup(java.util.Map<java.lang.String,javax.sql.DataSource> dataSources)
Create a new instance of the MapDataSourceLookup class.

Parameters:
dataSources - the Map of DataSources; the keys are Strings, the values are actual DataSource instances.

MapDataSourceLookup

public MapDataSourceLookup(java.lang.String dataSourceName,
                           javax.sql.DataSource dataSource)
Create a new instance of the MapDataSourceLookup class.

Parameters:
dataSourceName - the name under which the supplied DataSource is to be added
dataSource - the DataSource to be added
Method Detail

setDataSources

public void setDataSources(java.util.Map<java.lang.String,javax.sql.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 - said Map of DataSources

getDataSources

public java.util.Map<java.lang.String,javax.sql.DataSource> getDataSources()
Get the Map of DataSources maintained by this object.

The returned Map is unmodifiable.

Returns:
said Map of DataSources (never null)

addDataSource

public void addDataSource(java.lang.String dataSourceName,
                          javax.sql.DataSource dataSource)
Add the supplied DataSource to the map of DataSources maintained by this object.

Parameters:
dataSourceName - the name under which the supplied DataSource is to be added
dataSource - the DataSource to be so added

getDataSource

public javax.sql.DataSource getDataSource(java.lang.String dataSourceName)
                                   throws DataSourceLookupFailureException
Description copied from interface: DataSourceLookup
Retrieve the DataSource identified by the given name.

Specified by:
getDataSource in interface DataSourceLookup
Parameters:
dataSourceName - the name of the DataSource
Returns:
the DataSource (never null)
Throws:
DataSourceLookupFailureException - if the lookup failed

Spring Framework