Discussed with Gunnar a bit on IRC. Some thoughts:
{code} /** * Marks a custom annotation as a defining an identifier generator. * <p/> * Custom annotations must have retention policy {@link RetentionPolicy#RUNTIME}. */ public interface CustomIdentifierGeneratorAnnotationMarker { Class<? extends IdentifierGeneratorBuilder> builder(); }
public interface IdentifierGeneratorBuilder { public IdentifierGenerator getIdentifierGenerator(Annotation customAnnotation, ... ); } {code}
So for example: {code} public class MyUuidGenerator implements IdentifierGenerator { ... }
public class MyUuidGeneratorBuilder implements IdentifierGeneratorBuilder { public IdentifierGenerator getIdentifierGenerator(Annotation customAnnotation, ... ) { return new MyUuidGenerator(); } }
@CustomIdentifierGeneratorAnnotationMarker( builder = MyUuidGeneratorBuilder.class ) @Retention( RetentionPolicy.RUNTIME ) public @interface UUID { } {code}
Then a user would be able to use this custom annotation/generator like: {code} @Id @GeneratedValue @UUID private UUID id; {code}
|