Skip to content

Commit

Permalink
Merge pull request #8 from timf/H2PR
Browse files Browse the repository at this point in the history
cache JNDI lookups
  • Loading branch information
greese committed Feb 21, 2013
2 parents 42abd0b + ec021bf commit 4851669
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/main/java/org/dasein/persist/Transaction.java
Expand Up @@ -80,6 +80,10 @@ public class Transaction {
* Cache of Execution objects to minimize dynamically created SQL
*/
static private final Map<String,Stack<Execution>> eventCache = new ConcurrentHashMap<String, Stack<Execution>>(8, 0.9f, 1);
/**
* Cache of DataSource instances. JNDI blocks on System properties.
*/
static private final Map<String,DataSource> dsCache = new ConcurrentHashMap<String, DataSource>(8, 0.9f, 1);

static private final AtomicBoolean maidLaunched = new AtomicBoolean(false);

Expand Down Expand Up @@ -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() ) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/dasein/persist/jdbc/Loader.java
Expand Up @@ -197,7 +197,9 @@ public Map<String,Object> run(Transaction xaction, Map<String,Object> params) th
}
finally {
try { results.close(); }
catch( SQLException e ) { }
catch( SQLException e ) {
logger.error("Problem closing results: " + e.getMessage(), e);
}
}

long endTimestamp = System.currentTimeMillis();
Expand Down

0 comments on commit 4851669

Please sign in to comment.