List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
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 ww w. ja v a 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.ProductoDAOImpl.java
@Override public List<Producto> findByBarcode(String barcode) { Criteria criteria = getSession().createCriteria(Producto.class); criteria.add(Restrictions.ilike("codigoProducto", barcode, MatchMode.START)); criteria.add(Restrictions.gt("cantidadTotal", 0)); List<Producto> list = criteria.list(); return list;/*from w ww. ja v a 2 s. c o m*/ }
From source file:com.ar.dev.tierra.api.dao.impl.StockDAOImpl.java
@Override @SuppressWarnings("null") public List<WrapperStock> searchByBarcodeInStock(int sucursal, String barcode) { Criteria criteria = null;// ww w . jav a 2 s. com switch (sucursal) { case 1: criteria = getSession().createCriteria(StockTierra.class); break; case 2: criteria = getSession().createCriteria(StockBebelandia.class); break; case 3: criteria = getSession().createCriteria(StockLibertador.class); break; } criteria.add(Restrictions.eq("estado", true)); Criteria producto = criteria.createCriteria("idProducto"); producto.add(Restrictions.ilike("codigoProducto", barcode, MatchMode.START)); criteria.add(Restrictions.gt("cantidad", 0)); criteria.addOrder(Order.desc("idStock")); List<WrapperStock> list = new ArrayList<>(); switch (sucursal) { case 1: List<StockTierra> tierraList = criteria.list(); for (StockTierra stockTierra : tierraList) { WrapperStock wrapperTierra = new WrapperStock(); wrapperTierra.setStockTierra(stockTierra); list.add(wrapperTierra); } break; case 2: List<StockBebelandia> bebeList = criteria.list(); for (StockBebelandia stockBebelandia : bebeList) { WrapperStock wrapperBebelandia = new WrapperStock(); wrapperBebelandia.setStockBebelandia(stockBebelandia); list.add(wrapperBebelandia); } break; case 3: List<StockLibertador> libertadorList = criteria.list(); for (StockLibertador stockLibertador : libertadorList) { WrapperStock wrapperLibertador = new WrapperStock(); wrapperLibertador.setStockLibertador(stockLibertador); list.add(wrapperLibertador); } break; } return list; }
From source file:com.bean.PropertyUserBean.java
public List<Property> getGenerateListProperty() { Dao dao = new Dao(); Users u = (Users) SessionUtils.getSession().getAttribute("login"); if (u != null) { LogicalExpression logic = null;//from www .j a v a 2 s .c om Criterion cr = Restrictions.eq("users", u); if (publish != null && !publish.equals("")) { Criterion pub = Restrictions.eq("proPublish", Boolean.parseBoolean(publish)); logic = Restrictions.and(cr, pub); } else { Criterion pub = Restrictions.isNotNull("proPublish"); logic = Restrictions.and(cr, pub); } Order o = Order.desc("proPublishDate"); if (fromDate != null) { Criterion from = Restrictions.gt("proCreateDate", fromDate); logic = Restrictions.and(logic, from); } if (toDate != null) { Criterion to = Restrictions.lt("proCreateDate", toDate); logic = Restrictions.and(logic, to); } if (cat != 0) { PropertyType t = new PropertyType(cat); Criterion ca = Restrictions.eq("propertyType", t); logic = Restrictions.and(logic, ca); } listProperty = dao.getByCondition(Property.class, logic, o); } return listProperty; }
From source file:com.bean.SearchBean.java
public void init() { Dao dao = new Dao(); long pMin = 0, pMax = 0, aMin = 0, aMax = 0; try {//from w w w.j av a 2 s . co m pMin = Long.parseLong(this.priceMin); } catch (Exception ex) { } try { pMax = Long.parseLong(this.priceMax); } catch (Exception ex) { } try { aMin = Long.parseLong(this.areaMin); } catch (Exception ex) { } try { aMax = Long.parseLong(this.areaMax); } catch (Exception ex) { } LogicalExpression logic; Criterion district = null; Criterion province; Criterion propertyType = null; Criterion exchange = null; Criterion priceMin; Criterion priceMax; Criterion areaMin; Criterion areaMax; if (this.propertyType != 0) { PropertyType p = new PropertyType(this.propertyType); propertyType = Restrictions.eq("propertyType", p); } else { propertyType = Restrictions.isNotNull("propertyType"); } if (this.exchangeType != 0) { ExchangeType e = new ExchangeType(this.exchangeType); exchange = Restrictions.eq("exchangeType", e); } else { exchange = Restrictions.isNotNull("exchangeType"); } if (districtId != 0) { District d = new District(districtId); district = Restrictions.eq("district", d); } else { if (provinceId != 0) { Province p = (Province) dao.getById1(Province.class, provinceId); //Set<District> list = p.getDistricts(); if (p != null && p.getDistricts().size() > 0) { district = Restrictions.in("district", p.getDistricts()); } else { district = Restrictions.isNull("district"); } } } Criterion cpub = Restrictions.eq("proPublish", true); Criterion stt = Restrictions.eq("proStatus", 0); logic = Restrictions.and(propertyType, exchange); logic = Restrictions.and(logic, stt); logic = Restrictions.and(logic, cpub); if (district != null) { logic = Restrictions.and(logic, district); } if (pMax > 0) { priceMax = Restrictions.between("proPrice", pMin, pMax); logic = Restrictions.and(logic, priceMax); } else { priceMin = Restrictions.gt("proPrice", pMin); logic = Restrictions.and(logic, priceMin); } if (aMax > 0) { areaMax = Restrictions.between("proArea", aMin, aMax); logic = Restrictions.and(logic, areaMax); } else { areaMin = Restrictions.gt("proArea", aMin); logic = Restrictions.and(logic, areaMin); } Order o = Order.desc("proPublishDate"); listSearch = dao.getByCondition(Property.class, logic, o); }
From source file:com.bloatit.data.queries.DaoAbstractQuery.java
License:Open Source License
/** * Creates a criterion on a {@link Comparable} element. * <p>//from w w w. j a va2s .c om * For example: <code> * createNbRestriction(GREATER, "amount", 12) * </code> Will select elements with amount > 12. * </p> * * @param cmp the comparator * @param element the countable element name. * @param nb the number on which we try to compare the <code>element</code> * value. * @return the criterion */ protected final Criterion createNbCriterion(final Comparator cmp, final String element, final Object nb) { switch (cmp) { case EQUAL: return Restrictions.eq(element, nb); case LESS: return Restrictions.lt(element, nb); case LESS_EQUAL: return Restrictions.le(element, nb); case GREATER: return Restrictions.gt(element, nb); case GREATER_EQUAL: return Restrictions.ge(element, nb); default: return Restrictions.eq(element, nb); } }
From source file:com.blue.ssh.core.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,.//from www . java 2s . c o m */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName?"); Criterion criterion = null; // ?MatchTypecriterion switch (matchType) { case EQ: criterion = Restrictions.eq(propertyName, propertyValue); break; case LIKE: criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); break; case LE: criterion = Restrictions.le(propertyName, propertyValue); break; case LT: criterion = Restrictions.lt(propertyName, propertyValue); break; case GE: criterion = Restrictions.ge(propertyName, propertyValue); break; case GT: criterion = Restrictions.gt(propertyName, propertyValue); case NE: criterion = Restrictions.ne(propertyName, propertyValue); } return criterion; }
From source file:com.bookselling.dao.SellingPostDaoImpl.java
private Object[] genericFilter(SellingPostFilterForm criteriaForm, int first, int items, int id) { Criteria criteria = getSession().createCriteria(SellingPost.class); //parse form/* w ww.ja v a 2s. c o m*/ SellingPostFilterForm form = criteriaForm; //get form data String keyword = form.getKeyword(); Double minPrice = form.getMinPrice(); Double maxPrice = form.getMaxPrice(); QuatityFilterType quatityStatus = form.getQuatityStatus(); SellingPostFilterType searchBy = form.getSearchBy(); SellingPostStatus sellingPostStatus[] = form.getSellingPostStatus(); Set<Subject> subjects = form.getSubjects(); Integer subjectIds[] = new Integer[subjects.size()]; Subject subjectsArray[] = subjects.toArray(new Subject[subjectIds.length]); for (int i = 0; i < subjects.size(); i++) subjectIds[i] = subjectsArray[i].getId(); //create criteria criteria.createAlias("purchasingSellingEntity", "bk").createAlias("bk.subjects", "sbj") .createAlias("bk.publisher", "pub").createAlias("seller", "sl").createAlias("sl.account", "acc"); //search by keyword if (keyword != null && !keyword.isEmpty()) { keyword = "%" + keyword.trim() + "%"; if (searchBy == SellingPostFilterType.HEADER) criteria.add(Restrictions.like("header", keyword)); else if (searchBy == SellingPostFilterType.NAME) { criteria.add(Restrictions.like("bk.name", keyword)); //product } else if (searchBy == SellingPostFilterType.PUBLISHER) { criteria.add(Restrictions.like("pub.name", keyword)); } } //search with price range criteria.add(Restrictions.between("bk.sellingPrice", minPrice == null ? 0 : minPrice, maxPrice == null ? Integer.MAX_VALUE : maxPrice)); //search with quatity status if (quatityStatus == QuatityFilterType.AVAILABLE) criteria.add(Restrictions.gt("bk.quatity", 0)); else if (quatityStatus == QuatityFilterType.OUTOFSTOCK) criteria.add(Restrictions.eq("bk.quatity", 0)); //search with selling post status if (sellingPostStatus.length != 0) criteria.add(Restrictions.in("status", sellingPostStatus)); //search with subjects if (subjectIds.length != 0) criteria.add(Restrictions.in("sbj.id", subjectIds)); //get data from form SortType sortType = form.getSortType(); SellingPostOrderType sortByProperty = form.getSortByProperty(); //Set up criteria String propertyName = null; if (sortByProperty == SellingPostOrderType.HEADER) propertyName = "header"; else if (sortByProperty == SellingPostOrderType.NAME) propertyName = "bk.name"; else if (sortByProperty == SellingPostOrderType.PUBLISHER) propertyName = "pub.name"; else if (sortByProperty == SellingPostOrderType.CREATEDDATE) propertyName = "createdDate"; else if (sortByProperty == SellingPostOrderType.PRICE) propertyName = "bk.sellingPrice"; if (id != -1) criteria.add(Restrictions.eq("sl.id", id)); //Ly s dng long rowCount = (long) criteria.setProjection(Projections.countDistinct("id")).uniqueResult(); //Ly id criteria.setProjection(null).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setProjection(Projections.distinct(Projections.id())).setFirstResult(first).setMaxResults(items) .addOrder(sortType == SortType.ASC ? Order.asc(propertyName) : Order.desc(propertyName)); List<Integer> ids = new ArrayList<>(); for (Iterator<Integer> temp = criteria.list().iterator(); temp.hasNext();) ids.add(temp.next()); //Criteria ph Criteria subCriteria = getSession().createCriteria(SellingPost.class); subCriteria.createAlias("purchasingSellingEntity", "bk").createAlias("bk.subjects", "sbj") .createAlias("bk.publisher", "pub").createAlias("seller", "sl").createAlias("sl.account", "acc") .add(Restrictions.in("id", ids.size() > 0 ? ids : Arrays.asList(-1))) .addOrder(sortType == SortType.ASC ? Order.asc(propertyName) : Order.desc(propertyName)); return new Object[] { subCriteria, rowCount }; }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
@Transactional(readOnly = true) public List<I> getCanOpenResults() { DetachedCriteria criteria = DetachedCriteria.forClass(issueDataDao.getEntityClass()); criteria.add(Restrictions.lt("endedTime", new Date())); criteria.add(Restrictions.gt("endedTime", DateUtils.addDays(new Date(), -1))); criteria.add(Restrictions.eq("state", IssueState.ISSUE_SATE_END)); criteria.addOrder(Order.desc("id")); return issueDataDao.findByDetachedCriteria(criteria, true); }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * ??/*from w w w . ja v a 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); }