コード例 #1
0
ファイル: PmsDaoImpl.java プロジェクト: rsyuxiangyang/myforum
 private Criterion findbyOR(String type, String str, Session session) {
   Criterion criterion = null;
   StringBuffer sbSQL = new StringBuffer("select p.pmid from Pms as p where");
   List<String> srch = new ArrayList<String>();
   str = str.replace("|", ",");
   String[] srchAND = str.split(" and ");
   for (int i = 0; i < srchAND.length; i++) {
     String[] srch_ = srchAND[i].split(" ");
     for (int j = 0; j < srch_.length; j++) {
       if (cn.jsprun.utils.FormDataCheck.isValueString(srch_[j])) {
         srch.add(srch_[j]);
       }
     }
   }
   for (int i = 0; i < srch.size(); i++) {
     sbSQL.append(" p." + type + " like '%" + srch.get(i) + "%' or");
   }
   String sql = sbSQL.substring(0, sbSQL.length() - 2);
   try {
     Query query = session.createQuery(sql);
     List<Integer> list = query.list();
     criterion = Expression.in("pmid", list);
     session.flush();
   } catch (HibernateException e) {
     e.printStackTrace();
     criterion = null;
   }
   return criterion;
 }
コード例 #2
0
ファイル: PmsDaoImpl.java プロジェクト: rsyuxiangyang/myforum
 private Criterion findbyAnd(String type, String str) {
   Criterion criterion = null;
   List<String> srch = new ArrayList<String>();
   String[] srchAND = str.split(" and ");
   for (int i = 0; i < srchAND.length; i++) {
     String[] srch_ = srchAND[i].split(" ");
     for (int j = 0; j < srch_.length; j++) {
       if (cn.jsprun.utils.FormDataCheck.isValueString(srch_[j])) {
         srch.add(srch_[j]);
       }
     }
   }
   try {
     Criterion[] criterionArray = new Criterion[srch.size()];
     for (int i = 0; i < srch.size(); i++) {
       Criterion criterionCount = Expression.like(type, srch.get(i), MatchMode.ANYWHERE);
       criterionArray[i] = criterionCount;
     }
     for (int i = 0; i < criterionArray.length; i++) {
       if (i == 0) {
         criterion = Expression.and(criterionArray[i], criterionArray[i++]);
       } else {
         criterion = Expression.and(criterion, criterionArray[i]);
       }
     }
   } catch (HibernateException e) {
     e.printStackTrace();
     criterion = null;
   }
   return criterion;
 }