[hibernate-dev] [HSEARCH] Autodiscoverable field bridges next steps

Hardy Ferentschik hardy at hibernate.org
Wed Apr 2 15:18:15 EDT 2014

On 2 Jan 2014, at 17:37, Emmanuel Bernard <emmanuel at hibernate.org> wrote:

> Yes your analysis is correct.

Cool, so we seem to be on the same page then.

> I do think 3 is the most valuable but that 2c is a relatively close second.

+1 for case #3 being the most important one. I would even go so far to say that this is the only one we should address with the BridgeProvider.

> Now the @Spatial and @TikaBridge annotations do have attributes which will influence how the underlying bridge is created.
> I don’t think you are proposing to move the spatial and Tika bridge creation up on AnnotationMetadataProvider.

That’s what I am proposing. Also the processing of the @Bridge annotation (standalone or as part of @Field) should move. Really 
what happens in BridgeFactory#findExplicitFieldBridge (which is funny enough called by something like BridgeFactory#guessType)
is annotation and hence AnnotationMetadataProvider specific. BridgeFactory#guessType could really just become the handler of the described scenario 3.

> That would AFAIU duplicate the bridge creation logic between the AMP and some ProgrammaticMetadataProvider.

No, not really or at most temporarily. Remember, using commons annotations and pseudo annotations are just a crutch. It would be much easier to
instantiate the right metadata and bridges directly. After all the user does explicitly something like .property( "name", ElementType.FIELD ).spatial()
There is not need to guess, you could create the appropriate bridge directly. 

> Also I have a hard time navigating and understanding AnnotationMetadataProvider, so I’m not sure we should make it more complex.

Sure AnnotationMetadataProvider is a lot of code, but it is actually still very similar to the code you originally wrote for DocumentBuilder. It just has moved.
An indexed class is processed by creating the class hierarchy for this class and then iterating the class hierarchy finding indexed properties. You should
be able to follow the  flow quite easily from AnnotationMetadataProvider#initializeClass. Also have a look at the call sites for BridgeFactory#guessType.

> So somehow, the AMP should convert @Spatial, @NumericField, @TikaBridge, and @DateBridge into some non annotation based representation and pass that information to the bridgeFactory.

Somehow you would create the bridge directly. Either from the AnnotationMetadataProvider or we need some additional methods on BridgeFactory.

> Your approach would be to call explicitly buildXxxBridge() - like buildDateBridge() - methods form AMP.

That would be one way of doing it. If these methods would be in BridgeFactory they could even be called from the programmatic config

> These would be hosted on the BridgeFactory. Is that correct?


> And the same explicit call logic would be done on a programmatic API equivalent.


> Now how would you pass and to these kind of explicit calls in the 2c case when the annotation is unknown a priori?

A couple of things here.  buildXxxBridge() are specific to our internal bridges (date, spatial, tika). There is no equivalent for custom (user provided) bridges. They are either 
explicitly configured or go via the BridgeProvider contract. If we truly want to support 2c, we need something like the AnnoatedElement in the contract of BridgeProvider.
On the other hand, 2c can also be solved by the user by specifying his bridge directly. 

If we just think about case #3 BridgeProvider could almost become:

FieldBridge returnFieldBridgeIfMatching(Class<?> returnType, ServiceManager serviceManager);

For me it has many benefits:

1)  It separates completely the annotation processing from the bridge creation, something which is currently in the way for a refactoring of the programmatic config and probably a problem
     for non entity based indexing
2) Probably future proof for non entity based indexing
3) From a development point it treats case #1, #2a and #2b the same way - as explicitly known bridges (which is really the case)
4) There is no major loss in functionality


More information about the hibernate-dev mailing list