I need to write an Annotation to exclude certain values from a result set.
Background:
Distinct values are selected from fields and are listed in a ComboBox. Some of the legacy values are Deprecated and I don't want to show them, even if they are returned by JDBC's SELECT DISTINCT()
. It's like a mini-framework where people can build select queries by clicking values from ComboBoxes.
I tried the following (the code does not compile - commented lines are the ways I tried to solve the problem):
public enum JobType {
//...
S,
//...
}
public @interface Exclude {
Object[] values(); // Invalid type
Enum[] values(); // Invalid type again
String[] values(); // Accepts but see the following lines
}
@Table(name = "jobs_view")
public class JobSelectionView extends View {
//...
@Exclude(values = {JobType.S.toString()}) // Not a constant expression
@Exclude(values = {JobType.S.name()}) // Not a constant expression ?!?!?!
@Exclude(values = {"S"}) // Works but... come on!
@Enumerated(value = EnumType.STRING)
@Column(name = "type")
private JobType type;
//...
}
I don't like using {"S"}
, any suggestions?