diff --git a/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/QueryMapper.java b/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/QueryMapper.java index 80953ea..fa4a51d 100644 --- a/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/QueryMapper.java +++ b/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/QueryMapper.java @@ -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();