//build the proxy handler
handler = new ProxyConnection(this,con);
//set up the interceptor chain
- String[] proxies = getPoolProperties().getJdbcInterceptorsAsArray();
+ PoolProperties.InterceptorDefinition[] proxies = getPoolProperties().getJdbcInterceptorsAsArray();
for (int i=proxies.length-1; i>=0; i--) {
try {
JdbcInterceptor interceptor =
- (JdbcInterceptor) Class.forName(proxies[i], true, //should this be the class loader?
- Thread.currentThread().getContextClassLoader()).newInstance();
+ (JdbcInterceptor) Class.forName(proxies[i].getClassName(), true, Thread.currentThread().getContextClassLoader()).newInstance(); //should this be the class loader?
+ interceptor.setProperties(proxies[i].getProperties());
interceptor.setNext(handler);
interceptor.reset(this, con); //initialize
handler = interceptor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorProperty;
/**
* @author Filip Hanik
public static final String CLOSE_VAL = "close";
public static final String TOSTRING_VAL = "toString";
public static final String ISCLOSED_VAL = "isClosed";
-
+
+ protected List<InterceptorProperty> properties = null;
+
private JdbcInterceptor next = null;
public JdbcInterceptor() {
* @param con - the pooled connection
*/
public abstract void reset(ConnectionPool parent, PooledConnection con);
+
+ public List<InterceptorProperty> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(List<InterceptorProperty> properties) {
+ this.properties = properties;
+ }
+
}
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
+
/**
* @author Filip Hanik
*
private String jdbcInterceptors=null;
private boolean fairQueue = false;
+ private InterceptorDefinition[] interceptors = null;
+
public boolean isFairQueue() {
return fairQueue;
}
return jdbcInterceptors;
}
- public String[] getJdbcInterceptorsAsArray() {
- if (jdbcInterceptors==null) return new String[0];
- else {
- return jdbcInterceptors.split(";");
+ public InterceptorDefinition[] getJdbcInterceptorsAsArray() {
+ if (interceptors == null) {
+ if (jdbcInterceptors==null) {
+ interceptors = new InterceptorDefinition[0];
+ } else {
+ String[] interceptorValues = jdbcInterceptors.split(";");
+ InterceptorDefinition[] definitions = new InterceptorDefinition[interceptorValues.length];
+ for (int i=0; i<interceptorValues.length; i++) {
+ int propIndex = interceptorValues[i].indexOf("(");
+ if (propIndex<0) {
+ definitions[i] = new InterceptorDefinition(interceptorValues[i]);
+ } else {
+ String name = interceptorValues[i].substring(0,propIndex);
+ definitions[i] = new InterceptorDefinition(name);
+ String propsAsString = interceptorValues[i].substring(propIndex+1, interceptorValues[i].length());
+ String[] props = propsAsString.split(",");
+ for (int j=0; j<props.length; j++) {
+ int pidx = props[j].indexOf("=");
+ String propName = props[j].substring(0,pidx);
+ String propValue = props[j].substring(pidx+1);
+ definitions[i].addProperty(new InterceptorProperty(propName,propValue));
+ }
+ }
+ }
+ interceptors = definitions;
+ }
}
+ return interceptors;
}
public void setAccessToUnderlyingConnectionAllowed(boolean
public void setJdbcInterceptors(String jdbcInterceptors) {
this.jdbcInterceptors = jdbcInterceptors;
+ this.interceptors = null;
}
public String toString() {
result = result || (isTestWhileIdle() && getValidationQuery()!=null);
return result;
}
+
+ public static class InterceptorDefinition {
+ protected String className;
+ protected List<InterceptorProperty> properties = new ArrayList<InterceptorProperty>();
+
+ public InterceptorDefinition(String className) {
+ this.className = className;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+ public void addProperty(String name, String value) {
+ InterceptorProperty p = new InterceptorProperty(name,value);
+ addProperty(p);
+ }
+
+ public void addProperty(InterceptorProperty p) {
+ properties.add(p);
+ }
+
+ public List<InterceptorProperty> getProperties() {
+ return properties;
+ }
+ }
+
+ public static class InterceptorProperty {
+ String name;
+ String value;
+ public InterceptorProperty(String name, String value) {
+ this.name = name;
+ this.value = value;
+ }
+ public String getName() {
+ return name;
+ }
+ public String getValue() {
+ return value;
+ }
+ }
+
}