You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Sumanta Ghosh <su...@tcs.com> on 2006/07/25 06:09:36 UTC
Usage of Reflection
Hi,
We have started a new project where I have proposed IBATIS. But since
IBATIS uses reflection to populate result or parameters, people are raising
concerns. Now we have decided to go with either of the 2 options: -
1. Using Maps for result and parameters and then populating the
Entities from Maps (e.g. Entities will have a setAttributes(Map attrs)
method where a Entity will set its attributes from the Map) - but here the
concern is slowness of Map and also more coding, as in each Entity we have
to implement setAttributes(Map attrs) method.
2. Using Entities as result and parameters - but here concern is
usage of reflection.
Which option to go with? Please advice.
--
View this message in context: http://www.nabble.com/Usage-of-Reflection-tf1996304.html#a5479650
Sent from the iBATIS - User - Java forum at Nabble.com.
Re: Usage of Reflection
Posted by Leandro Saad <le...@gmail.com>.
I would not be concerned about reflection speed issues since sun has put a
lot of effort to make it more fast. Most of the ORM tools I know (not only
in Java) use reflection to populate beans from the result set, so reflection
is not something you can avoid using these tools.
You could write a simple test to compare calling your setters and using
reflection. Do you know the beanutils package?
This is what I have in my mind.
<java>
//TODO: track time
Map values = new HashMap();
values.put(FIELD_NAME,FIELD_VALUE);
...
for(int i=0 ; i< 1000000 ; i++)
{
Bean bean = new Bean();
BeanUtils.populate(bean,values);
}
//TODO: track time
for(int i=0 ; i< 1000000 ; i++)
{
Bean bean = new Bean();
bean.setXX(values.get(XX));
...
}
//TODO: track time
</java>
This should give you an idea o reflection speed.
--
Leandro Rodrigo Saad Cruz
CTO - InterBusiness Technologies
db.apache.org/ojb
guara-framework.sf.net
xingu.sf.net
On 7/25/06, Sumanta Ghosh <su...@tcs.com> wrote:
>
>
> Hi,
> We have started a new project where I have proposed IBATIS. But since
> IBATIS uses reflection to populate result or parameters, people are
> raising
> concerns. Now we have decided to go with either of the 2 options: -
> 1. Using Maps for result and parameters and then populating the
> Entities from Maps (e.g. Entities will have a setAttributes(Map attrs)
> method where a Entity will set its attributes from the Map) - but here the
> concern is slowness of Map and also more coding, as in each Entity we have
> to implement setAttributes(Map attrs) method.
> 2. Using Entities as result and parameters - but here concern is
> usage of reflection.
> Which option to go with? Please advice.
> --
> View this message in context:
> http://www.nabble.com/Usage-of-Reflection-tf1996304.html#a5479650
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>
Re: Usage of Reflection
Posted by Sumanta Ghosh <su...@tcs.com>.
Thanks a lot!! - I'll go for 2.... FINAL. And in fact, we are using JDK 1.4.
Also, I have read a one liner about usage of CGLIB in IBATIS. Please let me
know if there are some more documentation regarding this.
--
View this message in context: http://www.nabble.com/Usage-of-Reflection-tf1996304.html#a5479900
Sent from the iBATIS - User - Java forum at Nabble.com.
Re: Usage of Reflection
Posted by Larry Meadors <lm...@apache.org>.
If the concern is performance, it's unfounded (unless you are also
using like jdk1.2 or jdk1.3), and using maps instead of beans as
described in option #1 (for the sake of performance) is absolutely
retarded, IMO.
Go with #2.
Larry
On 7/24/06, Sumanta Ghosh <su...@tcs.com> wrote:
>
> Hi,
> We have started a new project where I have proposed IBATIS. But since
> IBATIS uses reflection to populate result or parameters, people are raising
> concerns. Now we have decided to go with either of the 2 options: -
> 1. Using Maps for result and parameters and then populating the
> Entities from Maps (e.g. Entities will have a setAttributes(Map attrs)
> method where a Entity will set its attributes from the Map) - but here the
> concern is slowness of Map and also more coding, as in each Entity we have
> to implement setAttributes(Map attrs) method.
> 2. Using Entities as result and parameters - but here concern is
> usage of reflection.
> Which option to go with? Please advice.
> --
> View this message in context: http://www.nabble.com/Usage-of-Reflection-tf1996304.html#a5479650
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>
Re: Usage of Reflection
Posted by Larry Meadors <lm...@apache.org>.
LOL, no, it was 302ms slower on my box...that is significant. ;-)
Larry
On 7/24/06, Clinton Begin <cl...@gmail.com> wrote:
>
> ARRRGH!!!!! It's 2006 and people are still worried about reflection!!!!????
>
> I advise you find a new client. ;-)
>
> No seriously, what the heck are they worried about??? Performance? Let me
> guess, someone wrote a for loop that called 1,000,000 getters and proved
> that reflection is 300ms slower.
>
> ARRGH!
>
> Clinton :-)
>
>
> On 7/24/06, Clinton Begin <cl...@gmail.com> wrote:
> >
> >
> > [Biting my tongue.]
> >
> > What, pray tell, are they concerned about?
> >
> > [Unnnggh. Biting harder.]
> >
> >
> > Clinton
> >
> >
> >
> >
> > On 7/24/06, Sumanta Ghosh <su...@tcs.com> wrote:
> > >
> > > Hi,
> > > We have started a new project where I have proposed IBATIS. But since
> > > IBATIS uses reflection to populate result or parameters, people are
> raising
> > > concerns. Now we have decided to go with either of the 2 options: -
> > > 1. Using Maps for result and parameters and then populating the
> > > Entities from Maps (e.g. Entities will have a setAttributes(Map attrs)
> > > method where a Entity will set its attributes from the Map) - but here
> the
> > > concern is slowness of Map and also more coding, as in each Entity we
> have
> > > to implement setAttributes(Map attrs) method.
> > > 2. Using Entities as result and parameters - but here concern
> is
> > > usage of reflection.
> > > Which option to go with? Please advice.
> > > --
> > > View this message in context:
> http://www.nabble.com/Usage-of-Reflection-tf1996304.html#a5479650
> > > Sent from the iBATIS - User - Java forum at Nabble.com.
> > >
> > >
> >
> >
>
>
Re: Usage of Reflection
Posted by Clinton Begin <cl...@gmail.com>.
ARRRGH!!!!! It's 2006 and people are still worried about reflection!!!!????
I advise you find a new client. ;-)
No seriously, what the heck are they worried about??? Performance? Let me
guess, someone wrote a for loop that called 1,000,000 getters and proved
that reflection is 300ms slower.
ARRGH!
Clinton :-)
On 7/24/06, Clinton Begin <cl...@gmail.com> wrote:
>
>
> [Biting my tongue.]
>
> What, pray tell, are they concerned about?
>
> [Unnnggh. Biting harder.]
>
> Clinton
>
>
>
> On 7/24/06, Sumanta Ghosh <su...@tcs.com> wrote:
> >
> >
> > Hi,
> > We have started a new project where I have proposed IBATIS. But since
> >
> > IBATIS uses reflection to populate result or parameters, people are
> > raising
> > concerns. Now we have decided to go with either of the 2 options: -
> > 1. Using Maps for result and parameters and then populating the
> >
> > Entities from Maps (e.g. Entities will have a setAttributes(Map attrs)
> > method where a Entity will set its attributes from the Map) - but here
> > the
> > concern is slowness of Map and also more coding, as in each Entity we
> > have
> > to implement setAttributes(Map attrs) method.
> > 2. Using Entities as result and parameters - but here concern
> > is
> > usage of reflection.
> > Which option to go with? Please advice.
> > --
> > View this message in context:
> > http://www.nabble.com/Usage-of-Reflection-tf1996304.html#a5479650
> > Sent from the iBATIS - User - Java forum at Nabble.com.
> >
> >
>
Re: Usage of Reflection
Posted by Clinton Begin <cl...@gmail.com>.
[Biting my tongue.]
What, pray tell, are they concerned about?
[Unnnggh. Biting harder.]
Clinton
On 7/24/06, Sumanta Ghosh <su...@tcs.com> wrote:
>
>
> Hi,
> We have started a new project where I have proposed IBATIS. But since
> IBATIS uses reflection to populate result or parameters, people are
> raising
> concerns. Now we have decided to go with either of the 2 options: -
> 1. Using Maps for result and parameters and then populating the
> Entities from Maps (e.g. Entities will have a setAttributes(Map attrs)
> method where a Entity will set its attributes from the Map) - but here the
> concern is slowness of Map and also more coding, as in each Entity we have
> to implement setAttributes(Map attrs) method.
> 2. Using Entities as result and parameters - but here concern is
> usage of reflection.
> Which option to go with? Please advice.
> --
> View this message in context:
> http://www.nabble.com/Usage-of-Reflection-tf1996304.html#a5479650
> Sent from the iBATIS - User - Java forum at Nabble.com.
>
>