From 8403adac90d74d89b03fe288131a36f3aad76f10 Mon Sep 17 00:00:00 2001 From: rbygrave Date: Sat, 30 May 2015 20:54:51 +1200 Subject: [PATCH] #298 - JndiDataSourceLookup assumes java: prefix --- .../server/core/JndiDataSourceLookup.java | 47 ++++++++----------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/avaje/ebeaninternal/server/core/JndiDataSourceLookup.java b/src/main/java/com/avaje/ebeaninternal/server/core/JndiDataSourceLookup.java index 3bd662510..120cce758 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/core/JndiDataSourceLookup.java +++ b/src/main/java/com/avaje/ebeaninternal/server/core/JndiDataSourceLookup.java @@ -11,34 +11,27 @@ import javax.sql.DataSource; */ public class JndiDataSourceLookup { - private static final String DEFAULT_PREFIX = "java:comp/env/jdbc/"; + public JndiDataSourceLookup() { + } - public JndiDataSourceLookup() { - } - - /** - * Return the DataSource by JNDI lookup. - *

- * If name is null the 'default' dataSource is returned. - *

- */ - public DataSource lookup(String jndiName) { + /** + * Return the DataSource by JNDI lookup. + *

+ * If name is null the 'default' dataSource is returned. + *

+ */ + public DataSource lookup(String jndiName) { - try { - - if (!jndiName.startsWith("java:")){ - jndiName = DEFAULT_PREFIX + jndiName; - } - - Context ctx = new InitialContext(); - DataSource ds = (DataSource) ctx.lookup(jndiName); - if (ds == null) { - throw new PersistenceException("JNDI DataSource [" + jndiName + "] not found?"); - } - return ds; + 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); - } - } + } catch (NamingException ex) { + throw new PersistenceException(ex); + } + } }