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.

 


雅虎1G免费邮箱百分百防垃圾信
雅虎助手-搜索、杀毒、防骚扰

Reply via email to