Aliaksandr Radzivanovich wrote:
Thanks Kris, I've already found this class. My problem is that in some
cases it's a bit cumbersome to deal with type handlers in XML mapping
file.
It's not a problem for result maps, for example:
<resultMap id="personResult" class="person">
<result property="birthDate" column="BirthDate" typeHandler="thDate"/>
Once described this result map can be used for any number of queries.
But to apply type handler to a parameter (not a result) I have to use
parameter map, or I have to specify
#parameterName,typeHandler=typeHandlerName#
for every mapped bean property like in the following example.
INSERT INTO Person (ID, â, BirthDate)
VALUES (#id#, â, #birthDate,typeHandler=thDate#)
When using parameter map it is impossible to use bean property names,
only their indices. So mapping and statement would look like
<parameterMap id="personParam" class="person">
<parameter property="id"/>
...
<parameter property="birthDate" typeHandler="thDate"/>
INSERT INTO Person (ID, â, BirthDate)
VALUES (?, â, ?)
Thus, for every single insert or update statement I have to provide
its own unique parameter map, or I have to specify type handler for
the same property in every update statement.
Am I right in my assumption?
So my suggestion is: it would be nice to create one general parameter
map and then using it with any number update statements providing bean
property names instead of their indices. Is this possible?
Your help will be appreciated.
I believe you're right - you'll have to specify the typeHandler in every place that you use the property.
As for your suggestion, we'll have to farm this out to Clinton et. al., but it strikes me as messy. Here's my alternative suggestion (shamelessly lifted from Spring 's Validator interface) - add a new method to TypeHandlerCallback:
/** Returns true if this typehandler supports the given class. */ boolean supports( Class clazz );
For a property with a non-standard javaType, SqlMap would transparently use the first registered TypeHandler that claims to support the property's class.
Perhaps SqlMap would consult these /before/ the standard typehandlers, which would give people the possibility of overriding the default handling, too.
Any thoughts, anybody?
-- Kris Jenkins Email: [EMAIL PROTECTED] Blog: http://cafe.jenkster.com/ Wiki: http://wiki.jenkster.com/