Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 22029 invoked from network); 12 Feb 2006 16:48:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Feb 2006 16:48:07 -0000 Received: (qmail 54796 invoked by uid 500); 12 Feb 2006 16:48:05 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 54775 invoked by uid 500); 12 Feb 2006 16:48:05 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 54763 invoked by uid 99); 12 Feb 2006 16:48:05 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Feb 2006 08:48:05 -0800 X-ASF-Spam-Status: No, hits=1.9 required=10.0 tests=DNS_FROM_RFC_ABUSE,DNS_FROM_RFC_POST,HTML_MESSAGE X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [68.142.206.52] (HELO web32905.mail.mud.yahoo.com) (68.142.206.52) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 12 Feb 2006 08:48:04 -0800 Received: (qmail 45452 invoked by uid 60001); 12 Feb 2006 16:47:37 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.cn; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Qia4KYQjGpaOBQ85LhJmKCmbrEjJg9bgulu1TCFGvfT3Sej5ffXOgdSDRvSS2flbS0DI5+OPENHgcdqS91Dd/b+4kmhmif6X2pAGCtt5OzQ6y5DWp1wDxYXm3CrZO/bGBvg50tWaE9j4DIUPGjb5Fl9pjvVK1i5N3MMbTRYvqbM= ; Message-ID: <20060212164737.45447.qmail@web32905.mail.mud.yahoo.com> Received: from [221.3.110.237] by web32905.mail.mud.yahoo.com via HTTP; Mon, 13 Feb 2006 00:47:37 CST Date: Mon, 13 Feb 2006 00:47:37 +0800 (CST) From: wang lei Subject: Re: dynamic Sql and parameter together To: user-java@ibatis.apache.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1507026052-1139762857=:36077" Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --0-1507026052-1139762857=:36077 Content-Type: text/plain; charset=gb2312 Content-Transfer-Encoding: 8bit I am soryy not to agree to your opinions. You said the xml is simpler than the code. Now i want to write it in detail. the code is the following; int id=... int min=... int max=... //get value from the servlet parameter IQuery t_AllQuery = this.dao.newQuery(User.class); if(id>0) { IQuery t_Query = this.dao.newQuery(User.class); t_Query.addEqualTo("equal", new Integer(id)); t_AllQuery.addOrCriteria(t_Query); } if(min>0) { IQuery t_Query = this.dao.newQuery(User.class); t_Query.addEqualTo("min", new Integer(min)); t_AllQuery.addOrCriteria(t_Query); } if(max<1000000) { IQuery t_Query = this.dao.newQuery(User.class); t_Query.addEqualTo("max", new Integer(max)); t_AllQuery.addOrCriteria(t_Query); } Now if the following urls are: example.do?id=12&min=100 example.do?min=100 example.do?id=12&max=100 ... ... 8 urls can listed and 8 sql statements will be executed. Now may be 8 statement to support this query. With the increment of the condition, more sqls will be added,it's difficult to maintain. So i can't agree to your opinions of "the dynamic tag is simpler". And which one is easy to understand, "java code" or xml. for me,8 xml will be more difficult to maintain and understand. If you have a good solution or any idea,just give me, Thanks for your help. Addtionaly: why I need to implement a dao to support ojb,hibernate and ibatis,even jdbc. because our company has some products to sell,some time these products is needed to work with some products from other companies. So we must have a common dao to support plantation. > > As far as I can tell, the dynamic SQL example you gave is shorter than > the Java code you wrote (if you get rid of the redundant CDATA sections). > > That said, I understand your point. A future goal for iBATIS SQL Maps > (Data Mapper) will be to more easily support ad-hoc queries and > configuration via the Java API. This will help you get to where you want > to be. Unfortunatley it's not available yet. > > Cheers, > Clinton > > wang lei wrote: > >> At first, thanks for the quick reply from Brandon Goodin. >> I use java for 3 years. >> My major work is to provide small base libraries or swing and swt >> controls for the developers in our company. >> I don't have much experience in big projects. >> So my opinions is just based on the small or medium projects. >> My idea for "design" is simple. I try to make the developer know how >> to use my library in 1-3 hours.The simplicity is what i need. >> I think i understand what Brandon Goodin said. >> The strength of ibatis is make it easy to use the database's >> characteristic. >> If i use ibatis,i should use sql instead of the "Criteria". >> But i want more simplicity and flexibility. >> The following is a example. >> int id=... >> int min=... >> int max=... >> //get value from the servlet parameter >> IQuery t_AllQuery = this.dao.newQuery(User.class); >> if(id>0) >> { >> IQuery t_Query = this.dao.newQuery(User.class); >> t_Query.addEqualTo("equal", new Integer(id)); >> >> t_AllQuery.addOrCriteria(t_Query); >> } >> >> if(min>0) >> { >> IQuery t_Query = this.dao.newQuery(User.class); >> t_Query.addEqualTo("min", new Integer(min)); >> >> t_AllQuery.addOrCriteria(t_Query); >> } >> >> if(max<1000000) >> { >> IQuery t_Query = this.dao.newQuery(User.class); >> t_Query.addEqualTo("max", new Integer(max)); >> >> t_AllQuery.addOrCriteria(t_Query); >> } >> the java code above is common in out projects. >> How many sql i need to write. >> I write one example. >> >> >> >> > USER_ID=#equal# >> ]]> >> >> > USER_ID>#min# >> ]]> >> >> > USER_ID<#"max"# >> ]]> >> >> >> >> >> >> >> If there is no the parameter of "equal". >> the sql for execution will be >> "Select USER_ID, USER_NAME, PHOTO, USER_MEMO from DEMO.USER_T". >> I want to know h ow can i make it easy to handle it. >> --------------------------------- ���Ϊ��С�ա��¿��衢�ż��������ݵ������� --0-1507026052-1139762857=:36077 Content-Type: text/html; charset=gb2312 Content-Transfer-Encoding: 8bit
I am soryy not to agree to your opinions.
You said the <dynamic> xml is simpler than the code.
Now i want to write it in detail.
 
