The Spring Framework

## org.springframework.jdbc.datasource.lookup
Class MapDataSourceLookup

    java.lang.Object
      org.springframework.jdbc.datasource.lookup.MapDataSourceLookup

All Implemented Interfaces:
  DataSourceLookup

    public class MapDataSourceLookup

extends 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(Map dataSources)` Create a new instance of the `MapDataSourceLookup` class.
`MapDataSourceLookup(String dataSourceName, DataSource dataSource)` Create a new instance of the `MapDataSourceLookup` class.

Method Summary
`void` `addDataSource(String dataSourceName, DataSource dataSource)` Add the supplied `DataSource` to the map of `DataSources` maintained by this object.
`DataSource` `getDataSource(String dataSourceName)` Retrieve the DataSource identified by the given name.
`Map` `getDataSources()` Get the `Map` of `DataSources` maintained by this object.
`void` `setDataSources(Map 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(Map 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(String dataSourceName,
                               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(Map 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 Map 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(String dataSourceName,
                              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 DataSource getDataSource(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

The Spring Framework

Copyright © 2002-2008 The Spring Framework.