List of usage examples for org.hibernate.criterion Restrictions lt
public static SimpleExpression lt(String propertyName, Object value)
From source file:com.xbwl.common.orm.hibernate.HibernateDao.java
License:Apache License
/** * Criterion,.//from www. j a va 2 s .c o m */ protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName"); Criterion criterion = null; try { //MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue); } else if (MatchType.LIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:com.xin.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./*from w w w .j av a 2s . com*/ */ protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { AssertUtils.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); } return criterion; }
From source file:com.yahoo.elide.datastores.hibernate3.filter.CriterionFilterOperation.java
License:Apache License
@Override public Criterion apply(FilterPredicate filterPredicate) { List<FilterPredicate.PathElement> path = filterPredicate.getPath(); /* If the predicate refers to a nested association, the restriction should be 'alias.fieldName' */ String alias;//from w w w . j a va 2s . co m if (path.size() > 1) { alias = getAlias(path); alias = alias + "." + path.get(path.size() - 1).getFieldName(); /* If the predicate refers to the root entity, the restriction should be 'fieldName' */ } else { alias = path.get(0).getFieldName(); } switch (filterPredicate.getOperator()) { case IN: if (filterPredicate.getValues().isEmpty()) { return Restrictions.sqlRestriction("(false)"); } return Restrictions.in(alias, filterPredicate.getValues()); case NOT: if (filterPredicate.getValues().isEmpty()) { return Restrictions.sqlRestriction("(true)"); } return Restrictions.not(Restrictions.in(alias, filterPredicate.getValues())); case PREFIX: return Restrictions.like(alias, filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case PREFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case POSTFIX: return Restrictions.like(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)); case POSTFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)); case INFIX: return Restrictions.like(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case INFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case ISNULL: return Restrictions.isNull(alias); case NOTNULL: return Restrictions.isNotNull(alias); case LT: return Restrictions.lt(alias, filterPredicate.getValues().get(0)); case LE: return Restrictions.le(alias, filterPredicate.getValues().get(0)); case GT: return Restrictions.gt(alias, filterPredicate.getValues().get(0)); case GE: return Restrictions.ge(alias, filterPredicate.getValues().get(0)); case TRUE: return Restrictions.sqlRestriction("(true)"); case FALSE: return Restrictions.sqlRestriction("(false)"); default: throw new InvalidPredicateException("Operator not implemented: " + filterPredicate.getOperator()); } }
From source file:com.zhima.base.dao.BaseDao.java
License:Open Source License
/** * ?criteriaeq,gt,ge,lt,le?/* w w w . j av a 2 s .c om*/ * * @param criteria * @param list * ?? */ @SuppressWarnings("rawtypes") private void setExpression(Criteria criteria, String[] list, String expression, Object dto) { Class dtoClass = dto.getClass(); try { for (String str : list) { if (str != null && !"".equals(str.trim())) { Field dtoField = dtoClass.getDeclaredField(str); dtoField.setAccessible(true); if (dtoField != null) { if (HibernateConstrant.HIBERNATE_CRITERIA_EQ.equals(expression)) { criteria.add(Restrictions.eq(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_GE.equals(expression)) { criteria.add(Restrictions.gt(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_GT.equals(expression)) { criteria.add(Restrictions.ge(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_LT.equals(expression)) { criteria.add(Restrictions.lt(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_LE.equals(expression)) { criteria.add(Restrictions.le(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_NE.equals(expression)) { criteria.add(Restrictions.ne(str, dtoField.get(dto))); } else if (HibernateConstrant.HIBERNATE_CRITERIA_LIKE.equals(expression)) { criteria.add(Restrictions.like(str, "%" + dtoField.get(dto) + "%")); } } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.zutubi.pulse.master.model.persistence.hibernate.HibernateBuildResultDao.java
License:Apache License
public BuildResult findPreviousBuildResultWithRevision(final BuildResult result, final ResultState[] states) { return getHibernateTemplate().execute(new HibernateCallback<BuildResult>() { public BuildResult doInHibernate(Session session) throws HibernateException { Criteria criteria = getBuildResultCriteria(session, result.getProject(), states, false); criteria.add(Restrictions.lt("number", result.getNumber())); criteria.add(Restrictions.eq("userRevision", false)); criteria.add(Restrictions.isNotNull("revisionString")); criteria.setMaxResults(1);//from w ww. j a va2 s .c o m criteria.addOrder(Order.desc("number")); return (BuildResult) criteria.uniqueResult(); } }); }
From source file:com.zutubi.pulse.master.model.persistence.hibernate.HibernateBuildResultDao.java
License:Apache License
public List<BuildResult> findByBeforeBuild(final long buildId, final int maxResults, final ResultState... states) { final BuildResult result = findById(buildId); List<BuildResult> results = getHibernateTemplate().execute(new HibernateCallback<List<BuildResult>>() { public List<BuildResult> doInHibernate(Session session) throws HibernateException { Criteria criteria = getBuildResultCriteria(session, result.getProject(), states, result.isPersonal()); criteria.add(Restrictions.lt("id", buildId)); if (result.isPersonal()) { criteria.add(Restrictions.eq("user", result.getUser())); }//from w w w.j a va2 s .c o m criteria.addOrder(Order.desc("id")); criteria.setMaxResults(maxResults); return criteria.list(); } }); return newArrayList(reverse(results)); }
From source file:controlers.GuestControler.java
public String traziFestivale() { porukaZaPretragu = ""; Session session = null;//from ww w.j a va 2 s .c om Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Criteria cr = session.createCriteria(Festival.class); if (nazivFestivala != null && !nazivFestivala.equals("") && !nazivFestivala.equals(" ")) cr.add(Restrictions.like("naziv", "%" + nazivFestivala + "%")); if (datumOd != null) cr.add(Restrictions.gt("datumVremeOd", datumOd)); if (datumDo != null) cr.add(Restrictions.lt("datumVremeOd", datumDo)); if (mesto != null && !mesto.equals("") && !mesto.equals(" ")) cr.add(Restrictions.like("mesto", "%" + mesto + "%")); List result = cr.list(); if (izvodjac != null && !izvodjac.equals("") && !izvodjac.equals(" ")) { for (int j = 0; j < result.size(); j++) { Festival oneFest = (Festival) result.get(j); if (oneFest.getIzvodjacs() != null && oneFest.getIzvodjacs().size() > 0) { boolean founded = false; for (Izvodjac izv : (Set<Izvodjac>) oneFest.getIzvodjacs()) if (izv.getNaziv().toLowerCase().contains(izvodjac.toLowerCase())) { founded = true; break; } if (!founded) { result.remove(oneFest); j--; } } else { result.remove(oneFest); j--; } } } trazeniFestivali = (List<Festival>) result; } catch (Exception ex) { if (tx != null) tx.rollback(); ex.printStackTrace(); } finally { if (tx != null) tx.commit(); session.close(); } return "indexguest"; }
From source file:controlers.UserControler.java
public String traziFestivale() { porukaZaPretragu = ""; Session session = null;// www . j av a2 s . c o m Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Criteria cr = session.createCriteria(Festival.class); if (nazivFestivala != null && !nazivFestivala.equals("") && !nazivFestivala.equals(" ")) cr.add(Restrictions.like("naziv", "%" + nazivFestivala + "%")); if (datumOd != null) cr.add(Restrictions.gt("datumVremeOd", datumOd)); if (datumDo != null) cr.add(Restrictions.lt("datumVremeOd", datumDo)); if (mesto != null && !mesto.equals("") && !mesto.equals(" ")) cr.add(Restrictions.like("mesto", "%" + mesto + "%")); cr.add(Restrictions.gt("datumVremeDo", new Date())); List result = cr.list(); if (izvodjac != null && !izvodjac.equals("") && !izvodjac.equals(" ")) { for (int j = 0; j < result.size(); j++) { Festival oneFest = (Festival) result.get(j); if (oneFest.getIzvodjacs() != null && oneFest.getIzvodjacs().size() > 0) { boolean founded = false; for (Izvodjac izv : (Set<Izvodjac>) oneFest.getIzvodjacs()) if (izv.getNaziv().toLowerCase().contains(izvodjac.toLowerCase())) { founded = true; break; } if (!founded) { result.remove(oneFest); j--; } } else { result.remove(oneFest); j--; } } } trazeniFestivali = (List<Festival>) result; } catch (Exception ex) { if (tx != null) tx.rollback(); ex.printStackTrace(); } finally { if (tx != null) tx.commit(); session.close(); } return "index"; }
From source file:corner.service.tree.TreeService.java
License:Apache License
/** * //from ww w.ja v a 2 s . c o m * @param page * * @param clazz class * @param depend * @param depth ? */ public List getDepthTree(IPage page, Class clazz, String[] depends, int depth, int left, int right) { DetachedCriteria criteria = DetachedCriteria.forClass(clazz); if (depth == 1) { // select * from MP_S_ACCOUNT_ITEM_CODE where tree_depth = 1; criteria.add(Restrictions.eq(ITreeAdaptor.DEPTH_PRO_NAME, depth)); } else { // select * from MP_S_ACCOUNT_ITEM_CODE where tree_depth = 2 and tree_left_code > 1 and tree_right_code < 8; Criterion leftright = Restrictions.and(Restrictions.gt(ITreeAdaptor.LEFT_PRO_NAME, left), Restrictions.lt(ITreeAdaptor.RIGHT_PRO_NAME, right)); criteria.add(Restrictions.and(Restrictions.eq(ITreeAdaptor.DEPTH_PRO_NAME, depth), leftright)); } // if (page instanceof ITreeQueryPage) { ((ITreeQueryPage) page).appendCriteria(criteria, depends); } criteria.addOrder(Order.asc(ITreeAdaptor.LEFT_PRO_NAME)); return findByCriteria(criteria); }
From source file:corner.services.tree.AbstractMoveTreeNodeProcessor.java
License:Apache License
/** * /*from www . j av a2 s . c o m*/ * * @return */ protected TreeAdapter getParentNode() { if (this.parentNode != null) { return this.parentNode; } if (node.getDepth() > 1) {// ?,? List<?> list = service.executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(treeClassName); /** * ? ??? ?? ? -1 */ criteria.add(Restrictions.gt(TreeAdapter.RIGHT_PRO_NAME, node.getRight())) .add(Restrictions.lt(TreeAdapter.LEFT_PRO_NAME, node.getLeft())); criteria.addOrder(Order.desc(TreeAdapter.LEFT_PRO_NAME)); criteria.setFirstResult(0); criteria.setMaxResults(1); return criteria.list(); } }); if (list.size() != 1) { // throw new RuntimeException("?(" + node.getLeft() + "," + node.getRight() + ")"); } parentNode = (TreeAdapter) list.get(0); } else { // ,? parentNode = constructRootNode(); } return parentNode; }