the code is the following;
int id=...
int min=...
int max=...
//get value from the servlet parameter
 
IQuery t_AllQuery = this.dao.newQuery(User.class);
  
if(id>0)
  {
   IQuery t_Query = this.dao.newQuery(User.class);
   t_Query.addEqualTo("equal", new Integer(id));
   
   t_AllQuery.addOrCriteria(t_Query);
  }

 if(min>0)
  {
   IQuery t_Query = this.dao.newQuery(User.class);
   t_Query.addEqualTo("min", new Integer(min));
   
   t_AllQuery.addOrCriteria(t_Query);
  }

  if(max<1000000)
  {
   IQuery t_Query = this.dao.newQuery(User.class);
   t_Query.addEqualTo("max", new Integer(max));
   
   t_AllQuery.addOrCriteria(t_Query);
  }
 
Now if the following urls are:
example.do?id=12&min=100
example.do?min=100
example.do?id=12&max=100
...
...
8 urls can listed and 8 sql statements will be executed.
 
Now may be 8 <dynamic> statement to support this query.
 < /DIV>
With the increment of the condition, more sqls will be added,it's difficult to maintain.
So i can't agree to your opinions of "the dynamic tag is simpler".
And which one is easy to understand, "java code" or xml.
for me,8 <dynamic> xml will be more difficult to maintain and understand.
 
If you have a good solution or any idea,just give me,
Thanks for your help.
 
Addtionaly:
why I need to implement a dao to support ojb,hibernate and ibatis,even jdbc.
because our company has some products to sell,some time these products is needed to work with some products from other companies.
So w e must have a common dao to support plantation.
 
 
 
 >
> As far as I can tell, the dynamic SQL example you gave is shorter than
> the Java code you wrote (if you get rid of the redundant CDATA sections).
>
> That said, I understand your point. A future goal for iBATIS SQL Maps
> (Data Mapper) will be to more easily support ad-hoc queries and
> configuration via the Java API. This will help you get to where you want
> to be. Unfortunatley it's not available yet.
>
> Cheers,
> Clinton
>
> wang lei wrote:
>
>> At first, thanks for the quick reply from Brandon Goodin.
>> I use java for 3 years.
>> My major work is to provide small base libraries or swing and swt
>> controls for the developers in our company.
>> I don't have much experien ce in big projects.
>> So my opinions is just based on the small or medium projects.
>> My idea for "design" is simple. I try to make the developer know how
>> to use my library in 1-3 hours.The simplicity is what i need.
>> I think i understand what Brandon Goodin said.
>> The strength of ibatis is make it easy to use the database's
>> characteristic.
>> If i use ibatis,i should use sql instead of the "Criteria".
>> But i want more simplicity and flexibility.
>> The following is a example.
>> int id=...
>> int min=...
>> int max=...
>> //get value from the servlet parameter
>> IQuery t_AllQuery = this.dao.newQuery(User.class);
>> if(id>0)
>> {
>> IQuery t_Query = this.dao.newQuery(User.class);
>> t_Query.addEqualTo("equal", new Integer(id));
>>
>> t_AllQuery.addOrCriteria(t_Query);
>> }
>>
>> if(min>0)
>> {
>> IQuery t_Query = this.dao.newQuery(User.class);
>> t_Query.addEqualTo("min", new Integer(min));
>>
>> t_AllQuery.addOrCriteria(t_Query);
>> }
>>
>> if(max<1000000)
>> {
>> IQuery t_Query = this.dao.newQuery(User.class);
>> t_Query.addEqualTo("max", new Integer(max));
>>
>> t_AllQuery.addOrCriteria(t_Query);
>> }
>> the java code above is common in out projects.
>> How many <dynamic> sql i need to write.
>> I write one example.
>> <sql id="selectUserWhere">
>> <dynamic prepend="where">
>> <isPropertyAvailable prepend="and" property="equal">
>> <![CDATA[
>> USER_ID=#equal#
>> ]]>
>> <isPropertyAvailable prepend="or" property="min">
>> <![CDATA[
>> USER_ID>#min#
>> ]]>
>> <isPropertyAvailable prepend="and" property="max">
>> <![CDATA[
>> USER_ID<#"max"#
>> ]]>
>> </isPropertyAvailable>
>> </isPropertyAvailable>
>> </isPropertyAvailable>
>> </dynamic>
>> </sql>
>> <select id="doSelectUser" parameterClass="java.util.Map"
>> resultMap="userResult">
>> <![CDATA[
>> Select USER_ID, USER_NAME, PHOTO, USER_MEMO from DEMO.USER_T
>> ]]>
>> <include refid="selectUserWhere" />
>> </select>
>> If there is no the parameter of "equal".
>> the sql for execution will be
>> "Select USER_ID, USER_NAME, PHOTO, USER_MEMO from DEMO.USER_T".
>> I want to know h ow can i make it easy to handle it.
>>


���Ϊ��С�ա��¿��衢�ż��������ݵ������� --0-1507026052-1139762857=:36077--