/** * Creates a JuConnUtil wrapper around a JDBC DataSource. * <p> * Allows to specify whether to reuse the same connection all the time. This can be useful * for performance improvements, e.g. in testing contexts... * @param ds DataSource * @param recycleConnection If true, the same connection will be recycled (and never closed!) * @return JuConnUtil */ public static JuConnUtil createByDataSource(final DataSource ds, boolean recycleConnection) { if (!recycleConnection) { return JuConnUtils.createByDataSource(ds); } else { try { final Connection conn = ds.getConnection(); return new AbstractJuConnUtil() { @Override protected void performDbWork(DbWork work) throws SQLException { work.execute(conn); } }; } catch (Exception ex) { throw new JuRuntimeException("Couldn't get Connection from DataSource", ex); } } }