List of usage examples for org.hibernate.criterion Projections groupProperty
public static PropertyProjection groupProperty(String propertyName)
From source file:ca.myewb.controllers.chapter.FindDupes.java
License:Open Source License
private void findEmailMatch(Context ctx, String toMatch, String key) { int maxSize = 11; String query = "SELECT userid FROM useremails e WHERE e.email LIKE '%" + toMatch + "%'"; List ids = HibernateUtil.currentSession().createSQLQuery(query).list(); if (ids.isEmpty()) { ctx.put(key, new Vector()); return;//from ww w. ja v a 2 s . c o m } Criteria crit = hibernateSession.createCriteria(UserModel.class); List uniqueResultsList = crit.add(Restrictions.in("id", ids)).add(Restrictions.ne("id", new Integer(1))) .setProjection(Projections.groupProperty("id")).setMaxResults(maxSize).list(); Vector<UserModel> uniqueResults = new Vector<UserModel>(); if (uniqueResultsList.size() < maxSize) { Iterator iter = uniqueResultsList.iterator(); while (iter.hasNext()) { Integer i = (Integer) iter.next(); // This try/catch block is a workaround to the deleted-admin-causes-cgilib-blowup bug try { uniqueResults.add((UserModel) hibernateSession.get(UserModel.class, i)); } catch (Exception e) { log.warn("Unable to add user to usersearch: id " + i.toString()); } } ctx.put(key, uniqueResults); } }
From source file:ca.myewb.controllers.chapter.FindDupes.java
License:Open Source License
private void findNameMatch(Context ctx, UserModel targetUser, String key) { int maxSize = 11; Criteria crit = hibernateSession.createCriteria(UserModel.class); List uniqueResultsList = crit.add(Restrictions.eq("firstname", targetUser.getFirstname())) .add(Restrictions.eq("lastname", targetUser.getLastname())) .add(Restrictions.ne("id", new Integer(1))).setProjection(Projections.groupProperty("id")) .setMaxResults(maxSize).list(); Vector<UserModel> uniqueResults = new Vector<UserModel>(); if (uniqueResultsList.size() < maxSize) { Iterator iter = uniqueResultsList.iterator(); while (iter.hasNext()) { Integer i = (Integer) iter.next(); // This try/catch block is a workaround to the deleted-admin-causes-cgilib-blowup bug try { uniqueResults.add((UserModel) hibernateSession.get(UserModel.class, i)); } catch (Exception e) { log.warn("Unable to add user to usersearch: id " + i.toString()); }// w ww . j av a 2s. c o m } ctx.put(key, uniqueResults); } }
From source file:ca.myewb.controllers.chapter.FindDupes.java
License:Open Source License
private void findUsernameMatch(Context ctx, UserModel targetUser, String key) { int maxSize = 11; Criteria crit = hibernateSession.createCriteria(UserModel.class); List uniqueResultsList = crit .add(Restrictions.like("username", "%" + targetUser.getEmail().split("@")[0] + "%")) .add(Restrictions.ne("id", new Integer(1))).setProjection(Projections.groupProperty("id")) .setMaxResults(maxSize).list(); Vector<UserModel> uniqueResults = new Vector<UserModel>(); if (uniqueResultsList.size() < maxSize) { Iterator iter = uniqueResultsList.iterator(); while (iter.hasNext()) { Integer i = (Integer) iter.next(); // This try/catch block is a workaround to the deleted-admin-causes-cgilib-blowup bug try { uniqueResults.add((UserModel) hibernateSession.get(UserModel.class, i)); } catch (Exception e) { log.warn("Unable to add user to usersearch: id " + i.toString()); }// w ww . ja v a2 s.c o m } ctx.put(key, uniqueResults); } }
From source file:ca.myewb.controllers.common.EventList.java
License:Open Source License
private List<EventModel> getUniqueEventList(Criteria criteria) { criteria.setProjection(Projections.groupProperty("id")); Iterator it = criteria.list().iterator(); List<EventModel> list = new ArrayList<EventModel>(); while (it.hasNext()) { list.add((EventModel) hibernateSession.load(EventModel.class, (Integer) it.next())); }//from w w w .j a v a2 s . c om return list; }
From source file:ca.myewb.controllers.common.EventList.java
License:Open Source License
private int getUniqueEventCount(Criteria criteria) { criteria.setProjection(Projections.groupProperty("id")); return criteria.list().size(); }
From source file:ca.myewb.controllers.common.Member.java
License:Open Source License
private void searchMode(Context ctx) throws Exception, RedirectionException { MemberSearchForm searchForm = null;/* ww w . j av a 2 s. com*/ List result = null; if (currentUser.isAdmin()) { result = hibernateSession.createQuery("FROM GroupChapterModel where visible=true").list(); } // run search, store results in temp list if (requestParams.get("Advanced") != null) { searchForm = new MemberSearchForm(getInterpageVar("membersearchtarget") + "/search", requestParams, true, result); ctx.put("advanced", new Boolean(true)); } else { searchForm = new MemberSearchForm(getInterpageVar("membersearchtarget") + "/search", requestParams, false, result); } Message m = searchForm.validate(); if (m != null) // validation failed, redirect to self, next time we'll be entering the next block { // Display error and prompt user to fix throw getValidationException(searchForm, m, (String) getInterpageVar("membersearchtarget")); } //form validation succeeded! String first = searchForm.getParameter("Firstname"); String last = searchForm.getParameter("Lastname"); String email = searchForm.getParameter("Email"); String city = searchForm.getParameter("City", false); String province = searchForm.getParameter("Province", false); String lang = searchForm.getParameter("Language", false); String gender = searchForm.getParameter("Gender", false); String birth = searchForm.getParameter("Birth", false); String student = searchForm.getParameter("Student", false); String username = searchForm.getParameter("Username", false); Criteria crit = hibernateSession.createCriteria(UserModel.class); if ((username != null) && !username.equals("")) { crit.add(Restrictions.like("username", "%" + username.trim() + "%")); } if ((first != null) && !first.equals("")) { crit.add(Restrictions.like("firstname", "%" + first.trim() + "%")); } if ((last != null) && !last.equals("")) { crit.add(Restrictions.like("lastname", "%" + last.trim() + "%")); } if ((email != null) && !email.equals("")) { List ids = HibernateUtil.currentSession() .createSQLQuery("SELECT userid FROM useremails e WHERE e.email LIKE '%" + email.trim() + "%'") .list(); if (!ids.isEmpty()) { crit.add(Restrictions.in("id", ids)); } else { crit.add(Restrictions.eq("email", "###invalidemail###")); //so that no results are given } } if ((city != null) && !city.equals("")) { crit.add(Restrictions.like("address", "%\n%" + city.trim() + "%\n%")); } if ((province != null) && !province.equals("")) { crit.add(Restrictions.like("address", "%\n%" + province.trim() + "%\n%")); } if ((lang != null) && !lang.equals("")) { crit.add(Restrictions.eq("language", lang.trim())); } if ((gender != null) && !gender.equals("")) { crit.add(Restrictions.eq("gender", gender.trim())); } if ((birth != null) && !birth.equals("")) { crit.add(Restrictions.eq("birth", new Integer(birth))); } if ((student != null) && !student.equals("")) { crit.add(Restrictions.eq("student", new Boolean(student))); } // Get "my" own lead groups, since I can only // see people in groups I lead crit.createAlias("roles", "r"); crit.add(Restrictions.isNull("r.end")); if (!currentUser.isAdmin()) { crit.add(Restrictions.in("r.group", currentUser.getGroups('l'))); } else { GroupChapterModel chapter = null; if (searchForm.getParameter("Chapter", false) != null) { if (!searchForm.getParameter("Chapter", false).equals("")) { chapter = (GroupChapterModel) hibernateSession.get(GroupChapterModel.class, new Integer(searchForm.getParameter("Chapter", false))); } } if (chapter != null) { crit.add(Restrictions.eq("r.group", chapter)); crit.add(Restrictions.eq("r.level", new Character('m'))); } //don't filter out deleted users! } crit.add(Restrictions.ne("id", new Integer(1))); crit.addOrder(Order.asc("lastname")); crit.addOrder(Order.asc("firstname")); crit.setProjection(Projections.groupProperty("id")); crit.setMaxResults(101); List uniqueResultsList = crit.list(); Vector<UserModel> uniqueResults = new Vector<UserModel>(); if (uniqueResultsList.size() < 101) { Iterator iter = uniqueResultsList.iterator(); while (iter.hasNext()) { Integer i = (Integer) iter.next(); // This try/catch block is a workaround to the deleted-admin-causes-cgilib-blowup bug try { uniqueResults.add((UserModel) hibernateSession.get(UserModel.class, i)); } catch (Exception e) { log.warn("Unable to add user to usersearch: id " + i.toString()); } } } else { ctx.put("tooMany", "yes"); } setInterpageVar("membersearchtempresults", uniqueResultsList); ctx.put("tempresults", uniqueResults); //NOT the ids, but the users ctx.put("searchmode", "yes"); if (searchForm == null) { log.info("search form was null!"); throw new RedirectionException(getInterpageVar("membersearchtarget") + "/new"); } ctx.put("form", searchForm); ctx.put("target", getInterpageVar("membersearchtarget")); }
From source file:ca.myewb.controllers.common.PostList.java
License:Open Source License
private int getUniquePostCount(Criteria criteria) { criteria.setProjection(Projections.groupProperty("id")); return criteria.list().size(); }
From source file:ca.myewb.controllers.common.PostList.java
License:Open Source License
private List<PostModel> getUniquePostList(Criteria criteria) { criteria.setProjection(Projections.groupProperty("id")); Iterator it = criteria.list().iterator(); List<PostModel> list = new ArrayList<PostModel>(); while (it.hasNext()) { list.add((PostModel) hibernateSession.load(PostModel.class, (Integer) it.next())); }//from w ww.j a va 2 s. c o m return list; }
From source file:ca.myewb.controllers.common.WhiteboardList.java
License:Open Source License
private List<WhiteboardModel> getUniqueWhiteboardList(Criteria criteria) { criteria.setProjection(Projections.groupProperty("id")); Iterator it = criteria.list().iterator(); List<WhiteboardModel> list = new ArrayList<WhiteboardModel>(); while (it.hasNext()) { list.add((WhiteboardModel) hibernateSession.load(WhiteboardModel.class, (Integer) it.next())); }//from ww w . j a v a2s .c o m return list; }
From source file:ca.myewb.controllers.common.WhiteboardList.java
License:Open Source License
private int getUniqueWhiteboardCount(Criteria criteria) { criteria.setProjection(Projections.groupProperty("id")); return criteria.list().size(); }