package com.github.arteam.jdbi3.strategies;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.annotation.Timed;
import org.jdbi.v3.core.extension.ExtensionMethod;
import org.jdbi.v3.core.statement.StatementContext;

import java.lang.reflect.Method;

/**
 * Takes into account the {@link Timed} annotation on extension methods
 */
public class TimedAnnotationNameStrategy implements StatementNameStrategy {

    @Override
    public String getStatementName(StatementContext statementContext) {
        ExtensionMethod extensionMethod = statementContext.getExtensionMethod();
        if (extensionMethod != null) {
            final Class<?> clazz = extensionMethod.getType();
            final Method method = extensionMethod.getMethod();
            final Timed timed = method.getAnnotation(Timed.class);
            if (timed != null) {
                return timed.absolute() ? timed.name() : MetricRegistry.name(clazz, timed.name());
            }
        }
        return null;
    }
}

@@ -687,24 +687,95 @@
 .getType();%0A
+            final Timed classTimed = clazz.getAnnotation(Timed.class);%0A
             
@@ -849,17 +849,23 @@
 l Timed 
-t
+methodT
 imed = m
@@ -914,72 +914,373 @@
     
-if (timed != null) %7B%0A                return timed.absolute() ? t
+// If the method is metered, figure out the name%0A            if (methodTimed != null) %7B%0A                if (methodTimed.absolute()) %7B%0A                    return methodTimed.name();%0A                %7D else %7B%0A                    // We need to check if the class has a custom timer name%0A                    return classTimed == null ? MetricRegistry.name(clazz, methodT
 imed
@@ -1290,45 +1290,286 @@
 me()
+)
  :
- MetricRegistry.name(clazz, timed.n
+%0A                            MetricRegistry.name(classTimed.name(), methodTimed.name());%0A                %7D%0A            %7D%0A            // Maybe the class is metered?%0A            if (classTimed != null) %7B%0A                return MetricRegistry.name(classTimed.name(), method.getN
 ame(

Add support for annotating the class as `@Timed`