Do EnsureContext.setup() call from QueryMapper once

This commit is contained in:
moparisthebest 2014-04-22 16:02:57 -04:00
parent 48e93aaa44
commit 2d9c00e8db

View File

@ -4,6 +4,7 @@ import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.io.*;
import java.lang.reflect.Method;
import java.sql.*;
import java.util.*;
@ -11,6 +12,17 @@ import static com.moparisthebest.jdbc.TryClose.tryClose;
public class QueryMapper implements Closeable {
static {
try{
final Class<?> ensureContext = Class.forName(System.getProperty("QueryMapper.ensureContext.class", "com.gcl.containerless.EnsureContext"));
final Method method = ensureContext.getMethod(System.getProperty("QueryMapper.ensureContext.method", "setup"));
method.invoke(null);
}catch(Throwable e){
// ignore
e.printStackTrace();
}
}
protected final ResultSetMapper cm;
protected final Connection conn;
protected final Context context;
@ -20,7 +32,6 @@ public class QueryMapper implements Closeable {
Context context = null;
if (conn == null && jndiName != null)
try {
//todo: EnsureContext.setup();
context = new InitialContext();
DataSource ds = (DataSource) context.lookup(jndiName);
conn = ds.getConnection();