ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Shpak (JIRA)" <ibatis-...@incubator.apache.org>
Subject [jira] Commented: (IBATIS-50) Ability to override the default bean creation mechanism
Date Thu, 25 Aug 2005 13:01:24 GMT
    [ http://issues.apache.org/jira/browse/IBATIS-50?page=comments#action_12319991 ] 

Oleg Shpak commented on IBATIS-50:

Because I need factories very much I had a go at hacking iBatis.

If iBatis developers are interested I would be glad to send them the modified files/diff.

Of course, I do not think that what I did is a complete solution and that it is implemented
in the most correct way.

My idea was very simple (maybe overly simple):
 - I added getFactory/setFactory to ResultMap iface and implemented it in BasicResultMap.
I added the setter because I didn't want to mess about with the configuration code. It's fine
by me to set the factory in my DAO initialisation.
- defined this interface
public interface ObjectFactory {
	Object createInstance(Class resultMapClass);
- patched 2 classes in com.ibatis.sqlmap.engine.exchange 
ComplexDataExchange and JavaBeanDataExchange
replaced line (2 occurencies in every file).
          object = Resources.instantiate(resultMap.getResultClass());
        	  object = resultMap.getFactory().createInstance(resultMap.getResultClass());
        	  object = Resources.instantiate(resultMap.getResultClass());

that's all.

> Ability to override the default bean creation mechanism
> -------------------------------------------------------
>          Key: IBATIS-50
>          URL: http://issues.apache.org/jira/browse/IBATIS-50
>      Project: iBatis for Java
>         Type: Wish
>   Components: SQL Maps
>     Versions: 2.0.9
>     Reporter: Philippe Laflamme

> Currently, iBatis is responsible for creating instances of classes used in result maps.
It relies on the assumption that objects can be obtained using the Class.newInstance() method
(or something equivalent).
> The assumption forces users of the framework to create classes with a no-arg default
constructor. IMHO, this also has the effect of favoring implementation inheritance (extends)
over interface inheritance.
> Although this is not a problem in most cases, the ability to plug in an external instance
factory would provide more flexibility and favor good programming practices. Amongst other
things, it would provide developers the ability write code in terms of interface.
> A simple solution is to provide an extension point where resultMap class instances are
obtained from.
> The simplest form would be:
> public interface InstanceFactory {
>   Object createInstance(Class resultMapClass);
> }
> The default implementation would do something along the lines of:
> [...]
> return resultMapClass.newInstance();
> [...]
> Developers could configure iBatis to either use the default implementation or their own
custom implementation. The setting could be part of the sqlMapConfig file or even per resultMap.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

View raw message