se.cambio.cds.model.util.sql
Class DataSourceLocator

Package class diagram package DataSourceLocator
java.lang.Object
  extended by se.cambio.cds.model.util.sql.DataSourceLocator

public class DataSourceLocator
extends Object

Caches references to DataSources. It allows to register explicitally a DataSource under a name, and get a reference to it by its name (using JNDI, if not already registered or cached).


Field Summary
static String JNDI_PREFIX
          The recommended JNDI context name for all DataSources: java:comp/env/jdbc/
 
Method Summary
static void addDataSource(String name, DataSource dataSource)
          Allows to register explicitally a DataSource with a given name.
static DataSource getDataSource(String name)
          Gets a reference to the DataSource with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JNDI_PREFIX

public static final String JNDI_PREFIX
The recommended JNDI context name for all DataSources: java:comp/env/jdbc/

See Also:
Constant Field Values
Method Detail

addDataSource

public static void addDataSource(String name,
                                 DataSource dataSource)
Allows to register explicitally a DataSource with a given name. This method should only be used when DataSources are not accessible through JNDI (for example when using an application server providing only servlets and JSP).


getDataSource

public static DataSource getDataSource(String name)
                                throws InternalErrorException
Gets a reference to the DataSource with the given name. If the reference has been explicitally registered (with addDataSource(String, DataSource)) or is cached, it is returned immediatelly. Otherwise, JNDI is used to get a reference to it (caching it for the next time) using the JNDI name: JNDI_PREFIX + name. This allows an easy transition from an application server not providing DataSources registered under JNDI to one providing them.

Throws:
InternalErrorException


Copyright © 2013 Cambio. All Rights Reserved.