All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebeaninternal.server.core.JndiDataSourceLookup Maven / Gradle / Ivy

There is a newer version: 15.8.1
Show newest version
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