List of usage examples for org.hibernate.criterion Restrictions ne
public static SimpleExpression ne(String propertyName, Object value)
From source file:com.cai310.lottery.web.controller.ticket.TicketBaseController.java
public String subsriptionList() { Map map = Maps.newHashMap();// ww w . j a v a 2 s. c o m ReqParamVisitor reqParamVisitor = new ReqParamVisitor(); JsonConfig jsonConfig = new JsonConfig(); try { check(); if (StringUtils.isNotBlank(wParam)) { Map<String, Object> wParam_map = JsonUtil.getMap4Json(wParam); if (null != wParam_map) { Lottery lotteryType = null; if (StringUtils.isNotBlank(wLotteryId)) { try { lotteryType = Lottery.values()[Integer.valueOf(wLotteryId.trim())]; } catch (Exception e) { throw new WebDataException("12-?"); } if (null == lotteryType) { throw new WebDataException("12-?"); } } if (StringUtils.isBlank(start)) { throw new WebDataException("9-"); } try { Integer.valueOf(start); } catch (Exception e) { throw new WebDataException("9-"); } if (StringUtils.isBlank(count)) { throw new WebDataException("10-?"); } try { Integer.valueOf(count); } catch (Exception e) { throw new WebDataException("10-?"); } String orderTypeStr = null == wParam_map.get("orderType") ? null : String.valueOf(wParam_map.get("orderType")); OrderType orderType = null; if (StringUtils.isNotBlank(orderTypeStr)) { try { orderType = OrderType.values()[Integer.valueOf(orderTypeStr)]; } catch (Exception e) { throw new WebDataException("11-?"); } } String playTypeOrdinal = null == wParam_map.get("playTypeOrdinal") ? null : String.valueOf(wParam_map.get("playTypeOrdinal")); String key = wLotteryId + "-" + start + "-" + count + "-" + orderTypeStr + "-" + playTypeOrdinal; /// net.sf.ehcache.Element el = schemeQueryCache.get(key); if (el == null) { List<Criterion> restrictions = Lists.newArrayList(); restrictions.add(Restrictions.eq("shareType", ShareType.TOGETHER)); restrictions.add(Restrictions.eq("state", SchemeState.UNFULL)); switch (getLottery()) { case PL: if (StringUtils.isBlank(playTypeOrdinal)) { throw new WebDataException("12-"); } try { if (Integer.valueOf(0).equals(Integer.valueOf(playTypeOrdinal))) { restrictions.add(Restrictions.eq("playType", PlPlayType.P5Direct)); } else { restrictions.add(Restrictions.ne("playType", PlPlayType.P5Direct)); } } catch (Exception e) { throw new WebDataException("12-"); } break; case SFZC: if (StringUtils.isBlank(playTypeOrdinal)) { throw new WebDataException("12-"); } try { com.cai310.lottery.support.zc.PlayType zcPlayType = com.cai310.lottery.support.zc.PlayType .values()[Integer.valueOf(playTypeOrdinal)]; restrictions.add(Restrictions.eq("playType", zcPlayType)); } catch (Exception e) { throw new WebDataException("12-"); } break; } List<Order> orders = Lists.newArrayList(); if (orderType != null) { switch (orderType) { case CREATE_TIME_DESC: orders.add(Order.desc("id")); break; case CREATE_TIME_ASC: orders.add(Order.asc("id")); break; case PROCESS_RATE_DESC: orders.add(Order.desc("progressRate")); break; case PROCESS_RATE_ASC: orders.add(Order.asc("progressRate")); break; case SCHEME_COST_DESC: orders.add(Order.desc("schemeCost")); break; case SCHEME_COST_ASC: orders.add(Order.asc("schemeCost")); break; } } else { orders.add(Order.desc("orderPriority")); orders.add(Order.asc("state")); orders.add(Order.desc("progressRate")); } orders.add(Order.desc("id")); List<Scheme> list = this.getSchemeEntityManager(lotteryType).findSubsriptionByCriterion( restrictions, orders, Integer.valueOf(start), Integer.valueOf(count)); List<SubsriptionDTO> subsriptionList = Lists.newArrayList(); for (Scheme s : list) { s.setSubscriptions(null); SubsriptionDTO subsriptionDTO = new SubsriptionDTO(); subsriptionDTO.setSchemeId(s.getId()); subsriptionDTO.setLotteryType(lotteryType); subsriptionDTO.setSchemeState(s.getState()); switch (lotteryType) { case PL: PlScheme plScheme = (PlScheme) s; subsriptionDTO.setPlayTypeOrdinal(plScheme.getPlayTypeOrdinal()); break; case SFZC: SfzcScheme sfzcScheme = (SfzcScheme) s; subsriptionDTO.setPlayTypeOrdinal(sfzcScheme.getPlayTypeOrdinal()); break; case WELFARE3D: Welfare3dScheme welfare3dScheme = (Welfare3dScheme) s; subsriptionDTO.setPlayTypeOrdinal(welfare3dScheme.getPlayTypeOrdinal()); break; case DLT: DltScheme dltScheme = (DltScheme) s; subsriptionDTO.setPlayTypeOrdinal(dltScheme.getPlayTypeOrdinal()); break; case DCZC: DczcScheme dczcScheme = (DczcScheme) s; subsriptionDTO.setPlayTypeOrdinal(dczcScheme.getPlayTypeOrdinal()); break; case JCLQ: JclqScheme jclqScheme = (JclqScheme) s; subsriptionDTO.setPlayTypeOrdinal(jclqScheme.getPlayTypeOrdinal()); break; case JCZQ: JczqScheme jczqScheme = (JczqScheme) s; subsriptionDTO.setPlayTypeOrdinal(jczqScheme.getPlayTypeOrdinal()); break; } PropertyUtils.copyProperties(subsriptionDTO, s); subsriptionList.add(subsriptionDTO); } el = new net.sf.ehcache.Element(key, subsriptionList); this.schemeQueryCache.put(el); map.put("processId", "0"); map.put("totalCount", subsriptionList.size()); map.put("list", subsriptionList); } else { List list = (List) el.getValue(); map.put("processId", "0"); map.put("totalCount", list.size()); map.put("list", list); } } } } catch (WebDataException e) { String processId = "7"; if (null != e.getMessage() && e.getMessage().indexOf("-") != -1) { String temp = e.getMessage().split("-")[0]; try { processId = "" + Integer.valueOf(temp); } catch (Exception ex) { } /// Struts2Utils.setAttribute("errorMsg", e.getMessage()); } else { Struts2Utils.setAttribute("errorMsg", ""); } map.put("processId", processId); map.put("errorMsg", e.getMessage()); } catch (ServiceException e) { logger.warn(e.getMessage(), e); String processId = "7"; if (null != e.getMessage() && e.getMessage().indexOf("-") != -1) { String temp = e.getMessage().split("-")[0]; try { processId = "" + Integer.valueOf(temp); } catch (Exception ex) { } /// Struts2Utils.setAttribute("errorMsg", e.getMessage()); } else { Struts2Utils.setAttribute("errorMsg", ""); } map.put("processId", processId); map.put("errorMsg", e.getMessage()); } catch (Exception e) { logger.warn(e.getMessage(), e); String processId = "7"; if (null != e.getMessage() && e.getMessage().indexOf("-") != -1) { String temp = e.getMessage().split("-")[0]; try { processId = "" + Integer.valueOf(temp); } catch (Exception ex) { } /// Struts2Utils.setAttribute("errorMsg", e.getMessage()); } else { Struts2Utils.setAttribute("errorMsg", ""); } map.put("processId", processId); map.put("errorMsg", e.getMessage()); } renderJson(map, jsonConfig); return null; }
From source file:com.cimmyt.model.dao.impl.AbstractDAO.java
License:Apache License
/** * adds a criterion to a Junction(conjunction/disjunction), based on the meta-data passed. * /* w w w . j a v a 2 s .c o m*/ * @param junction The Junction to conditionally add a criterion * @param condition The type of criterion: like, equals, etc. * @param dataType Indicates if its a numeric or character value for a filter * @param qualifiedParam the qualified parameter for a query * @param value The string value to use in the criterion */ public void addDynamicCriterion(Junction junction, Operator condition, DataType dataType, String qualifiedParam, String value) { if (!qualifiedParam.equals("sample.studysampleid")) { if (dataType == DataType.STRING) { if (condition == Operator.TypeString.LIKE) { junction.add(Restrictions.like(qualifiedParam, value, MatchMode.ANYWHERE)); } else if (condition == Operator.TypeString.EQUAL) { junction.add(Restrictions.like(qualifiedParam, value, MatchMode.EXACT)); } else if (condition == Operator.TypeString.NOT_EQUAL) { junction.add(Restrictions.ne(qualifiedParam, value)); } else if (condition == Operator.TypeString.NOT_LIKE) { junction.add(Restrictions.not(Restrictions.like(qualifiedParam, value, MatchMode.ANYWHERE))); } } else if (dataType == DataType.NUMBER) { if (condition == Operator.TypeNumber.EQUALS) { junction.add(Restrictions.eq(qualifiedParam, Integer.valueOf(value))); } else if (condition == Operator.TypeNumber.GREATER) { junction.add(Restrictions.ge(qualifiedParam, Integer.valueOf(value))); } if (condition == Operator.TypeNumber.LESS) { junction.add(Restrictions.le(qualifiedParam, Integer.valueOf(value))); } else if (condition == Operator.TypeNumber.NOT_EQUALS) { junction.add(Restrictions.ne(qualifiedParam, Integer.valueOf(value))); } else if (condition == Operator.TypeNumber.IN) { List<Integer> listStr = new ArrayList<Integer>(); String[] arr = value.split(","); for (int i = 0; i < arr.length; i++) { try { if (!arr[i].trim().equals("")) listStr.add(Integer.parseInt(arr[i])); } catch (Exception ex) { ex.printStackTrace(); } } junction.add(Restrictions.in(qualifiedParam, listStr)); } } } else { String prefix = StrUtils.getPrefixSampleFindString(value); int id = StrUtils.getSampleIDFindString(value); if (prefix.trim().equals("")) prefix = value; if (condition == Operator.TypeString.LIKE) { junction.add(Restrictions.like("study.prefix", prefix, MatchMode.ANYWHERE)); if (id > 0) junction.add(Restrictions.eq("sample.samplegid", id)); } else if (condition == Operator.TypeString.EQUAL) { junction.add(Restrictions.eq("study.prefix", prefix)); if (id > 0) junction.add(Restrictions.eq("sample.samplegid", id)); } else if (condition == Operator.TypeString.NOT_EQUAL) { junction.add(Restrictions.ne("study.prefix", prefix)); if (id > 0) junction.add(Restrictions.ne("sample.samplegid", id)); } else if (condition == Operator.TypeString.NOT_LIKE) { junction.add(Restrictions.not(Restrictions.like("study.prefix", prefix, MatchMode.ANYWHERE))); if (id > 0) junction.add(Restrictions.not(Restrictions.eq("sample.samplegid", id))); } } }
From source file:com.cimmyt.model.dao.impl.SampleDetailDAOImpl.java
License:Apache License
/** * Gets a list of samples from a Study by it ID, excluding samples selected * for SENT to external company and excluding samples in excluedSamples * parameter//from w ww. j a va2 s. c om * * @param labStudyId * Study ID * @param excludedSamples * list of samples to exclude * @return List of samples with matching ID, empty list if not matching ID * or all samples are in excluedSamples */ @Override @SuppressWarnings("unchecked") public List<SampleDetail> getSamplesByStudy(final Integer labStudyId, final List<Integer> excludedSamples) { List<SampleDetail> sampleDetails = null; DetachedCriteria criteria = DetachedCriteria.forClass(SampleDetail.class); criteria.add(Restrictions.eq("labstudyid.labstudyid", labStudyId)); criteria.add(Restrictions.ne("selforsend", ShipmentStatus.FOR_SEND.getId())); if (excludedSamples.size() > 0) { criteria.add(Restrictions.not(Restrictions.in("studysampleid", excludedSamples))); } sampleDetails = (List<SampleDetail>) getHibernateTemplate().findByCriteria(criteria); return sampleDetails; }
From source file:com.court.controller.AssignNewLoanFxmlController.java
public ObservableList<Member> getAllMembers(String except) { Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(Member.class); c.add(Restrictions.ne("memberId", except)); List<Member> mList = c.list(); ObservableList<Member> members = FXCollections.observableArrayList(mList); session.close();//from w w w . j ava 2s .c om return members; }
From source file:com.court.controller.AssignNewLoanFxmlController.java
private Set<Member> getAvailableGuarantors() { Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c1 = session.createCriteria(MemberLoan.class); c1.setProjection(Projections.projectionList().add(Projections.property("isComplete"), "isComplete") .add(Projections.property("guarantors"), "guarantors") .add(Projections.property("member"), "member")); c1.setResultTransformer(Transformers.aliasToBean(MemberLoan.class)); List<MemberLoan> ml = c1.list(); //GET ALL GUARANTORS OF ONGOING LOANS List<String> guarantors = ml.stream().filter(p -> !p.isIsComplete()) .map(m -> m.getGuarantors() + "-" + m.getMember().getMemberId()).collect(Collectors.toList()); Set<String> lkm = new HashSet<>(guarantors); List<String> guarantor_filtered = lkm.stream().map(r -> r = r.split("-")[0]).collect(Collectors.toList()); //GET ALREADY GUARANTED MEMBERS OF THE GARNTOR List<String> alreadyGurantedMembers = ml.stream().filter(p -> !p.isIsComplete()) .filter(p -> p.getMember().getMemberId().equalsIgnoreCase(getMember().getMemberId())) .map(MemberLoan::getGuarantors).collect(Collectors.toList()); //======================== Set<Member> set = new HashSet<>(); //======================== //GET ALL MEMBERS EXCEPT THE LOAN GRANTOR Criteria c2 = session.createCriteria(Member.class); c2.add(Restrictions.ne("memberId", getMember().getMemberId())); c2.add(Restrictions.eq("status", true)); c2.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId") .add(Projections.property("fullName"), "fullName")); c2.setResultTransformer(Transformers.aliasToBean(Member.class)); //IF NO GURANTORS FOUND THEN ALL MEMBERS CAN GUARANT FOR THE LOAN EXCEPT THE LOAN GRANTOR if (getUniqueGuarantors(guarantor_filtered, UNIQUE_GUR_FRQUENCY).isEmpty()) { List<Member> list = c2.list(); set.addAll(list);/*w ww . j av a2s. com*/ // } else { List<Member> list = c2.add(Restrictions .not(Restrictions.in("memberId", getUniqueGuarantors(guarantor_filtered, UNIQUE_GUR_FRQUENCY)))) .list(); set.addAll(list); } //IF NO GUARANTORS AVAILABLE THEY CAN GURANT THE GRANTOR ULTIMATELY UNTIL ALL GUARANTED LOANS END if (!alreadyGurantedMembers.isEmpty()) { Set<Member> arlm = getAlreadyGurantedMembers(alreadyGurantedMembers, session); set.addAll(arlm); } session.close(); return set; }
From source file:com.court.controller.OldLoansFxmlController.java
private Set<Member> getAvailableGuarantors() { String mbrId = mbr_search_txt.getText().split("-")[0].trim(); //GET ALL MEMBERS EXPECT GRANTOR====== Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c2 = session.createCriteria(Member.class); c2.add(Restrictions.ne("memberId", mbrId)); c2.add(Restrictions.eq("status", true)); c2.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId") .add(Projections.property("fullName"), "fullName")); c2.setResultTransformer(Transformers.aliasToBean(Member.class)); List<Member> list = c2.list(); session.close();//from ww w . ja v a 2 s.c o m return new HashSet<>(list); }
From source file:com.cubeia.backoffice.users.dao.UserDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w .j a v a 2s. c o m*/ public Collection<User> findUsersByExample(UserInformation ui, Long operatorId) { Session hbs = getHibernateSession(); Criteria uc = hbs.createCriteria(User.class); uc.add(Restrictions.ne("status", REMOVED)); uc.add(Restrictions.eq("userType", UserType.USER)); if (operatorId != null && operatorId >= 0) { uc.add(Restrictions.eq("operatorId", operatorId)); } Example ex = Example.create(ui); uc.createCriteria("information").add(ex); return uc.list(); }
From source file:com.dell.asm.asmcore.asmmanager.db.DiscoveryResultDAO.java
License:Open Source License
/** * Retrieve DiscoveryResult based on parent job id. * @return the list of discovery results for given parent job id. *//*from w w w. j a va2 s .c o m*/ @SuppressWarnings("unchecked") public List<DiscoveryResultEntity> getDiscoveryResult(String parentJobId, List<SortParamParser.SortInfo> sortInfos, List<FilterParamParser.FilterInfo> filterInfos, PaginationInfo paginationInfo) throws AsmManagerDAOException { Session session = null; Transaction tx = null; List<DiscoveryResultEntity> entityList = new ArrayList<DiscoveryResultEntity>(); logger.debug("getDiscoveryResult for job: " + parentJobId); try { int offset = paginationInfo.getOffset(); int limit = paginationInfo.getLimit(); int pageSize = limit; session = _dao._database.getNewSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(DiscoveryResultEntity.class); BaseDAO.addSortCriteria(criteria, sortInfos); criteria.add(Restrictions.ne("serverType", Server.ServerType.BLADE.value())); // never return blades criteria.add(Restrictions.ne("serverType", Server.ServerType.COMPELLENT.value())); // never return compellents which now show up as iDrac7 List<FilterParamParser.FilterInfo> notFound = BaseDAO.addFilterCriteria(criteria, filterInfos, DiscoveryResultEntity.class); if (notFound != null && notFound.size() > 0) { criteria.createAlias("discoveryResultEntity", "discoveryResultEntityAlias"); for (FilterParamParser.FilterInfo filterInfo : notFound) { criteria.add( Restrictions.eq("discoveryResultEntityAlias.deviceKey", filterInfo.getColumnName())); if (filterInfo.getColumnValue().size() == 1) { criteria.add(Restrictions.eq("discoveryResultEntityAlias.deviceValue", filterInfo.getColumnValue().get(0))); } else if (filterInfo.getColumnValue().size() > 1) { criteria.add(Restrictions.in("discoveryResultEntityAlias.deviceValue", filterInfo.getColumnValue())); } } } //criteria.setFirstResult((pageNumber - 1) * pageSize); criteria.setFirstResult(offset); criteria.setMaxResults(pageSize); entityList = criteria.list(); // Commit transaction. tx.commit(); logger.debug("getDiscoveryResult for job: " + entityList.size()); } catch (Exception e) { logger.warn("Caught exception during get discovery result for job: " + parentJobId + ", " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get device: " + ex); } //throw new AsmManagerDAOException("Caught exception during get discovery result for jobId: " + parentJobId + ", " + e, e); throw new AsmManagerInternalErrorException("Error Getting Discovery result", "DiscoveryResultDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get device: " + ex); } } return entityList; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateUserDao.java
License:Mozilla Public License
public boolean canRemovePermissionFromRole(Integer id, String string) { Long result = (Long) sessionFactory.getCurrentSession().createCriteria(User.class) .createAlias("globalRole", "roleAlias").add(Restrictions.eq("active", true)) .add(Restrictions.eq("isLdapUser", false)).add(Restrictions.eq("roleAlias." + string, true)) .add(Restrictions.ne("roleAlias.id", id)).setProjection(Projections.rowCount()).uniqueResult(); if (result == null || result == 0) { // we also need to do a lookup on groups result += (Long) sessionFactory.getCurrentSession().createCriteria(User.class) .createAlias("groups", "groupAlias").createAlias("groupAlias.globalRole", "roleAlias") .add(Restrictions.eq("active", true)).add(Restrictions.eq("isLdapUser", false)) .add(Restrictions.eq("groupAlias.active", true)) .add(Restrictions.eq("roleAlias." + string, true)).add(Restrictions.ne("roleAlias.id", id)) .setProjection(Projections.rowCount()).uniqueResult(); }/*www .j a v a 2 s .c o m*/ return result != null && result > 0; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateUserDao.java
License:Mozilla Public License
public boolean canRemovePermissionFromUser(Integer id, String string) { Long result = (Long) sessionFactory.getCurrentSession().createCriteria(User.class) .createAlias("globalRole", "roleAlias").add(Restrictions.eq("active", true)) .add(Restrictions.eq("isLdapUser", false)).add(Restrictions.eq("roleAlias." + string, true)) .add(Restrictions.ne("id", id)).setProjection(Projections.rowCount()).uniqueResult(); if (result == null || result == 0) { // we also need to do a lookup on groups result += (Long) sessionFactory.getCurrentSession().createCriteria(User.class) .createAlias("groups", "groupAlias").createAlias("groupAlias.globalRole", "roleAlias") .add(Restrictions.eq("active", true)).add(Restrictions.eq("isLdapUser", false)) .add(Restrictions.eq("groupAlias.active", true)) .add(Restrictions.eq("roleAlias." + string, true)).add(Restrictions.ne("id", id)) .setProjection(Projections.rowCount()).uniqueResult(); }//from w w w. ja va2s .c om return result != null && result > 0; }