List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
From source file:corner.services.tree.MoveUpProcessor.java
License:Apache License
@Override protected void appendQueryReplaceNodeCriteria(Criteria criteria) { criteria.add(Restrictions.lt(TreeAdapter.LEFT_PRO_NAME, getCurrentNode().getLeft())) .add(Restrictions.gt(TreeAdapter.LEFT_PRO_NAME, getParentNode().getLeft())); criteria.addOrder(Order.desc(TreeAdapter.LEFT_PRO_NAME)); }
From source file:corner.tree.services.impl.AbstractMoveTreeNodeProcessor.java
License:Apache License
/** * //from w ww . j a v a2 s . co m * * @return */ protected TreeAdapter getParentNode() { if (this.parentNode != null) { return this.parentNode; } if (node.getDepth() > 1) {// ?,? List<?> list = hibernateEntityService.executeFind(new HibernateCallback() { /** * @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session) */ @Override 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; }
From source file:cz.jirutka.rsql.hibernate.AbstractCriterionBuilder.java
License:Open Source License
/** * Apply a "greater than" constraint to the named property. * /* w ww. j a v a 2 s .c o m*/ * @param propertyPath property name prefixed with an association alias * @param argument value * @return Criterion */ protected Criterion createGreaterThan(String propertyPath, Object argument) { return Restrictions.gt(propertyPath, argument); }
From source file:cz.jirutka.rsql.hibernate.AbstractCriterionBuilderTest.java
License:Open Source License
@Test public void testCreateCriterion3args() { String property = "foo"; Criterion exptected;/*from w w w . j ava 2 s . co m*/ Criterion actual; exptected = Restrictions.eq(property, "bar"); actual = instance.createCriterion(property, Comparison.EQUAL, "bar"); assertEquals(exptected.toString(), actual.toString()); exptected = Restrictions.ilike(property, "bar%"); actual = instance.createCriterion(property, Comparison.EQUAL, "bar*"); assertEquals(exptected.toString(), actual.toString()); exptected = Restrictions.ne(property, "bar"); actual = instance.createCriterion(property, Comparison.NOT_EQUAL, "bar"); assertEquals(exptected.toString(), actual.toString()); exptected = Restrictions.not(Restrictions.ilike(property, "%bar")); actual = instance.createCriterion(property, Comparison.NOT_EQUAL, "*bar"); assertEquals(exptected.toString(), actual.toString()); exptected = Restrictions.gt(property, 42); actual = instance.createCriterion(property, Comparison.GREATER_THAN, 42); assertEquals(exptected.toString(), actual.toString()); exptected = Restrictions.ge(property, -42); actual = instance.createCriterion(property, Comparison.GREATER_EQUAL, -42); assertEquals(exptected.toString(), actual.toString()); exptected = Restrictions.lt(property, 42.2); actual = instance.createCriterion(property, Comparison.LESS_THAN, 42.2); assertEquals(exptected.toString(), actual.toString()); exptected = Restrictions.le(property, -42.2); actual = instance.createCriterion(property, Comparison.LESS_EQUAL, -42.2); assertEquals(exptected.toString(), actual.toString()); }
From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java
License:Apache License
@Override public Criterion visit(ComparisonNode node) { String name = node.getSelector(); /*// www. j av a 2s . com Get the path and property names */ Tuple<Type, String>[] path = getPath(root, name); Type type = getType(path); boolean isPrimitive = type instanceof StringRepresentableType; boolean isCustom = type instanceof CustomType; boolean isCollection = type instanceof CollectionType; String exp = getExpression(path, isCollection); List<Object> arguments = new ArrayList<Object>(node.getArguments().size()); for (String argument : node.getArguments()) { Object value = argument; if (isPrimitive) { value = ((StringRepresentableType) type).fromStringValue((String) value); } else if (isCustom) { value = ((CustomType) type).stringToObject((String) value); } else if (isCollection) { value = IntegerType.INSTANCE.fromString((String) value); } if (value instanceof String) { value = toSqlWildcardString((String) value); } arguments.add(value); } ComparisonOperator operator = node.getOperator(); assert arguments.size() >= 1; Object firstArgument = arguments.get(0); if (operator.equals(RSQLOperators.EQUAL)) { if (!isCollection) { if (String.class.isInstance(firstArgument) && ((String) firstArgument).contains("%")) { return Restrictions.ilike(exp, firstArgument); } else { return Restrictions.eq(exp, firstArgument); } } else { return Restrictions.sizeEq(exp, (Integer) firstArgument); } } else if (operator.equals(RSQLOperators.NOT_EQUAL)) { if (!isCollection) { if (String.class.isInstance(firstArgument) && ((String) firstArgument).contains("%")) { return Restrictions.not(Restrictions.ilike(exp, firstArgument)); } else { return Restrictions.ne(exp, firstArgument); } } else { return Restrictions.sizeNe(exp, (Integer) firstArgument); } } else if (operator.equals(RSQLOperators.GREATER_THAN)) { if (!isCollection) { return Restrictions.gt(exp, firstArgument); } else { return Restrictions.sizeGt(exp, (Integer) firstArgument); } } else if (operator.equals(RSQLOperators.GREATER_THAN_OR_EQUAL)) { if (!isCollection) { return Restrictions.ge(exp, firstArgument); } else { return Restrictions.sizeGe(exp, (Integer) firstArgument); } } else if (operator.equals(RSQLOperators.LESS_THAN)) { if (!isCollection) { return Restrictions.lt(exp, firstArgument); } else { return Restrictions.sizeLt(exp, (Integer) firstArgument); } } else if (operator.equals(RSQLOperators.LESS_THAN_OR_EQUAL)) { if (!isCollection) { return Restrictions.le(exp, firstArgument); } else { return Restrictions.sizeLe(exp, (Integer) firstArgument); } } else if (operator.equals(RSQLOperators.IN)) { if (!isCollection) { return Restrictions.in(exp, arguments); } } else if (operator.equals(RSQLOperators.NOT_IN)) { if (!isCollection) { return Restrictions.not(Restrictions.in(exp, arguments)); } } throw new IllegalArgumentException("Unknown operation " + operator.toString() + " for property" + name); }
From source file:cz.muni.fi.spc.SchedVis.model.entities.Event.java
License:Open Source License
/** * Get the event that immediately follows the specified event with relation to * the given machine./* ww w . j av a 2 s. c o m*/ * * @param evt * The event in question. * @param m * ID of the machine in question. If null, no machine is considered. * * @return The next event. */ public static Event getNext(final Event evt, final Machine m) { final Criteria crit = BaseEntity.getCriteria(Job.class); crit.addOrder(Order.asc("id")); crit.add(Restrictions.gt("parent", evt)); if (m != null) { crit.add(Restrictions.eq("machine", m)); } crit.setMaxResults(1); final Job job = (Job) crit.uniqueResult(); if (job == null) { return Event.getLast(); } return job.getParent(); }
From source file:d4n1x.photosocial.DAO.impl.PhotoDAOImpl.java
License:Open Source License
@Override public List<Photo> getNewPhotos() throws Exception { List<Photo> new_photos = null; Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR_OF_DAY, -12); Session session = factory.openSession(); try {//from w w w . j a va 2 s . com Criteria cr = session.createCriteria(Photo.class); cr.add(Restrictions.gt("upload_data", cal.getTime())); cr.setMaxResults(10); new_photos = (List<Photo>) cr.list(); } catch (RuntimeException e) { System.out.println("ERROR_DAO: " + e.getMessage()); } finally { session.close(); } return new_photos; }
From source file:data.dao.CarDao.java
public List<Car> getCarLesserPrice(BigDecimal price) { Criteria cr = currentSession().createCriteria(getSupportedClass()); cr.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); cr.add(Restrictions.le("cmPrice", price.doubleValue())); cr.add(Restrictions.gt("cmPrice", Double.valueOf("0.0"))); return cr.list(); }
From source file:de.arago.rike.activitylog.json.PollUpdates.java
License:Open Source License
@Override public Map execute(IDataWrapper data) throws Exception { JSONObject result = new JSONObject(); result.put("count", 0); String lastId = data.getRequestAttribute("id"); if (lastId != null && !lastId.isEmpty()) { final DataHelperRike<ActivityLog> helper = new DataHelperRike<ActivityLog>(ActivityLog.class); List<ActivityLog> list = helper .list(helper.filter().add(Restrictions.gt("id", Long.valueOf(lastId, 10)))); result.put("count", list.size()); }/*from w ww . j av a2s .co m*/ return result; }
From source file:de.arago.rike.commons.util.MilestoneHelper.java
License:Open Source License
public static List<Milestone> listNotExpired() { DataHelperRike<Milestone> helper = new DataHelperRike<Milestone>(Milestone.class); return helper.list(helper.filter() .add(Restrictions.or(Restrictions.gt("dueDate", new Date()), Restrictions.isNull("dueDate"))) .addOrder(Order.asc("dueDate")).addOrder(Order.asc("title"))); }