1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public interface RegistrableQuery
{
/**
* @return la requête JPQL.
*/
default String getQuery(){
try {
EnumQuery annotation = this.getClass().getField(((Enum<?>) this).name()).getDeclaredAnnotation(EnumQuery.class);
if (annotation != null){
return annotation.query();
} else {
throw new RuntimeException("enum "+this+" does not have a @EnumQuery annotation");
}
} catch (NoSuchFieldException e) {
throw new RuntimeException(this+" is a broken enum according to java specs. Should not happend");
} catch (ClassCastException e) {
throw new RuntimeException(this+" is not an enum");
}
};
/**
* @return l'identifiant de la requête JPQL.
*/
default String getIdentifier() {
return String.format("%s_%s", this.getClass(), ((Enum<?>)this).name());
}
} |
Partager