List of usage examples for org.hibernate.criterion Restrictions not
public static Criterion not(Criterion expression)
From source file:com.algoTrader.CriteriaSearch.java
/** * Adds an <code>Restrictions</code> to a <code>Criteria</code>. The given <code>parameterValues</code> * represents either an array of <code>String</code> or another object. The different values in the * array are added to a disjunction or conjunction which is connected with logical and to the other criteria of the * search.//from w w w . java 2 s.co m * * @param criteria * @param parameterName * @param parameterValues * @param searchIfNull * @param comparator * @param matchMode */ private void addExpression(Criteria criteria, String parameterName, Object[] parameterValues, int comparator, MatchMode matchMode) { if (parameterValues != null) { Disjunction disjunction = null; Conjunction conjunction = null; switch (comparator) { case SearchParameter.LIKE_COMPARATOR: { disjunction = Restrictions.disjunction(); if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction .add(Restrictions.like(parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.like(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } break; } case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: { disjunction = Restrictions.disjunction(); if ((matchMode != null) && (parameterValues instanceof String[])) { String[] stringParameterValues = (String[]) parameterValues; for (int index = 0; index < parameterValues.length; index++) { if (stringParameterValues[index] != null) { disjunction.add( Restrictions.ilike(parameterName, stringParameterValues[index], matchMode)); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } else { for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.ilike(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } } break; } case SearchParameter.EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.eq(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.ge(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.GREATER_THAN_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.gt(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.le(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.LESS_THAN_COMPARATOR: { disjunction = Restrictions.disjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { disjunction.add(Restrictions.lt(parameterName, parameterValues[index])); } else { disjunction.add(Restrictions.isNull(parameterName)); } } break; } case SearchParameter.IN_COMPARATOR: { criteria.add(Restrictions.in(parameterName, parameterValues)); break; } case SearchParameter.NOT_IN_COMPARATOR: { criteria.add(Restrictions.not(Restrictions.in(parameterName, parameterValues))); break; } case SearchParameter.NOT_EQUAL_COMPARATOR: { conjunction = Restrictions.conjunction(); for (int index = 0; index < parameterValues.length; index++) { if (parameterValues[index] != null) { conjunction.add(Restrictions.ne(parameterName, parameterValues[index])); } else { conjunction.add(Restrictions.isNotNull(parameterName)); } } break; } } if (disjunction != null) { criteria.add(disjunction); } if (conjunction != null) { criteria.add(conjunction); } } else { switch (comparator) { case SearchParameter.EMPTY_COMPARATOR: { criteria.add(Restrictions.isEmpty(parameterName)); break; } case SearchParameter.NOT_EMPTY_COMPARATOR: { criteria.add(Restrictions.isNotEmpty(parameterName)); break; } default: { criteria.add(Restrictions.isNull(parameterName)); } } } }
From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java
@SuppressWarnings("unchecked") @Override/*from ww w . ja v a2 s . co m*/ public List<Factura> getAll() { Criteria criteria = getSession().createCriteria(Factura.class); criteria.add(Restrictions.not(Restrictions.in("estado", new String[] { "RESERVADO" }))); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Factura> list = criteria.list(); return list; }
From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java
@Override public List<Factura> getDiary() { Criteria criteria = getSession().createCriteria(Factura.class); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Date fromDate = calendar.getTime(); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); Date toDate = calendar.getTime(); criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate)); criteria.addOrder(Order.asc("idFactura")); criteria.add(Restrictions.not(Restrictions.in("estado", new String[] { "RESERVADO" }))); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.addOrder(Order.desc("idFactura")); List<Factura> list = criteria.list(); return list;// w ww . j a va2 s . com }
From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java
@Override public List<Factura> getMonth() { Criteria criteria = getSession().createCriteria(Factura.class); Calendar calendar = Calendar.getInstance(); Date toDate = calendar.getTime(); calendar.add(Calendar.MONTH, -1); Date fromDate = calendar.getTime(); criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate)); criteria.add(Restrictions.not(Restrictions.in("estado", new String[] { "RESERVADO" }))); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.addOrder(Order.desc("idFactura")); List<Factura> list = criteria.list(); return list;//from ww w.j av a 2 s .c o m }
From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java
@Override public List<Factura> getDiaryReserva() { Criteria criteria = getSession().createCriteria(Factura.class); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Date fromDate = calendar.getTime(); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); Date toDate = calendar.getTime(); criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate)); criteria.addOrder(Order.desc("idFactura")); criteria.add(Restrictions .not(Restrictions.in("estado", new String[] { "INICIADO", "CONFIRMADO", "CANCELADO" }))); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Factura> list = criteria.list(); return list;//from w ww.j ava2 s . c om }
From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java
@Override public List<Factura> getMonthReserva() { Criteria criteria = getSession().createCriteria(Factura.class); Calendar calendar = Calendar.getInstance(); Date toDate = calendar.getTime(); calendar.add(Calendar.MONTH, -1); Date fromDate = calendar.getTime(); criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate)); criteria.add(Restrictions .not(Restrictions.in("estado", new String[] { "INICIADO", "CONFIRMADO", "CANCELADO" }))); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.addOrder(Order.desc("idFactura")); List<Factura> list = criteria.list(); return list;/*from w w w . j av a2 s. c om*/ }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * ??/*from w w w . j a va 2 s . c o m*/ * * @param dateNow * * @param beforeTime * ??? * @param size * ? * @return ??? */ @Transactional(readOnly = true) public List<I> getCanChaseIssue(Date dateNow, Integer beforeTime, Integer size) { if (null == dateNow) return null; if (null == beforeTime) return null; if (null == size) return null; Class<S> clazz = ReflectionUtils.getSuperClassGenricType(getClass(), 0); DetachedCriteria criteria = DetachedCriteria.forClass(clazz); criteria.add(Restrictions.not(Restrictions.eq("state", IssueState.ISSUE_SATE_FINISH))); criteria.add(Restrictions.gt("endedTime", DateUtils.addMinutes(dateNow, beforeTime))); criteria.addOrder(Order.asc("endedTime")); return issueDataDao.findByDetachedCriteria(criteria, 0, size, true); }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * ??/*from w w w.ja v a 2s . c om*/ * * @param dateNow * * @param beforeTime * ??? * @return ??? */ @Transactional(readOnly = true) public Integer getCanChaseIssueNum(Date dateNow, Integer beforeTime) { if (null == dateNow) return null; if (null == beforeTime) return null; Class<S> clazz = ReflectionUtils.getSuperClassGenricType(getClass(), 0); DetachedCriteria criteria = DetachedCriteria.forClass(clazz); criteria.add(Restrictions.not(Restrictions.eq("state", IssueState.ISSUE_SATE_FINISH))); criteria.add(Restrictions.gt("endedTime", DateUtils.addMinutes(dateNow, beforeTime))); criteria.addOrder(Order.asc("endedTime")); criteria.setProjection(Projections.rowCount()); List<Integer> resultList = schemeDao.findByDetachedCriteria(criteria, true); if (resultList != null && resultList.size() > 0) { return resultList.get(0); } else { return 0; } }
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 av 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 w w . j ava 2 s.c o m * * @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; }