List of usage examples for org.hibernate.criterion Restrictions isNull
public static Criterion isNull(String propertyName)
From source file:cz.muni.fi.spc.SchedVis.model.entities.Machine.java
License:Open Source License
/** * Retrieve all the machines in a given group. * // w w w . j a v a2 s. c o m * @param groupId * ID of the group whose machines will be retrieved. If null, * machines in no group are retrieved. * @return The machines. */ @SuppressWarnings("unchecked") public static Set<Machine> getAll(final Integer groupId) { final Criteria crit = BaseEntity.getCriteria(Machine.class); if (groupId != null) { crit.add(Restrictions.eq("group", MachineGroup.getWithId(groupId))); } else { crit.add(Restrictions.isNull("group")); } crit.addOrder(Order.asc("name")); return new TreeSet<Machine>(crit.list()); }
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();/* w w w . j a v a 2 s. co m*/ 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:dao.hibernate.HibernateWorkDAO.java
@Override public Work getApprovedWorkByStudentWithoutFinalURI(Student student) throws EngineDAOException { getSession().beginTransaction();/* w w w . j a va 2 s.c o m*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.isNull(FINAL_FILE_URI)); criteria.add(Restrictions.eq(STUDENT, student)); criteria.add(Restrictions.eq(STATUS, APPROVED)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Work work; try { work = (Work) criteria.uniqueResult(); System.out.println(work); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (work == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return work; }
From source file:dao.parent.Dao.java
protected Criterion nullOrFalse(String fieldName) { return Restrictions.or(Restrictions.isNull(fieldName), Restrictions.eq(fieldName, false)); }
From source file:data.dao.FeatureDao.java
public List<Feature> getGroupOfFeatures(Object cmgId, Object ccoId) { Criteria cr = currentSession().createCriteria(getSupportedClass()); if (cmgId == null && ccoId == null) { return getAllAsc("oldId"); } else {/*from www . j a v a 2 s .co m*/ if (cmgId != null) { if (!cmgId.equals(Long.valueOf("0"))) { //cr.add(cmgId.equals("") ? Restrictions.isNull("cmgId") : Restrictions.eq("cmgId",cmgId)); cr.add(Restrictions.eq("cmgId", cmgId)); } else { cr.add(Restrictions.isNull("cmgId")); } } if (ccoId != null) { //cr.add(ccoId.equals("") ? Restrictions.isNull("ccoId") : Restrictions.eq("ccoId",ccoId)); if (!ccoId.equals(Long.valueOf("0"))) { cr.add(Restrictions.eq("ccoId", ccoId)); } else { cr.add(Restrictions.isNull("ccoId")); } } } return cr.list(); }
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"))); }
From source file:de.congrace.blog4j.dao.CategoryDaoImpl.java
License:Apache License
public int getNextOrderValue(Category parent) { Criteria crit = getCurrentSession().createCriteria(Category.class); if (parent == null) { crit.add(Restrictions.isNull("parentCategory")); } else {/*from w w w .j ava2s.c o m*/ crit.createCriteria("parentCategory").add(Restrictions.idEq(parent.getId())); } crit.setProjection(Projections.rowCount()); return ((Integer) crit.uniqueResult()).intValue(); }
From source file:de.congrace.blog4j.dao.CategoryDaoImpl.java
License:Apache License
public Category getCategoryByOrder(Category parent, int order) { Criteria crit = this.getCurrentSession().createCriteria(Category.class) .add(Restrictions.eq("order", order)); if (parent == null) { crit.add(Restrictions.isNull("parentCategory")); } else {/*from www. j a v a 2s.co m*/ crit.createCriteria("parentCategory").add(Restrictions.idEq(parent.getId())); } return (Category) crit.uniqueResult(); }
From source file:de.congrace.blog4j.dao.CategoryDaoImpl.java
License:Apache License
@Override public List<Category> getAllRootCategories() { return (List<Category>) this.getCurrentSession().createCriteria(Category.class) .add(Restrictions.isNull("parentCategory")).addOrder(Order.asc("order")).list(); }
From source file:de.cosmocode.hibernate.CustomRestrictions.java
License:Apache License
/** * Apply a "not equal" constraint to the named property. * //from ww w.j a va 2 s . c om * <p> * Note: This implementation differs from {@link Restrictions#ne(String, Object)} * because it returns {@link CustomRestrictions#isNotEmpty(String)} * in case value is an empty string and returns an logical or expression * of {@link Restrictions#ne(String, Object)} and {@link Restrictions#isNull(String)}. * </p> * * @param propertyName the name of the property the constraint should be applied to * @param value the actual value the property should be not equals to * @return a new {@link Criterion} */ public static Criterion ne(String propertyName, String value) { if (StringUtils.isEmpty(value)) { return CustomRestrictions.isNotEmpty(propertyName); } else { return Restrictions.or(Restrictions.ne(propertyName, value), Restrictions.isNull(propertyName)); } }