@Test public void testOther() throws NamingException { DataSource dataSource = mock( DataSource.class ); when( context.lookup( "jdbc/" + testName ) ).thenReturn( dataSource ); assertEquals( dataSource, DatabaseUtil.getDataSourceFromJndi( testName, context ) ); }
protected static DataSource getDataSourceFromJndi( String dsName, Context ctx ) throws NamingException { if ( Utils.isEmpty( dsName ) ) { throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", String.valueOf( dsName ) ) ); } Object foundDs = FoundDS.get( dsName ); if ( foundDs != null ) { return (DataSource) foundDs; } Object lkup = null; DataSource rtn = null; NamingException firstNe = null; try { lkup = ctx.lookup( dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { firstNe = ignored; } try { lkup = ctx.lookup( "java:" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "java:comp/env/jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } if ( firstNe != null ) { throw firstNe; } throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", dsName ) ); }
DatabaseUtil implements DataSourceProviderInterface { protected static DataSource getDataSourceFromJndi( String dsName, Context ctx ) throws NamingException { if ( Utils.isEmpty( dsName ) ) { throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", String.valueOf( dsName ) ) ); } Object foundDs = FoundDS.get( dsName ); if ( foundDs != null ) { return (DataSource) foundDs; } Object lkup = null; DataSource rtn = null; NamingException firstNe = null; try { lkup = ctx.lookup( dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { firstNe = ignored; } try { lkup = ctx.lookup( "java:" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "java:comp/env/jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } if ( firstNe != null ) { throw firstNe; } throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", dsName ) ); } }
DatabaseUtil implements DataSourceProviderInterface { protected static DataSource getDataSourceFromJndi( String dsName, Context ctx ) throws NamingException { if ( Utils.isEmpty( dsName ) ) { throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", String.valueOf( dsName ) ) ); } Object foundDs = FoundDS.get( dsName ); if ( foundDs != null ) { return (DataSource) foundDs; } Object lkup = null; DataSource rtn = null; NamingException firstNe = null; try { lkup = ctx.lookup( dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { firstNe = ignored; } try { lkup = ctx.lookup( "java:" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "java:comp/env/jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } if ( firstNe != null ) { throw firstNe; } throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", dsName ) ); }  }
DatabaseUtil implements DataSourceProviderInterface { protected static DataSource getDataSourceFromJndi( String dsName, Context ctx ) throws NamingException { if ( Utils.isEmpty( dsName ) ) { throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", String.valueOf( dsName ) ) ); } Object foundDs = FoundDS.get( dsName ); if ( foundDs != null ) { return (DataSource) foundDs; } Object lkup = null; DataSource rtn = null; NamingException firstNe = null; try { lkup = ctx.lookup( dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { firstNe = ignored; } try { lkup = ctx.lookup( "java:" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "java:comp/env/jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } if ( firstNe != null ) { throw firstNe; } throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", dsName ) ); }  static void closeSilently( Connection[] connections ); static void closeSilently( Connection conn ); static void closeSilently( Statement[] statements ); static void closeSilently( Statement st ); @Override DataSource getNamedDataSource( String datasourceName ); @Override DataSource getNamedDataSource( String datasourceName, DatasourceType type ); }
DatabaseUtil implements DataSourceProviderInterface { protected static DataSource getDataSourceFromJndi( String dsName, Context ctx ) throws NamingException { if ( Utils.isEmpty( dsName ) ) { throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", String.valueOf( dsName ) ) ); } Object foundDs = FoundDS.get( dsName ); if ( foundDs != null ) { return (DataSource) foundDs; } Object lkup = null; DataSource rtn = null; NamingException firstNe = null; try { lkup = ctx.lookup( dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { firstNe = ignored; } try { lkup = ctx.lookup( "java:" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "java:comp/env/jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } try { lkup = ctx.lookup( "jdbc/" + dsName ); if ( lkup instanceof DataSource ) { rtn = (DataSource) lkup; FoundDS.put( dsName, rtn ); return rtn; } } catch ( NamingException ignored ) { } if ( firstNe != null ) { throw firstNe; } throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", dsName ) ); }  static void closeSilently( Connection[] connections ); static void closeSilently( Connection conn ); static void closeSilently( Statement[] statements ); static void closeSilently( Statement st ); @Override DataSource getNamedDataSource( String datasourceName ); @Override DataSource getNamedDataSource( String datasourceName, DatasourceType type );  }