db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Jefferson <a...@jpox.org>
Subject Re: Annotation enum : IdGeneratorStrategy
Date Fri, 10 Aug 2007 05:56:00 GMT
> As a perhaps lighter-weight variant on Andy's option (2) below, could
> we simply provide an alternative, string-based parameter to the
> annotation, such as 'customValueStrategy'?
>
>      @Target({ElementType.FIELD, ElementType.METHOD})
>      @Retention(RetentionPolicy.RUNTIME)
>      public @interface Persistent
>      {
>          // ...
>          IdGeneratorStrategy valueStrategy() default
> IdGeneratorStrategy.UNKNOWN;
>          String customValueStrategy() default "";
>      }

If going for this case a "CUSTOM" value should be added to the enum (rather 
than using UNKNOWN - which is for where you don't want one, maybe it should 
be NONE instead of UNKNOWN), and when it is CUSTOM the user supplies 
the "customValueStrategy".  Similarly in @DatastoreIdentity "strategy".

> Another option could be to have IdGeneratorStrategy become a marker
> interface and then have the enum be defined as something like:
>      public interface IdGeneratorStrategy {}
>      public enum StandardIdGeneratorStrategy implements
> IdGeneratorStrategy
>      {
>          UNKNOWN,
>          NATIVE,
>          // ...
>      };
> This would allow implementations to supply custom id generators in a
> typesafe way:
>
>      package org.jpox.annotations;
>      public enum JPOXIdGeneratorStrategy implements IdGeneratorStrategy
>      {
>          AUID,
>          // ...
>      };
>
> I like this latter approach, because it demonstrates very clearly
> that my usage is vendor-specific and non-portable.

Well the implementors of annotations in the JDK decided on this classic 
restriction :-
"only primitive, String, Class, annotation, enum are permitted as the types of 
the element in an annotation" meaning that you can't have an element with an 
interface type.
and we also can't "extend" an enum.


-- 
Andy  (Java Persistent Objects - http://www.jpox.org)

Mime
View raw message