I'm creating a custom Metric Aspect so that I don't have to do METRIC.aboutTo("save", "order") in the code. My organization uses custom metric libraries.
So, I want to create a custom metric annotation and aspect to do this for me.
I'm looking to be able to add the annotation @PostgressMetric to both the class and the method. It would look something like this:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface PostgressMetric {
String value() default "";
String table() default "";
}
If the metric is on the class, then I want to use those values as "defaults". So you could have something like this:
@Repository
@PostgressMetric(table = "order")
public class OrderRepository {
@PostgressMetric("save")
public void save(Order order) {
}
}
This is also a valid setup:
@Repository
public class OrderRepository {
@PostgressMetric(table="order", value="save")
public void save(Order order) {
}
}
and of course this is also a valid setup:
@Repository
@PostgressMetric(table="order", value="save")
public class OrderRepository {
public void save(Order order) {
}
}
Now, in my aspect I want to get the annotation from the class, then get the annotation from the method. If the class has the annotation then get the table and value and use those as default values. If the method has the annotation then if the values aren't blank, use them to override the default values specified in the class annotation.
Is there a standard way to get the two annotations, or is it just a brute force get the class values and then get the method values and override them?