Java Code Examples for org.apache.tomcat.jdbc.pool.JdbcInterceptor

The following examples show how to use org.apache.tomcat.jdbc.pool.JdbcInterceptor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Tomcat7.0.67   Source File: ResetAbandonedTimer.java    License: Apache License 2.0 6 votes vote down vote up
public boolean resetTimer() {
    boolean result = false;
    JdbcInterceptor interceptor = this.getNext();
    while (interceptor!=null && result==false) {
        if (interceptor instanceof ProxyConnection) {
            PooledConnection con = ((ProxyConnection)interceptor).getConnection();
            if (con!=null) {
                con.setTimestamp(System.currentTimeMillis());
                result = true;
            } else {
                break;
            }
        }
        interceptor = interceptor.getNext();
    }
    return result;
}
 
Example 2
Source Project: tomcatsrc   Source File: ResetAbandonedTimer.java    License: Apache License 2.0 6 votes vote down vote up
public boolean resetTimer() {
    boolean result = false;
    JdbcInterceptor interceptor = this.getNext();
    while (interceptor!=null && result==false) {
        if (interceptor instanceof ProxyConnection) {
            PooledConnection con = ((ProxyConnection)interceptor).getConnection();
            if (con!=null) {
                con.setTimestamp(System.currentTimeMillis());
                result = true;
            } else {
                break;
            }
        }
        interceptor = interceptor.getNext();
    }
    return result;
}
 
Example 3
Source Project: Tomcat8-Source-Read   Source File: TestStatementCache.java    License: MIT License 5 votes vote down vote up
/**
 * Helper method that finds interceptor instance in interceptor chain of a
 * proxied class.
 *
 * @param proxy
 *            Proxy class
 * @param clazz
 *            Interceptor class that we are looking for
 * @return Instance of <code>clazz</code>
 */
private static <T extends JdbcInterceptor> T findInterceptor(Object proxy,
        Class<T> clazz) {
    JdbcInterceptor interceptor = (JdbcInterceptor) Proxy
            .getInvocationHandler(proxy);
    while (interceptor != null) {
        if (clazz.isInstance(interceptor)) {
            return clazz.cast(interceptor);
        }
        interceptor = interceptor.getNext();
    }
    return null;
}
 
Example 4
Source Project: Tomcat7.0.67   Source File: TestStatementCache.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that finds interceptor instance in interceptor chain of a
 * proxied class.
 *
 * @param proxy
 *            Proxy class
 * @param clazz
 *            Interceptor class that we are looking for
 * @return Instance of <code>clazz</code>
 */
private static <T extends JdbcInterceptor> T findInterceptor(Object proxy,
        Class<T> clazz) {
    JdbcInterceptor interceptor = (JdbcInterceptor) Proxy
            .getInvocationHandler(proxy);
    while (interceptor != null) {
        if (clazz.isInstance(interceptor)) {
            return clazz.cast(interceptor);
        }
        interceptor = interceptor.getNext();
    }
    return null;
}
 
Example 5
Source Project: tomcatsrc   Source File: TestStatementCache.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that finds interceptor instance in interceptor chain of a
 * proxied class.
 *
 * @param proxy
 *            Proxy class
 * @param clazz
 *            Interceptor class that we are looking for
 * @return Instance of <code>clazz</code>
 */
private static <T extends JdbcInterceptor> T findInterceptor(Object proxy,
        Class<T> clazz) {
    JdbcInterceptor interceptor = (JdbcInterceptor) Proxy
            .getInvocationHandler(proxy);
    while (interceptor != null) {
        if (clazz.isInstance(interceptor)) {
            return clazz.cast(interceptor);
        }
        interceptor = interceptor.getNext();
    }
    return null;
}
 
Example 6
Source Project: aws-xray-sdk-java   Source File: TracingInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    //get the name of the method for comparison
    final String name = method.getName();
    //was close invoked?
    boolean close = compare(JdbcInterceptor.CLOSE_VAL, name);
    //allow close to be called multiple times
    if (close && closed) {
        return null;
    }
    //are we calling isClosed?
    if (compare(JdbcInterceptor.ISCLOSED_VAL, name)) {
        return Boolean.valueOf(closed);
    }
    //if we are calling anything else, bail out
    if (closed) {
        throw new SQLException("Statement closed.");
    }
    //check to see if we are about to execute a query
    final boolean process = isExecute(method);
    Object result = null;
    Subsegment subsegment = null;
    if (process) {
        subsegment = AWSXRay.beginSubsegment(hostname);
    }
    try {
        if (process && null != subsegment) {
            subsegment.putAllSql(additionalParams);
            subsegment.setNamespace(Namespace.REMOTE.toString());
        }
        result = method.invoke(delegate, args); //execute the query
    } catch (Throwable t) {
        if (null != subsegment) {
            subsegment.addException(t);
        }
        if (t instanceof InvocationTargetException && t.getCause() != null) {
            throw t.getCause();
        } else {
            throw t;
        }
    } finally {
        if (process && null != subsegment) {
            AWSXRay.endSubsegment();
        }
    }

    //perform close cleanup
    if (close) {
        closed = true;
        delegate = null;
    }

    return result;
}
 
Example 7
Source Project: aws-xray-sdk-java   Source File: TracingInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    //get the name of the method for comparison
    final String name = method.getName();
    //was close invoked?
    boolean close = compare(JdbcInterceptor.CLOSE_VAL, name);
    //allow close to be called multiple times
    if (close && closed) {
        return null;
    }
    //are we calling isClosed?
    if (compare(JdbcInterceptor.ISCLOSED_VAL, name)) {
        return Boolean.valueOf(closed);
    }
    //if we are calling anything else, bail out
    if (closed) {
        throw new SQLException("Statement closed.");
    }
    //check to see if we are about to execute a query
    final boolean process = isExecute(method);
    Object result = null;
    Subsegment subsegment = null;
    if (process) {
        subsegment = AWSXRay.beginSubsegment(hostname);
    }
    try {
        if (process && null != subsegment) {
            subsegment.putAllSql(additionalParams);
            subsegment.setNamespace(Namespace.REMOTE.toString());
        }
        result = method.invoke(delegate, args); //execute the query
    } catch (Throwable t) {
        if (null != subsegment) {
            subsegment.addException(t);
        }
        if (t instanceof InvocationTargetException && t.getCause() != null) {
            throw t.getCause();
        } else {
            throw t;
        }
    } finally {
        if (process && null != subsegment) {
            AWSXRay.endSubsegment();
        }
    }

    //perform close cleanup
    if (close) {
        closed = true;
        delegate = null;
    }

    return result;
}