Search in sources :

Example 1 with SQLTraceRecord

use of org.glassfish.api.jdbc.SQLTraceRecord in project Payara by payara.

the class ProfiledConnectionWrapper40 method getProxyObject.

// TODO refactor this method and move to a higher level
private <T> T getProxyObject(final Object actualObject, Class<T>[] ifaces) throws Exception {
    T result;
    InvocationHandler ih = new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            SQLTraceRecord record = new SQLTraceRecord();
            record.setMethodName(method.getName());
            record.setParams(args);
            record.setClassName(actualObject.getClass().getName());
            record.setThreadName(Thread.currentThread().getName());
            record.setThreadID(Thread.currentThread().getId());
            record.setTimeStamp(System.currentTimeMillis());
            try {
                long startTime = System.currentTimeMillis();
                Object methodResult = method.invoke(actualObject, args);
                record.setExecutionTime(System.currentTimeMillis() - startTime);
                return methodResult;
            } catch (InvocationTargetException ex) {
                Throwable cause = ex.getCause();
                if (cause != null) {
                    throw cause;
                } else {
                    throw ex;
                }
            } finally {
                sqlTraceDelegator.sqlTrace(record);
            }
        }
    };
    result = (T) Proxy.newProxyInstance(actualObject.getClass().getClassLoader(), ifaces, ih);
    return result;
}
Also used : SQLTraceRecord(org.glassfish.api.jdbc.SQLTraceRecord) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with SQLTraceRecord

use of org.glassfish.api.jdbc.SQLTraceRecord in project Payara by payara.

the class JdbcObjectsFactory method getProxyObject.

protected <T> T getProxyObject(final Object actualObject, Class<T>[] ifaces, final SQLTraceDelegator sqlTraceDelegator) throws Exception {
    T result;
    InvocationHandler ih = new InvocationHandler() {

        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            SQLTraceRecord record = new SQLTraceRecord();
            record.setMethodName(method.getName());
            record.setParams(args);
            record.setClassName(actualObject.getClass().getName());
            record.setThreadName(Thread.currentThread().getName());
            record.setThreadID(Thread.currentThread().getId());
            record.setTimeStamp(System.currentTimeMillis());
            long startTime = System.currentTimeMillis();
            Object methodResult = method.invoke(actualObject, args);
            record.setExecutionTime(System.currentTimeMillis() - startTime);
            sqlTraceDelegator.sqlTrace(record);
            return methodResult;
        }
    };
    result = (T) Proxy.newProxyInstance(actualObject.getClass().getClassLoader(), ifaces, ih);
    return result;
}
Also used : SQLTraceRecord(org.glassfish.api.jdbc.SQLTraceRecord) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 3 with SQLTraceRecord

use of org.glassfish.api.jdbc.SQLTraceRecord in project Payara by payara.

the class ProfiledConnectionWrapper30 method getProxyObject.

// TODO refactor this method and move to a higher level
private <T> T getProxyObject(final Object actualObject, Class<T>[] ifaces) throws Exception {
    T result;
    InvocationHandler ih = new InvocationHandler() {

        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            SQLTraceRecord record = new SQLTraceRecord();
            record.setMethodName(method.getName());
            record.setParams(args);
            record.setClassName(actualObject.getClass().getName());
            record.setThreadName(Thread.currentThread().getName());
            record.setThreadID(Thread.currentThread().getId());
            record.setTimeStamp(System.currentTimeMillis());
            try {
                long startTime = System.currentTimeMillis();
                Object methodResult = method.invoke(actualObject, args);
                record.setExecutionTime(System.currentTimeMillis() - startTime);
                return methodResult;
            } catch (InvocationTargetException ex) {
                Throwable cause = ex.getCause();
                if (cause != null) {
                    throw cause;
                } else {
                    throw ex;
                }
            } finally {
                sqlTraceDelegator.sqlTrace(record);
            }
        }
    };
    result = (T) Proxy.newProxyInstance(actualObject.getClass().getClassLoader(), ifaces, ih);
    return result;
}
Also used : SQLTraceRecord(org.glassfish.api.jdbc.SQLTraceRecord) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationHandler (java.lang.reflect.InvocationHandler)3 Method (java.lang.reflect.Method)3 SQLTraceRecord (org.glassfish.api.jdbc.SQLTraceRecord)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2