ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles Bayon" <gilles.ba...@laposte.net>
Subject RE: iBATIS.NET Binder suggestion with Oracle selectKey (quick fix)
Date Sat, 01 Jan 2005 20:46:42 GMT
Added the fix in SVN.

-----Message d'origine-----
De : roberto [mailto:roberto@theaegis.org] 
Envoyé : vendredi 31 décembre 2004 08:25
À : ibatis-dev@incubator.apache.org
Objet : iBATIS.NET Binder suggestion with Oracle selectKey (quick fix)

Gilles,

Luke's Binder suggestion as posted on SourceForge did work, however as he
mentioned, there should be a better way without throwing out type safety.

I went through the code for getting selectKeys and noticed the similarity
with QueryForObject since they both go through
MappedStatement.ExecuteQueryForObject() and
MappedStatement.ApplyResultMap().

I ended up finding why both QueryForObject() and using a selectKey return a
System.Decimal when using Oracle even if the resultClass is specified as int
(or string or anything else).  The generated ResultProperty for a primitive
resultClass didn't have a TypeHandler specified, so the resulting object was
being handled by grabbing the db/provider type.

Thankfully, it's a quick fix!  :-)

Here's the area in MappedStatement.ApplyResultMap() (lines 383 to 392...the
"property.TypeHandler..." line is the fix):

// Check if the ResultClass is a 'primitive' Type
if (Type.GetTypeCode(outObject.GetType()) != TypeCode.Object)
{
	// Create a ResultProperty
	ResultProperty property = new ResultProperty();
	property.PropertyName = "value";
	property.ColumnIndex = 0;
	property.TypeHandler =
TypeHandlerFactory.GetTypeHandler(outObject.GetType());

	SetObjectProperty(request, request.ResultMap, property, ref
outObject, reader);
}

This should hopefully resolve any weird errors others may be getting when
specifying a primitive result class but not actually getting the object of
that type.  Haven't heard many complaints though!  hehe

Roberto

-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.7 - Release Date: 30/12/2004
 

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.7 - Release Date: 30/12/2004
 


Mime
View raw message