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 Richard Bibb <ri...@aimhedge.com> on 2009/08/19 12:09:30 UTC

Populating a Pojo with two ArrayLists

I'm trying to populate a pojo with two array lists and my code doesn't do
what I intended

The pojo has two arrayLists as memebers one called 'dates' the other
'values'

The mapper XML file I have set up looks like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.aimhedge.trading.database.BackAdjFutureMapper">
	<resultMap id="futureMap" type="DataMap">
		<collection property="dates" javaType="ArrayList" ofType="Date">
			<id property="date" column="date" javaType="Date" jdbcType="DATE"/>
		</collection>
		<collection property="values" javaType="ArrayList" ofType="Double">
			<id property="value" column="value" javaType="Double" jdbcType="DOUBLE"/>
		</collection>
	</resultMap>
	<select id="selectBackAdjFuture" parameterType="BackAdjFuture"
resultMap="futureMap">
  		select date, value 
  		from back_adj_future
		where feed = #{feed}
		and instrument = #{instrument}
		and periodicity = #{periodicity}
		and field = #{field}
		and date <![CDATA[<]]> str_to_date('19980721','%Y%m%d')
		and date <![CDATA[>]]> str_to_date('19980701','%Y%m%d')
	</select>
</mapper>

When I run the code, instead of having both one array list populated with
dates and the other with values both seem to contain dates. Can anyone point
out where I am going wrong? I'm new to iBatis and my use of collections is
probably wrong. One of my issues is that the value field isn't unique so
setting it as an id is probably wrong.
-- 
View this message in context: http://www.nabble.com/Populating-a-Pojo-with-two-ArrayLists-tp25041366p25041366.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Populating a Pojo with two ArrayLists

Posted by Richard Bibb <ri...@aimhedge.com>.
I could do that but it then doesn't map onto my model. The data is time
series data and needs to be available as Array's or ArrayLists. To use a
DataValePair as you suggest will slow my code down markedly as I need to
load quite large amounts of data 


Ingmar Lötzsch wrote:
> 
>> I'm trying to populate a pojo with two array lists and my code doesn't do
>> what I intended
>> 
>> The pojo has two arrayLists as memebers one called 'dates' the other
>> 'values'
> 
> Why can't you create
> 
> class DateValuePair
> {
> 	private Date date;
> 
> 	private Double value;
> 
> 	... getter, setter
> }
> 
> and query for List<DateValuePair>?
> 
> 

-- 
View this message in context: http://www.nabble.com/Populating-a-Pojo-with-two-ArrayLists-tp25041366p25042175.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Populating a Pojo with two ArrayLists

Posted by Zart Colwin <za...@wanadoo.fr>.
Because there is a big difference between two lists of atomic data and a 
single list of composite data.
On one hand you allocate only two objects while on the other hand you 
allocate many small objects who have absolutely no business or 
algorithmic value.
The framework should provides the functionalities that the developer 
needs, not the other around.

ZC.


Ingmar Lötzsch wrote:
>> I'm trying to populate a pojo with two array lists and my code doesn't do
>> what I intended
>>
>> The pojo has two arrayLists as memebers one called 'dates' the other
>> 'values'
>>     
>
> Why can't you create
>
> class DateValuePair
> {
> 	private Date date;
>
> 	private Double value;
>
> 	... getter, setter
> }
>
> and query for List<DateValuePair>?
>
>   
>> The mapper XML file I have set up looks like this
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE mapper
>> PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
>> "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
>> <mapper namespace="com.aimhedge.trading.database.BackAdjFutureMapper">
>> 	<resultMap id="futureMap" type="DataMap">
>> 		<collection property="dates" javaType="ArrayList" ofType="Date">
>> 			<id property="date" column="date" javaType="Date" jdbcType="DATE"/>
>> 		</collection>
>> 		<collection property="values" javaType="ArrayList" ofType="Double">
>> 			<id property="value" column="value" javaType="Double" jdbcType="DOUBLE"/>
>> 		</collection>
>> 	</resultMap>
>> 	<select id="selectBackAdjFuture" parameterType="BackAdjFuture"
>> resultMap="futureMap">
>>   		select date, value 
>>   		from back_adj_future
>> 		where feed = #{feed}
>> 		and instrument = #{instrument}
>> 		and periodicity = #{periodicity}
>> 		and field = #{field}
>> 		and date <![CDATA[<]]> str_to_date('19980721','%Y%m%d')
>> 		and date <![CDATA[>]]> str_to_date('19980701','%Y%m%d')
>> 	</select>
>> </mapper>
>>     
>
> Example in iBATIS 2 syntax (I'm not familiar with iBATIS 3):
>
> <resultMap id="futureMap" resultClass="com...DateValuePair">
> 	<result property="date" column="date" jdbcType="DATE">
> 	<result property="value" column="value" jdbcType="NUMERIC">
> </resultMap>
>
> <select id="selectBackAdjFuture" parameterClass="BackAdjFuture"
> resultMap="futureMap">
> 	SELECT date, value
> 	FROM back_adj_future
> 	WHERE feed = #feed#
> 	AND instrument = #instrument#
> 	AND periodicity = #periodicity#
> 	AND field = #field#
> 	AND str_to_date('19980721', '%Y%m%d') > date
> 	AND date > str_to_date('19980701', '%Y%m%d')
> </select>
>
> (You can avoid the CDATA sections "inverting" the "<" to ">".)
>
>   
>> When I run the code, instead of having both one array list populated with
>> dates and the other with values both seem to contain dates. Can anyone point
>> out where I am going wrong? I'm new to iBatis and my use of collections is
>> probably wrong. One of my issues is that the value field isn't unique so
>> setting it as an id is probably wrong.
>>     
>
> If you can't avoid the representation of your data using class DataMap
> then write a few lines and create the instance outside iBATIS based on
> the List<DateValuePair>.
>
> Also seems, that you can use BackAdjFuture instead of the additional
> class DateValuePair. Another approach is to use HashMap as result class.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
> ---------------------------------------------------------------------------------------
> Orange vous informe que cet  e-mail a ete controle par l'anti-virus mail. 
> Aucun virus connu a ce jour par nos services n'a ete detecte.
>
>
>
>   

Re: Populating a Pojo with two ArrayLists

Posted by Ingmar Lötzsch <il...@asci-systemhaus.de>.
> I'm trying to populate a pojo with two array lists and my code doesn't do
> what I intended
> 
> The pojo has two arrayLists as memebers one called 'dates' the other
> 'values'

Why can't you create

class DateValuePair
{
	private Date date;

	private Double value;

	... getter, setter
}

and query for List<DateValuePair>?

> The mapper XML file I have set up looks like this
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE mapper
> PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
> "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
> <mapper namespace="com.aimhedge.trading.database.BackAdjFutureMapper">
> 	<resultMap id="futureMap" type="DataMap">
> 		<collection property="dates" javaType="ArrayList" ofType="Date">
> 			<id property="date" column="date" javaType="Date" jdbcType="DATE"/>
> 		</collection>
> 		<collection property="values" javaType="ArrayList" ofType="Double">
> 			<id property="value" column="value" javaType="Double" jdbcType="DOUBLE"/>
> 		</collection>
> 	</resultMap>
> 	<select id="selectBackAdjFuture" parameterType="BackAdjFuture"
> resultMap="futureMap">
>   		select date, value 
>   		from back_adj_future
> 		where feed = #{feed}
> 		and instrument = #{instrument}
> 		and periodicity = #{periodicity}
> 		and field = #{field}
> 		and date <![CDATA[<]]> str_to_date('19980721','%Y%m%d')
> 		and date <![CDATA[>]]> str_to_date('19980701','%Y%m%d')
> 	</select>
> </mapper>

Example in iBATIS 2 syntax (I'm not familiar with iBATIS 3):

<resultMap id="futureMap" resultClass="com...DateValuePair">
	<result property="date" column="date" jdbcType="DATE">
	<result property="value" column="value" jdbcType="NUMERIC">
</resultMap>

<select id="selectBackAdjFuture" parameterClass="BackAdjFuture"
resultMap="futureMap">
	SELECT date, value
	FROM back_adj_future
	WHERE feed = #feed#
	AND instrument = #instrument#
	AND periodicity = #periodicity#
	AND field = #field#
	AND str_to_date('19980721', '%Y%m%d') > date
	AND date > str_to_date('19980701', '%Y%m%d')
</select>

(You can avoid the CDATA sections "inverting" the "<" to ">".)

> When I run the code, instead of having both one array list populated with
> dates and the other with values both seem to contain dates. Can anyone point
> out where I am going wrong? I'm new to iBatis and my use of collections is
> probably wrong. One of my issues is that the value field isn't unique so
> setting it as an id is probably wrong.

If you can't avoid the representation of your data using class DataMap
then write a few lines and create the instance outside iBATIS based on
the List<DateValuePair>.

Also seems, that you can use BackAdjFuture instead of the additional
class DateValuePair. Another approach is to use HashMap as result class.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org