io.ebeaninternal.server.core.JndiDataSourceLookup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ebean Show documentation
Show all versions of ebean Show documentation
composite of common runtime dependencies for all platforms
package io.ebeaninternal.server.core;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.PersistenceException;
import javax.sql.DataSource;
/**
* Helper to lookup a DataSource from JNDI.
*/
public class JndiDataSourceLookup {
public JndiDataSourceLookup() {
}
/**
* Return the DataSource by JNDI lookup.
*
* If name is null the 'default' dataSource is returned.
*
*/
public DataSource lookup(String jndiName) {
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiName);
if (ds == null) {
throw new PersistenceException("JNDI DataSource [" + jndiName + "] not found?");
}
return ds;
} catch (NamingException ex) {
throw new PersistenceException(ex);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy