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 Iwao AVE! <ha...@gmail.com> on 2009/04/21 12:09:37 UTC
Null handling of Ibator's Criteria class.
Hi all,
A Criteria inner class generated by Ibator throws RuntimeException when
addCriterion() or addCriterionForJDBCDate() method is called with null
as its 'value' argument.
As a result of this behavior, when I build a dynamic criteria, I have to
check null for each condition.
Criteria criteria = someExample.createCriteria();
if (condition1 != null)
criteria.andCondition1EqualTo(condition1);
if (condition2 != null)
criteria.andCondition1EqualTo(condition2);
...
Basically, I want criteria classes to ignore null value (i.e. not to add
any criteria).
When some condition is required, I would validate it in another way
(presentation framework's validation feature, for example).
Before opening a new issue on JIRA, I would like to hear from other
Ibator users about the behavior.
What do you think?
Thanks,
Iwao
Re: Null handling of Ibator's Criteria class.
Posted by Iwao AVE! <ha...@gmail.com>.
Thank you for the swift fix.
In case someone is interested, I pasted some of my plugins' source
to blogger.
http://harawata.blogspot.com/
// Iwao
on 09.4.23 3:48 AM Jeff Butler said the following:
> Fixed in SVN.
>
> Jeff Butler
>
> 2009/4/22 Iwao AVE! <ha...@gmail.com>:
>> Yes, the fix allows me to remove some extra lines.
>> Thanks!
>>
>> // Iwao
>>
>> on 09.4.23 2:12 AM Jeff Butler said the following:
>>> No - it's not intentional, I'll have to fix that. Plus, fixing it
>>> will make the plugin easier - you'll simply have to delete the second
>>> line of all addCriterion* methods and replace it with "return;"
>>>
>>> Jeff Butler
>>>
>>>
>>> 2009/4/22 Iwao AVE! <ha...@gmail.com>:
>>>> Zoran, Jeff,
>>>>
>>>> Thank you for your reply.
>>>> I actually have written a plugin and been using it for a while.
>>>>
>>>> Considering the characteristics of a tool like Ibator, though, I
>>>> thought the default behavior should be ignoring null and wanted to
>>>> know how other developers think.
>>>> It seems that the plugin is a sufficient solution.
>>>>
>>>> To Jeff,
>>>> While writing the plugin, I noticed that one of the
>>>> addCriterionForJDBCDate() method does not throw RuntimeException
>>>> when the value is null (NullPointerException is thrown).
>>>> Is this intentional?
>>>>
>>>> Regards,
>>>> Iwao
>>>>
>>>> on 09.4.23 1:11 AM Jeff Butler said the following:
>>>>> You cold also write a plugin to change the generated code in the model
>>>>> classes. It's a bit more complex than the average plugin, but
>>>>> certainly doable.
>>>>>
>>>>> Jeff Butler
>>>>>
>>>>>
>>>>> On Tue, Apr 21, 2009 at 6:39 PM, Zoran Avtarovski
>>>>> <zo...@sparecreative.com> wrote:
>>>>>> The simple solution we’ve implemented is to modify the source to ignore null
>>>>>> values. That way we don’t have to do null checks and it simplifies the
>>>>>> process of of building dynamic queries. You have two options you can modify
>>>>>> the source after Ibator has run or modify the Ibator source code. We opted
>>>>>> for the second option, but I can understand why some people might not want
>>>>>> to modify the Ibator source.
>>>>>>
>>>>>> I’m pretty sure your example below won’t work as only the last criteria
>>>>>> added will be used. It’s been a while since I looked at it so I’m not
>>>>>> certain.
>>>>>>
>>>>>> Z.
>>>>>>
>>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> A Criteria inner class generated by Ibator throws RuntimeException when
>>>>>> addCriterion() or addCriterionForJDBCDate() method is called with null
>>>>>> as its 'value' argument.
>>>>>> As a result of this behavior, when I build a dynamic criteria, I have to
>>>>>> check null for each condition.
>>>>>>
>>>>>> Criteria criteria = someExample.createCriteria();
>>>>>> if (condition1 != null)
>>>>>> criteria.andCondition1EqualTo(condition1);
>>>>>> if (condition2 != null)
>>>>>> criteria.andCondition1EqualTo(condition2);
>>>>>> ...
>>>>>>
>>>>>> Basically, I want criteria classes to ignore null value (i.e. not to add
>>>>>> any criteria).
>>>>>> When some condition is required, I would validate it in another way
>>>>>> (presentation framework's validation feature, for example).
>>>>>>
>>>>>> Before opening a new issue on JIRA, I would like to hear from other
>>>>>> Ibator users about the behavior.
>>>>>> What do you think?
>>>>>>
>>>>>> Thanks,
>>>>>> Iwao
>>
Re: Null handling of Ibator's Criteria class.
Posted by Jeff Butler <je...@gmail.com>.
Fixed in SVN.
Jeff Butler
2009/4/22 Iwao AVE! <ha...@gmail.com>:
> Yes, the fix allows me to remove some extra lines.
> Thanks!
>
> // Iwao
>
> on 09.4.23 2:12 AM Jeff Butler said the following:
>> No - it's not intentional, I'll have to fix that. Plus, fixing it
>> will make the plugin easier - you'll simply have to delete the second
>> line of all addCriterion* methods and replace it with "return;"
>>
>> Jeff Butler
>>
>>
>> 2009/4/22 Iwao AVE! <ha...@gmail.com>:
>>> Zoran, Jeff,
>>>
>>> Thank you for your reply.
>>> I actually have written a plugin and been using it for a while.
>>>
>>> Considering the characteristics of a tool like Ibator, though, I
>>> thought the default behavior should be ignoring null and wanted to
>>> know how other developers think.
>>> It seems that the plugin is a sufficient solution.
>>>
>>> To Jeff,
>>> While writing the plugin, I noticed that one of the
>>> addCriterionForJDBCDate() method does not throw RuntimeException
>>> when the value is null (NullPointerException is thrown).
>>> Is this intentional?
>>>
>>> Regards,
>>> Iwao
>>>
>>> on 09.4.23 1:11 AM Jeff Butler said the following:
>>>> You cold also write a plugin to change the generated code in the model
>>>> classes. It's a bit more complex than the average plugin, but
>>>> certainly doable.
>>>>
>>>> Jeff Butler
>>>>
>>>>
>>>> On Tue, Apr 21, 2009 at 6:39 PM, Zoran Avtarovski
>>>> <zo...@sparecreative.com> wrote:
>>>>> The simple solution we’ve implemented is to modify the source to ignore null
>>>>> values. That way we don’t have to do null checks and it simplifies the
>>>>> process of of building dynamic queries. You have two options you can modify
>>>>> the source after Ibator has run or modify the Ibator source code. We opted
>>>>> for the second option, but I can understand why some people might not want
>>>>> to modify the Ibator source.
>>>>>
>>>>> I’m pretty sure your example below won’t work as only the last criteria
>>>>> added will be used. It’s been a while since I looked at it so I’m not
>>>>> certain.
>>>>>
>>>>> Z.
>>>>>
>>>>>
>>>>> Hi all,
>>>>>
>>>>> A Criteria inner class generated by Ibator throws RuntimeException when
>>>>> addCriterion() or addCriterionForJDBCDate() method is called with null
>>>>> as its 'value' argument.
>>>>> As a result of this behavior, when I build a dynamic criteria, I have to
>>>>> check null for each condition.
>>>>>
>>>>> Criteria criteria = someExample.createCriteria();
>>>>> if (condition1 != null)
>>>>> criteria.andCondition1EqualTo(condition1);
>>>>> if (condition2 != null)
>>>>> criteria.andCondition1EqualTo(condition2);
>>>>> ...
>>>>>
>>>>> Basically, I want criteria classes to ignore null value (i.e. not to add
>>>>> any criteria).
>>>>> When some condition is required, I would validate it in another way
>>>>> (presentation framework's validation feature, for example).
>>>>>
>>>>> Before opening a new issue on JIRA, I would like to hear from other
>>>>> Ibator users about the behavior.
>>>>> What do you think?
>>>>>
>>>>> Thanks,
>>>>> Iwao
>
>
Re: Null handling of Ibator's Criteria class.
Posted by Iwao AVE! <ha...@gmail.com>.
Yes, the fix allows me to remove some extra lines.
Thanks!
// Iwao
on 09.4.23 2:12 AM Jeff Butler said the following:
> No - it's not intentional, I'll have to fix that. Plus, fixing it
> will make the plugin easier - you'll simply have to delete the second
> line of all addCriterion* methods and replace it with "return;"
>
> Jeff Butler
>
>
> 2009/4/22 Iwao AVE! <ha...@gmail.com>:
>> Zoran, Jeff,
>>
>> Thank you for your reply.
>> I actually have written a plugin and been using it for a while.
>>
>> Considering the characteristics of a tool like Ibator, though, I
>> thought the default behavior should be ignoring null and wanted to
>> know how other developers think.
>> It seems that the plugin is a sufficient solution.
>>
>> To Jeff,
>> While writing the plugin, I noticed that one of the
>> addCriterionForJDBCDate() method does not throw RuntimeException
>> when the value is null (NullPointerException is thrown).
>> Is this intentional?
>>
>> Regards,
>> Iwao
>>
>> on 09.4.23 1:11 AM Jeff Butler said the following:
>>> You cold also write a plugin to change the generated code in the model
>>> classes. It's a bit more complex than the average plugin, but
>>> certainly doable.
>>>
>>> Jeff Butler
>>>
>>>
>>> On Tue, Apr 21, 2009 at 6:39 PM, Zoran Avtarovski
>>> <zo...@sparecreative.com> wrote:
>>>> The simple solution we’ve implemented is to modify the source to ignore null
>>>> values. That way we don’t have to do null checks and it simplifies the
>>>> process of of building dynamic queries. You have two options you can modify
>>>> the source after Ibator has run or modify the Ibator source code. We opted
>>>> for the second option, but I can understand why some people might not want
>>>> to modify the Ibator source.
>>>>
>>>> I’m pretty sure your example below won’t work as only the last criteria
>>>> added will be used. It’s been a while since I looked at it so I’m not
>>>> certain.
>>>>
>>>> Z.
>>>>
>>>>
>>>> Hi all,
>>>>
>>>> A Criteria inner class generated by Ibator throws RuntimeException when
>>>> addCriterion() or addCriterionForJDBCDate() method is called with null
>>>> as its 'value' argument.
>>>> As a result of this behavior, when I build a dynamic criteria, I have to
>>>> check null for each condition.
>>>>
>>>> Criteria criteria = someExample.createCriteria();
>>>> if (condition1 != null)
>>>> criteria.andCondition1EqualTo(condition1);
>>>> if (condition2 != null)
>>>> criteria.andCondition1EqualTo(condition2);
>>>> ...
>>>>
>>>> Basically, I want criteria classes to ignore null value (i.e. not to add
>>>> any criteria).
>>>> When some condition is required, I would validate it in another way
>>>> (presentation framework's validation feature, for example).
>>>>
>>>> Before opening a new issue on JIRA, I would like to hear from other
>>>> Ibator users about the behavior.
>>>> What do you think?
>>>>
>>>> Thanks,
>>>> Iwao
Re: Null handling of Ibator's Criteria class.
Posted by Jeff Butler <je...@gmail.com>.
No - it's not intentional, I'll have to fix that. Plus, fixing it
will make the plugin easier - you'll simply have to delete the second
line of all addCriterion* methods and replace it with "return;"
Jeff Butler
2009/4/22 Iwao AVE! <ha...@gmail.com>:
> Zoran, Jeff,
>
> Thank you for your reply.
> I actually have written a plugin and been using it for a while.
>
> Considering the characteristics of a tool like Ibator, though, I
> thought the default behavior should be ignoring null and wanted to
> know how other developers think.
> It seems that the plugin is a sufficient solution.
>
> To Jeff,
> While writing the plugin, I noticed that one of the
> addCriterionForJDBCDate() method does not throw RuntimeException
> when the value is null (NullPointerException is thrown).
> Is this intentional?
>
> Regards,
> Iwao
>
> on 09.4.23 1:11 AM Jeff Butler said the following:
>> You cold also write a plugin to change the generated code in the model
>> classes. It's a bit more complex than the average plugin, but
>> certainly doable.
>>
>> Jeff Butler
>>
>>
>> On Tue, Apr 21, 2009 at 6:39 PM, Zoran Avtarovski
>> <zo...@sparecreative.com> wrote:
>>> The simple solution we’ve implemented is to modify the source to ignore null
>>> values. That way we don’t have to do null checks and it simplifies the
>>> process of of building dynamic queries. You have two options you can modify
>>> the source after Ibator has run or modify the Ibator source code. We opted
>>> for the second option, but I can understand why some people might not want
>>> to modify the Ibator source.
>>>
>>> I’m pretty sure your example below won’t work as only the last criteria
>>> added will be used. It’s been a while since I looked at it so I’m not
>>> certain.
>>>
>>> Z.
>>>
>>>
>>> Hi all,
>>>
>>> A Criteria inner class generated by Ibator throws RuntimeException when
>>> addCriterion() or addCriterionForJDBCDate() method is called with null
>>> as its 'value' argument.
>>> As a result of this behavior, when I build a dynamic criteria, I have to
>>> check null for each condition.
>>>
>>> Criteria criteria = someExample.createCriteria();
>>> if (condition1 != null)
>>> criteria.andCondition1EqualTo(condition1);
>>> if (condition2 != null)
>>> criteria.andCondition1EqualTo(condition2);
>>> ...
>>>
>>> Basically, I want criteria classes to ignore null value (i.e. not to add
>>> any criteria).
>>> When some condition is required, I would validate it in another way
>>> (presentation framework's validation feature, for example).
>>>
>>> Before opening a new issue on JIRA, I would like to hear from other
>>> Ibator users about the behavior.
>>> What do you think?
>>>
>>> Thanks,
>>> Iwao
>
Re: Null handling of Ibator's Criteria class.
Posted by Iwao AVE! <ha...@gmail.com>.
Zoran, Jeff,
Thank you for your reply.
I actually have written a plugin and been using it for a while.
Considering the characteristics of a tool like Ibator, though, I
thought the default behavior should be ignoring null and wanted to
know how other developers think.
It seems that the plugin is a sufficient solution.
To Jeff,
While writing the plugin, I noticed that one of the
addCriterionForJDBCDate() method does not throw RuntimeException
when the value is null (NullPointerException is thrown).
Is this intentional?
Regards,
Iwao
on 09.4.23 1:11 AM Jeff Butler said the following:
> You cold also write a plugin to change the generated code in the model
> classes. It's a bit more complex than the average plugin, but
> certainly doable.
>
> Jeff Butler
>
>
> On Tue, Apr 21, 2009 at 6:39 PM, Zoran Avtarovski
> <zo...@sparecreative.com> wrote:
>> The simple solution we’ve implemented is to modify the source to ignore null
>> values. That way we don’t have to do null checks and it simplifies the
>> process of of building dynamic queries. You have two options you can modify
>> the source after Ibator has run or modify the Ibator source code. We opted
>> for the second option, but I can understand why some people might not want
>> to modify the Ibator source.
>>
>> I’m pretty sure your example below won’t work as only the last criteria
>> added will be used. It’s been a while since I looked at it so I’m not
>> certain.
>>
>> Z.
>>
>>
>> Hi all,
>>
>> A Criteria inner class generated by Ibator throws RuntimeException when
>> addCriterion() or addCriterionForJDBCDate() method is called with null
>> as its 'value' argument.
>> As a result of this behavior, when I build a dynamic criteria, I have to
>> check null for each condition.
>>
>> Criteria criteria = someExample.createCriteria();
>> if (condition1 != null)
>> criteria.andCondition1EqualTo(condition1);
>> if (condition2 != null)
>> criteria.andCondition1EqualTo(condition2);
>> ...
>>
>> Basically, I want criteria classes to ignore null value (i.e. not to add
>> any criteria).
>> When some condition is required, I would validate it in another way
>> (presentation framework's validation feature, for example).
>>
>> Before opening a new issue on JIRA, I would like to hear from other
>> Ibator users about the behavior.
>> What do you think?
>>
>> Thanks,
>> Iwao
Re: Null handling of Ibator's Criteria class.
Posted by Jeff Butler <je...@gmail.com>.
You cold also write a plugin to change the generated code in the model
classes. It's a bit more complex than the average plugin, but
certainly doable.
Jeff Butler
On Tue, Apr 21, 2009 at 6:39 PM, Zoran Avtarovski
<zo...@sparecreative.com> wrote:
> The simple solution we’ve implemented is to modify the source to ignore null
> values. That way we don’t have to do null checks and it simplifies the
> process of of building dynamic queries. You have two options you can modify
> the source after Ibator has run or modify the Ibator source code. We opted
> for the second option, but I can understand why some people might not want
> to modify the Ibator source.
>
> I’m pretty sure your example below won’t work as only the last criteria
> added will be used. It’s been a while since I looked at it so I’m not
> certain.
>
> Z.
>
>
> Hi all,
>
> A Criteria inner class generated by Ibator throws RuntimeException when
> addCriterion() or addCriterionForJDBCDate() method is called with null
> as its 'value' argument.
> As a result of this behavior, when I build a dynamic criteria, I have to
> check null for each condition.
>
> Criteria criteria = someExample.createCriteria();
> if (condition1 != null)
> criteria.andCondition1EqualTo(condition1);
> if (condition2 != null)
> criteria.andCondition1EqualTo(condition2);
> ...
>
> Basically, I want criteria classes to ignore null value (i.e. not to add
> any criteria).
> When some condition is required, I would validate it in another way
> (presentation framework's validation feature, for example).
>
> Before opening a new issue on JIRA, I would like to hear from other
> Ibator users about the behavior.
> What do you think?
>
> Thanks,
> Iwao
>
>
Re: Null handling of Ibator's Criteria class.
Posted by Zoran Avtarovski <zo...@sparecreative.com>.
The simple solution we¹ve implemented is to modify the source to ignore null
values. That way we don¹t have to do null checks and it simplifies the
process of of building dynamic queries. You have two options you can modify
the source after Ibator has run or modify the Ibator source code. We opted
for the second option, but I can understand why some people might not want
to modify the Ibator source.
I¹m pretty sure your example below won¹t work as only the last criteria
added will be used. It¹s been a while since I looked at it so I¹m not
certain.
Z.
>
>
> Hi all,
>
> A Criteria inner class generated by Ibator throws RuntimeException when
> addCriterion() or addCriterionForJDBCDate() method is called with null
> as its 'value' argument.
> As a result of this behavior, when I build a dynamic criteria, I have to
> check null for each condition.
>
> Criteria criteria = someExample.createCriteria();
> if (condition1 != null)
> criteria.andCondition1EqualTo(condition1);
> if (condition2 != null)
> criteria.andCondition1EqualTo(condition2);
> ...
>
> Basically, I want criteria classes to ignore null value (i.e. not to add
> any criteria).
> When some condition is required, I would validate it in another way
> (presentation framework's validation feature, for example).
>
> Before opening a new issue on JIRA, I would like to hear from other
> Ibator users about the behavior.
> What do you think?
>
> Thanks,
> Iwao