On 5 Jan 2012, at 4:05 AM, Steve Ebersole wrote:

> Probably you can cache it by AnnotationInstance, so maybe something 
> like this instead:
> 
> class AnnotationProxyBuilder {
>    private final Map annotationProxyMap = new ...;
> 
>    public <T> T getAnnotationProxy(final AnnotationInstance 
> annotationInstance, final Class<T> annotationClass) {
>        T annotationProxy = (T) annotationProxyMap.get( 
> annotationInstance );
>        if ( annotationProxy == null ) {
>            annotationProxy = buildAnnotationProxy( annotationInstance, 
> annotationClass );
>            annotationProxyMap.put( annotationInstance, annotationProxy 
> );
>        }
>        return annotationProxy;
>    }
> 
>    private <T> T buildAnnotationProxy(final AnnotationInstance 
> annotationInstance, final Class<T> annotationClass) {
>        // as before...
>    }
> }

Is it really worth caching by annotation instance? Are we in most cases not 
processing/visiting the instance once?
That said, I kind of like the proxy approach. It makes the code more compact 
(less if statements) and by using java.lang.Annotation
we get some type safety back (annotation.foo() instead of 
annotationInstance.value("foo")). The drawback of course is the 
additional proxy overhead. I can see this idea as an evolution of the 
JandexHelper and would add it in there.

Maybe Envers can lead the way and we can see how this approach turns out. Given 
that there is so much other stuff
still left to do on the metamodel side itself I don't think we should start 
retrofitting right now. There are other more important things to
do.

--Hardy


_______________________________________________
hibernate-dev mailing list
hibernate-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev

Reply via email to