diff --git a/src/main/java/org/dasein/persist/Transaction.java b/src/main/java/org/dasein/persist/Transaction.java index f906cf5..f5b0937 100644 --- a/src/main/java/org/dasein/persist/Transaction.java +++ b/src/main/java/org/dasein/persist/Transaction.java @@ -80,6 +80,10 @@ public class Transaction { * Cache of Execution objects to minimize dynamically created SQL */ static private final Map> eventCache = new ConcurrentHashMap>(8, 0.9f, 1); + /** + * Cache of DataSource instances. JNDI blocks on System properties. + */ + static private final Map dsCache = new ConcurrentHashMap(8, 0.9f, 1); static private final AtomicBoolean maidLaunched = new AtomicBoolean(false); @@ -552,8 +556,20 @@ private synchronized void open(Execution event, String dsn) throws SQLException, if( dsn == null ) { dsn = event.getDataSource(); } + if (dsn == null) { + throw new PersistenceException("No data source name"); + } state = "LOOKING UP"; - ds = (DataSource)ctx.lookup(dsn); + ds = dsCache.get(dsn); + if (ds == null) { + ds = (DataSource)ctx.lookup(dsn); + if (ds != null) { + dsCache.put(dsn, ds); + } + } + if (ds == null) { + throw new PersistenceException("Could not find data source: " + dsn); + } conn = ds.getConnection(); openTime = System.currentTimeMillis(); if( logger.isDebugEnabled() ) {