List of usage examples for org.hibernate.criterion Restrictions lt
public static SimpleExpression lt(String propertyName, Object value)
From source file:corner.services.tree.MoveDownProcessor.java
License:Apache License
@Override protected void appendQueryReplaceNodeCriteria(Criteria criteria) { criteria.add(Restrictions.gt(TreeAdapter.RIGHT_PRO_NAME, getCurrentNode().getRight())) .add(Restrictions.lt(TreeAdapter.RIGHT_PRO_NAME, getParentNode().getRight())); criteria.addOrder(Order.asc(TreeAdapter.LEFT_PRO_NAME)); }
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 w w. j a v a2 s .c o 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 "less than" constraint to the named property. * //from w w w .j a va 2s . com * @param propertyPath property name prefixed with an association alias * @param argument value * @return Criterion */ protected Criterion createLessThan(String propertyPath, Object argument) { return Restrictions.lt(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 .ja va 2s .com*/ 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(); /*/* w w w . j ava 2 s. co m*/ 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 preceeds the specified event, with relation * to a given machine.// www. j av a2 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 previous event. */ public static Event getPrevious(final Event evt, final Machine m) { final Criteria crit = BaseEntity.getCriteria(Job.class); crit.addOrder(Order.desc("id")); crit.add(Restrictions.lt("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.getFirst(); } return job.getParent(); }
From source file:dao.CondominioDAO.java
public static List<Condominio> findByFiltros(Integer idMorador, Date dtInicial, Date dtFinal, boolean emAberto) throws Exception { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession();/*from w ww .j a va 2s . c om*/ Criteria crit = session.createCriteria(Condominio.class); Criteria subCrit = crit.createCriteria("pagamento", "pagamento", JoinType.INNER_JOIN); Criteria subCrit2 = crit.createCriteria("morador", "morador", JoinType.INNER_JOIN); if (emAberto) { subCrit.add(Restrictions.isNull("data")); crit.add(Restrictions.lt("data", new Date())); } if (idMorador != null && idMorador > 0) { subCrit2.add(Restrictions.eq("id", idMorador)); } if (dtInicial != null) { crit.add(Restrictions.ge("data", dtInicial)); } if (dtFinal != null) { crit.add(Restrictions.le("data", dtFinal)); } List<Condominio> list = crit.list(); session.flush(); session.close(); return list; }
From source file:de.appsolve.padelcampus.admin.controller.events.AdminEventsController.java
@RequestMapping(method = GET, value = "/{status}") public ModelAndView showEvents(HttpServletRequest request, Pageable pageable, @RequestParam(required = false, name = "search") String search, @PathVariable("status") String status) { Set<Criterion> criterions = new HashSet<>(); LocalDate today = new LocalDate(Constants.DEFAULT_TIMEZONE); if (status.equals("current")) { criterions.add(Restrictions.ge("endDate", today)); } else {// w w w . ja v a 2s . c o m criterions.add(Restrictions.lt("endDate", today)); } Page<Event> page; if (!StringUtils.isEmpty(search)) { page = eventDAO.findAllByFuzzySearch(search, criterions, "participants", "participants.players"); } else { page = eventDAO.findAllFetchWithParticipantsAndPlayers(pageable, criterions); } ModelAndView mav = new ModelAndView(getModuleName() + "/events"); mav.addObject("Page", page); mav.addObject("Models", page.getContent()); mav.addObject("moduleName", getModuleName()); mav.addObject("status", status); return mav; }
From source file:de.arago.rike.zombie.ZombieHelper.java
License:Open Source License
public static List<Task> getOverdueTasks() { DataHelperRike<Task> helper = new DataHelperRike<Task>(Task.class); Criteria crit = helper.filter().add(Restrictions.isNotNull("dueDate")) .add(Restrictions.lt("dueDate", new Date())) .add(Restrictions.ne("status", Task.Status.DONE.toString().toLowerCase())) .addOrder(Order.asc("dueDate")); return helper.list(crit); }