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; }
/** * Gets a list of all calendars available sorted by primary key. * * @return List of Calendar * @throws Exception */ public Set getCalendarList(List roles, List groups, Session session) throws Exception { List result = null; Query q = session.createQuery("from Calendar calendar order by calendar.id"); Criteria criteria = session.createCriteria(Calendar.class); criteria.createCriteria("owningRoles").add(Expression.in("name", roles.toArray())); if (groups.size() > 0) criteria.createCriteria("owningGroups").add(Expression.in("name", groups.toArray())); criteria.addOrder(Order.asc("name")); // result = criteria.list(); // return result; Set set = new LinkedHashSet(); set.addAll(criteria.list()); return set; }
public static void main(String[] args) throws Exception { Criteria c = HibernateUtil.currentSession().createCriteria(GuiaSimples.class); c.add(Expression.ge("dataAtendimento", Utils.parse("21/02/2008"))); c.add(Expression.le("dataAtendimento", Utils.parse("20/07/2008"))); c.add(Expression.in("situacao.descricao", situacoes)); alimentarMapa(c.list()); processarArquivo(); }
/** * Gets a list of all calendars not subscribed to sorted by primary key. * * @return List of Calendar * @throws Exception */ public Set getUnsubscribedCalendarList(String email, Session session) throws Exception { List result = null; Set subscriptions = SubscriptionController.getController().getSubscriberList(email, session); List subscriptionsList = new ArrayList(); Iterator i = subscriptions.iterator(); while (i.hasNext()) { Subscriber subscriber = (Subscriber) i.next(); subscriptionsList.add(subscriber.getCalendar().getId()); } Criteria criteria = session.createCriteria(Calendar.class); if (subscriptionsList.size() > 0) criteria.add(Expression.not(Expression.in("id", subscriptionsList.toArray()))); criteria.addOrder(Order.asc("name")); Set set = new LinkedHashSet(); set.addAll(criteria.list()); return set; }