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
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira