[hibernate-issues] [Hibernate-JIRA] Updated: (HSEARCH-618) BridgeFactory should pass along the field type to the field bridge constructor (if an appropriate constructor exists)

I D (JIRA) noreply at atlassian.com
Sat Nov 6 22:16:14 EDT 2010


     [ http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-618?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

I D updated HSEARCH-618:
------------------------

    Attachment: HSEARCH-618_patch.zip

Here you go. I confess - I couldn't find the time to actually compile HS and test this, but the changes are pretty clean cut, so I believe it will work out of the box. Diffs are against current trunk in github.

> BridgeFactory should pass along the field type to the field bridge constructor (if an appropriate constructor exists)
> ---------------------------------------------------------------------------------------------------------------------
>
>                 Key: HSEARCH-618
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-618
>             Project: Hibernate Search
>          Issue Type: Improvement
>    Affects Versions: 3.3.0.Beta2
>         Environment: Hibernate Core 3.6.0
>            Reporter: I D
>            Priority: Minor
>         Attachments: HSEARCH-618_patch.zip
>
>
> Currently, only the built in EnumBridge is getting access to the field type via its constructor.
> That's a shame, since the field type is very useful information, and may be necessary for certainy types of bridges, plus it's readily available to the BridgeFactory.
> Here's one use case:
> Suppose I want to create a bridge named EnumOrdinalBridge, similar to EnumBridge but saving the constants' ordinals to the index (instead of their names/values). This bridge would need to know the Enum type, so the only way this could be done presently is to make it a ParameterizedBridge and then to pass the enum's class name via the "params" param of the @FieldBridge annotation.
> Here is how an invokation of such a bridge would look:
> {code}
> public enum Gender {MALE,FEMALE}
> {code}
> {code}
> @Field(index = Index.UN_TOKENIZED)
> @FieldBridge(impl = EnumOrdinalBridge.class, params = {@Parameter(name="class", value="package.name.Gender")})
> public Gender getGender() {
> 	return gender;
> }
> {code}
> Note the problematic use of qualified class name as a string literal - this is neither portable nor refactoring-proof. What if I wanted to change the name of the enum or move it to another package (or what if I simply misspell the qualified class name)? These will all lead to runtime (rather than compile-time) errors. Also, repetition's bad (m'kay?), so there's no reason to have to explicitly pass along information to the bridge when that information is already implicitly available to the BridgeFactory.
> I suggest you use reflection in BridgeFactory to detect whether the constructed FieldBridge has a constructor with one argument of type Class. If so - that constructor will be used (instead of the no-args constructor, currently used for all non-built-in field bridges), and the type of the field will be passed as its argument.
> With this behavior implemented, the above example can be nicely reduced to the following, and we'll have achieved code portability and enhanced compile-time safety:
> {code}
> public enum Gender {MALE,FEMALE}
> {code}
> {code}
> @Field(index = Index.UN_TOKENIZED)
> @FieldBridge(impl = EnumOrdinalBridge.class)
> public Gender getGender() {
> 	return gender;
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list