ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wang lei <wl_95...@yahoo.com.cn>
Subject Re: dynamic Sql and parameter together
Date Sun, 12 Feb 2006 16:47:37 GMT
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.
   
  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 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 <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.
>>

		
---------------------------------
 想成为冯小刚、陈凯歌、张纪中三大导演的主角吗?
Mime
View raw message