// Path: src/main/java/com/github/gquintana/metrics/proxy/MethodInvocation.java
// public final class MethodInvocation<T> {
// 
//     /**
//      * Target (real) object
//      */
//     private final T delegate;
//     /**
//      * Proxy
//      */
//     private final Object proxy;
//     /**
//      * Method
//      */
//     private final Method method;
//     /**
//      * Invocation arguments
//      */
//     private final Object[] args;
// 
//     public MethodInvocation(T target, Object proxy, Method method, Object... args) {
//         this.delegate = target;
//         this.proxy = proxy;
//         this.method = method;
//         this.args = args;
//     }
// 
//     public int getArgCount() {
//         return args == null ? 0 : args.length;
//     }
// 
//     public Object getArgAt(int argIndex) {
//         return args[argIndex];
//     }
// 
//     public <R> R getArgAt(int argIndex, Class<R> argType) {
//         return argType.cast(getArgAt(argIndex));
//     }
// 
//     public String getMethodName() {
//         return method.getName();
//     }
// 
//     public Object proceed() throws Throwable {
//         try {
//             return method.invoke(delegate, args);
//         } catch(InvocationTargetException e) {
//             throw e.getTargetException();
//         }
//     }
// 
// }


import com.github.gquintana.metrics.proxy.MethodInvocation;
import java.sql.CallableStatement;
import com.codahale.metrics.Timer;

package com.github.gquintana.metrics.sql;

/*
 * #%L
 * Metrics SQL
 * %%
 * Copyright (C) 2014 Open-Source
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */




/**
 * JDBC Proxy handler for {@link CallableStatement}
 */
public class CallableStatementProxyHandler extends AbstractStatementProxyHandler<CallableStatement> {

    private final Query query;

    public CallableStatementProxyHandler(CallableStatement delegate, JdbcProxyFactory proxyFactory, Query query, Timer.Context lifeTimerContext) {
        super(delegate, CallableStatement.class, proxyFactory, lifeTimerContext);
        this.query = query;
    }


// Path: src/main/java/com/github/gquintana/metrics/proxy/MethodInvocation.java
// public final class MethodInvocation<T> {
// 
//     /**
//      * Target (real) object
//      */
//     private final T delegate;
//     /**
//      * Proxy
//      */
//     private final Object proxy;
//     /**
//      * Method
//      */
//     private final Method method;
//     /**
//      * Invocation arguments
//      */
//     private final Object[] args;
// 
//     public MethodInvocation(T target, Object proxy, Method method, Object... args) {
//         this.delegate = target;
//         this.proxy = proxy;
//         this.method = method;
//         this.args = args;
//     }
// 
//     public int getArgCount() {
//         return args == null ? 0 : args.length;
//     }
// 
//     public Object getArgAt(int argIndex) {
//         return args[argIndex];
//     }
// 
//     public <R> R getArgAt(int argIndex, Class<R> argType) {
//         return argType.cast(getArgAt(argIndex));
//     }
// 
//     public String getMethodName() {
//         return method.getName();
//     }
// 
//     public Object proceed() throws Throwable {
//         try {
//             return method.invoke(delegate, args);
//         } catch(InvocationTargetException e) {
//             throw e.getTargetException();
//         }
//     }
// 
// }


// Path: src/main/java/com/github/gquintana/metrics/sql/CallableStatementProxyHandler.java
import com.github.gquintana.metrics.proxy.MethodInvocation;
import java.sql.CallableStatement;
import com.codahale.metrics.Timer;

package com.github.gquintana.metrics.sql;

/*
 * #%L
 * Metrics SQL
 * %%
 * Copyright (C) 2014 Open-Source
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */




/**
 * JDBC Proxy handler for {@link CallableStatement}
 */
public class CallableStatementProxyHandler extends AbstractStatementProxyHandler<CallableStatement> {

    private final Query query;

    public CallableStatementProxyHandler(CallableStatement delegate, JdbcProxyFactory proxyFactory, Query query, Timer.Context lifeTimerContext) {
        super(delegate, CallableStatement.class, proxyFactory, lifeTimerContext);
        this.query = query;
    }


    protected final Object execute(MethodInvocation<CallableStatement> methodInvocation) throws Throwable {
