Example usage for org.hibernate.criterion Restrictions isNull

List of usage examples for org.hibernate.criterion Restrictions isNull

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions isNull.

Prototype

public static Criterion isNull(String propertyName) 

Source Link

Document

Apply an "is null" constraint to the named property

Usage

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

public List<DpPessoa> pessoasPorLotacao(Long id, Boolean incluirSublotacoes, Boolean somenteServidor,
        SituacaoFuncionalEnum situacoesFuncionais) throws AplicacaoException {
    if (id == null || id == 0)
        return null;

    DpLotacao lotacao = consultar(id, DpLotacao.class, false);

    List<DpLotacao> sublotacoes = new ArrayList<DpLotacao>();
    sublotacoes.add(lotacao);/*from   w ww  .  j a  va2 s .c om*/
    if (incluirSublotacoes) {
        List<DpLotacao> lotacoes = listarLotacoes();
        boolean continuar = true;
        while (continuar) {
            continuar = false;
            for (DpLotacao lot : lotacoes) {
                if (sublotacoes.contains(lot))
                    continue;
                if (sublotacoes.contains(lot.getLotacaoPai())) {
                    if (!lot.isSubsecretaria()) {
                        sublotacoes.add(lot);
                        continuar = true;
                    }
                }
            }
        }
    }

    List<DpPessoa> lstCompleta = new ArrayList<DpPessoa>();
    for (DpLotacao lot : sublotacoes) {

        Criteria c = HibernateUtil.getSessao().createCriteria(DpPessoa.class);
        c.createAlias("cargo", "c");

        c.add(Restrictions.eq("lotacao.id", lot.getId()));
        if (somenteServidor) {
            c.add(Restrictions.not(Restrictions.in("c.nomeCargo",
                    new String[] { "ESTAGIARIO", "JUIZ SUBSTITUTO", "JUIZ FEDERAL" })));
        }

        c.add(Restrictions.in("situacaoFuncionalPessoa", situacoesFuncionais.getValor()));

        c.add(Restrictions.isNull("dataFimPessoa"));

        c.addOrder(Order.asc("nomePessoa"));

        lstCompleta.addAll((List<DpPessoa>) c.list());

    }
    return lstCompleta;
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

public List<CpConfiguracao> consultarConfiguracoesDesde(Date desde) {
    Criteria c = HibernateUtil.getSessao().createCriteria(CpConfiguracao.class);
    LogicalExpression confsAtivas = Restrictions.and(Restrictions.ge("hisDtIni", desde),
            Restrictions.isNull("hisDtFim"));
    LogicalExpression confsInativas = Restrictions.and(Restrictions.ge("hisDtFim", desde),
            Restrictions.isNotNull("hisDtFim"));
    c.add(Restrictions.or(confsAtivas, confsInativas));
    return c.list();
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

public List<DpPessoa> consultarPorMatriculaEOrgao(Long matricula, Long idOrgaoUsu, boolean pessoasFinalizadas,
        boolean ordemDesc) {
    Criteria c = HibernateUtil.getSessao().createCriteria(DpPessoa.class);
    c.add(Restrictions.eq("matricula", matricula));
    c.add(Restrictions.eq("orgaoUsuario.idOrgaoUsu", idOrgaoUsu));

    if (pessoasFinalizadas) {
        c.add(Restrictions.isNotNull("dataFimPessoa"));
    } else {/* w  w  w . j a  va 2  s  .  c om*/
        c.add(Restrictions.isNull("dataFimPessoa"));
    }
    if (ordemDesc) {
        c.addOrder(Order.desc("dataInicioPessoa"));
    } else {
        c.addOrder(Order.asc("dataInicioPessoa"));
    }

    return c.list();

}

From source file:br.msf.commons.persistence.dao.AbstractEntityDaoBean.java

License:Open Source License

@Override
public Collection<T> findByProperty(final String propertyName, final Object propertyValue,
        final Order... orders) {
    ArgumentUtils.rejectIfNull(propertyName);
    final DetachedCriteria dc = createCriteria().setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    dc.add((propertyValue == null) ? Restrictions.isNull(propertyName)
            : Restrictions.eq(propertyName, propertyValue));
    return findByCriteria(dc, orders);
}

From source file:br.msf.commons.persistence.dao.AbstractEntityDaoBean.java

License:Open Source License

@Override
public Collection<T> findByProperties(final Map<String, Object> properties, final Order... orders) {
    ArgumentUtils.rejectIfEmptyOrNull(properties);
    final DetachedCriteria dc = createCriteria().setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    final Set<Map.Entry<String, Object>> props = properties.entrySet();
    for (Map.Entry<String, Object> entry : props) {
        final String propName = entry.getKey();
        final Object propValue = entry.getValue();
        dc.add((propValue == null) ? Restrictions.isNull(propName) : Restrictions.eq(propName, propValue));
    }//from w  w  w .  j  a  v a 2  s  .  c  om
    return findByCriteria(dc, orders);
}

From source file:br.os.rh.pontoprofessores.PontoProfessoresDAO.java

public List<PontoProfessores> pesquisaPontoEmail() {
    setSessao(HibernateUtil.getSessionFactory().openSession());
    setTransacao(getSessao().beginTransaction());
    List<PontoProfessores> ponto = null;

    ponto = (List<PontoProfessores>) getSessao().createCriteria(PontoProfessores.class)
            .add(Restrictions.or(Restrictions.isNull("horaEntrada"), Restrictions.isNull("horaSaida")))
            .add(Restrictions.or(Restrictions.eq("email", false), Restrictions.isNull("email")))
            .add(Restrictions.lt("data", new Date())).list();

    getSessao().close();/*from ww w .j  a  v a2s  .  c om*/
    return ponto;
}

From source file:ca.myewb.controllers.common.Member.java

License:Open Source License

private void searchMode(Context ctx) throws Exception, RedirectionException {
    MemberSearchForm searchForm = null;//from   w w w .  j  av a2 s  .c  o  m
    List result = null;

    if (currentUser.isAdmin()) {
        result = hibernateSession.createQuery("FROM GroupChapterModel where visible=true").list();
    }

    // run search, store results in temp list
    if (requestParams.get("Advanced") != null) {
        searchForm = new MemberSearchForm(getInterpageVar("membersearchtarget") + "/search", requestParams,
                true, result);
        ctx.put("advanced", new Boolean(true));
    } else {
        searchForm = new MemberSearchForm(getInterpageVar("membersearchtarget") + "/search", requestParams,
                false, result);
    }

    Message m = searchForm.validate();

    if (m != null) // validation failed, redirect to self, next time we'll be entering the next block
    {
        // Display error and prompt user to fix
        throw getValidationException(searchForm, m, (String) getInterpageVar("membersearchtarget"));
    }

    //form validation succeeded!
    String first = searchForm.getParameter("Firstname");
    String last = searchForm.getParameter("Lastname");
    String email = searchForm.getParameter("Email");
    String city = searchForm.getParameter("City", false);
    String province = searchForm.getParameter("Province", false);
    String lang = searchForm.getParameter("Language", false);
    String gender = searchForm.getParameter("Gender", false);
    String birth = searchForm.getParameter("Birth", false);
    String student = searchForm.getParameter("Student", false);
    String username = searchForm.getParameter("Username", false);

    Criteria crit = hibernateSession.createCriteria(UserModel.class);

    if ((username != null) && !username.equals("")) {
        crit.add(Restrictions.like("username", "%" + username.trim() + "%"));
    }

    if ((first != null) && !first.equals("")) {
        crit.add(Restrictions.like("firstname", "%" + first.trim() + "%"));
    }

    if ((last != null) && !last.equals("")) {
        crit.add(Restrictions.like("lastname", "%" + last.trim() + "%"));
    }

    if ((email != null) && !email.equals("")) {
        List ids = HibernateUtil.currentSession()
                .createSQLQuery("SELECT userid FROM useremails e WHERE e.email LIKE '%" + email.trim() + "%'")
                .list();
        if (!ids.isEmpty()) {
            crit.add(Restrictions.in("id", ids));
        } else {
            crit.add(Restrictions.eq("email", "###invalidemail###")); //so that no results are given
        }
    }

    if ((city != null) && !city.equals("")) {
        crit.add(Restrictions.like("address", "%\n%" + city.trim() + "%\n%"));
    }

    if ((province != null) && !province.equals("")) {
        crit.add(Restrictions.like("address", "%\n%" + province.trim() + "%\n%"));
    }

    if ((lang != null) && !lang.equals("")) {
        crit.add(Restrictions.eq("language", lang.trim()));
    }

    if ((gender != null) && !gender.equals("")) {
        crit.add(Restrictions.eq("gender", gender.trim()));
    }

    if ((birth != null) && !birth.equals("")) {
        crit.add(Restrictions.eq("birth", new Integer(birth)));
    }

    if ((student != null) && !student.equals("")) {
        crit.add(Restrictions.eq("student", new Boolean(student)));
    }

    // Get "my" own lead groups, since I can only
    // see people in groups I lead
    crit.createAlias("roles", "r");
    crit.add(Restrictions.isNull("r.end"));

    if (!currentUser.isAdmin()) {
        crit.add(Restrictions.in("r.group", currentUser.getGroups('l')));
    } else {
        GroupChapterModel chapter = null;

        if (searchForm.getParameter("Chapter", false) != null) {
            if (!searchForm.getParameter("Chapter", false).equals("")) {
                chapter = (GroupChapterModel) hibernateSession.get(GroupChapterModel.class,
                        new Integer(searchForm.getParameter("Chapter", false)));
            }
        }

        if (chapter != null) {
            crit.add(Restrictions.eq("r.group", chapter));
            crit.add(Restrictions.eq("r.level", new Character('m')));
        }

        //don't filter out deleted users!
    }

    crit.add(Restrictions.ne("id", new Integer(1)));

    crit.addOrder(Order.asc("lastname"));
    crit.addOrder(Order.asc("firstname"));
    crit.setProjection(Projections.groupProperty("id"));
    crit.setMaxResults(101);

    List uniqueResultsList = crit.list();
    Vector<UserModel> uniqueResults = new Vector<UserModel>();

    if (uniqueResultsList.size() < 101) {
        Iterator iter = uniqueResultsList.iterator();

        while (iter.hasNext()) {
            Integer i = (Integer) iter.next();

            // This try/catch block is a workaround to the deleted-admin-causes-cgilib-blowup bug
            try {
                uniqueResults.add((UserModel) hibernateSession.get(UserModel.class, i));
            } catch (Exception e) {
                log.warn("Unable to add user to usersearch: id " + i.toString());
            }
        }
    } else {
        ctx.put("tooMany", "yes");
    }

    setInterpageVar("membersearchtempresults", uniqueResultsList);
    ctx.put("tempresults", uniqueResults); //NOT the ids, but the users
    ctx.put("searchmode", "yes");
    if (searchForm == null) {
        log.info("search form was null!");
        throw new RedirectionException(getInterpageVar("membersearchtarget") + "/new");
    }

    ctx.put("form", searchForm);
    ctx.put("target", getInterpageVar("membersearchtarget"));
}

From source file:ca.myewb.controllers.common.PostList.java

License:Open Source License

private void addBooleanFilters(boolean onlyNew, boolean findReplies, boolean onlyFlagged, boolean onlyFeatured,
        boolean findEmails, boolean sortByLastReply, Criteria criteria) {

    if (!findReplies) {
        criteria.add(Restrictions.isNull("parent"));
    }/*from   w ww  .j  a v  a  2  s . co m*/

    if (!findEmails) {
        criteria.add(Restrictions.eq("emailed", false));
    }

    if (sortByLastReply) {
        criteria.addOrder(Order.desc("lastReply"));
    } else if (onlyNew) {
        SimpleExpression mainDate = Restrictions.gt("date", currentUser.getLastLogin());
        criteria.add(mainDate);
        criteria.addOrder(Order.asc("date"));
    } else {
        criteria.addOrder(Order.desc("date"));
    }

    if (onlyFlagged) {
        Set<PostModel> flaggedPosts2 = currentUser.getFlaggedPosts();
        if (flaggedPosts2.isEmpty()) {
            criteria.add(Restrictions.eq("id", 0));
        } else {
            Vector<Integer> flaggedIDs = new Vector<Integer>();
            for (PostModel p : flaggedPosts2) {
                flaggedIDs.add(p.getId());
            }

            Criterion flaggedSelf = Restrictions.in("id", flaggedIDs);
            Criterion flaggedParent = Restrictions.in("parent", flaggedPosts2);
            criteria.add(Restrictions.or(flaggedSelf, flaggedParent));
        }
    }

    if (onlyFeatured) {
        criteria.add(Restrictions.eq("featured", true));
    }

}

From source file:ca.myewb.controllers.common.PostList.java

License:Open Source License

private Criteria getListPostsCriteria(GroupLogic theGroup) {
    Criteria criteria = hibernateSession.createCriteria(PostModel.class);

    criteria.add(Restrictions.eq("group", theGroup)); // just posts in this
    // group please
    criteria.add(Restrictions.isNull("parent")); // no replies
    criteria.addOrder(Order.desc("date"));
    return criteria;
}

From source file:ca.myewb.controllers.mailing.AvailableLists.java

License:Open Source License

public void handle(Context ctx) throws Exception {
    List<GroupModel> currentLists = currentUser.getGroups();
    GroupChapterModel chapter = currentUser.getChapter();
    Criteria crit = null;/*from  ww  w  .  j  a v a 2s  .c  o  m*/
    Hashtable<String, List<GroupModel>> hash = new Hashtable<String, List<GroupModel>>();
    List<String> names = new Vector<String>();

    //chapter lists
    crit = hibernateSession.createCriteria(GroupChapterModel.class);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    crit.add(Restrictions.eq("visible", new Boolean(true)));
    crit.addOrder(Order.asc("name"));

    List<GroupModel> chapterLists = (new SafeHibList<GroupModel>(crit)).list();
    chapterLists.removeAll(currentLists);

    //general public lists
    crit = hibernateSession.createCriteria(GroupModel.class);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    crit.add(Restrictions.eq("admin", new Boolean(false)));
    crit.add(Restrictions.eq("visible", new Boolean(true)));

    crit.add(Restrictions.isNull("parent"));
    crit.add(Restrictions.eq("public", new Boolean(true)));

    List<GroupModel> generalPublicLists = (new SafeHibList<GroupModel>(crit)).list();
    generalPublicLists.removeAll(currentLists);
    generalPublicLists.removeAll(chapterLists);

    log.debug("Populating available lists:");

    if (currentUser.getUsername().equals("guest")) {
        generalPublicLists.add(0, Helpers.getGroup("Org"));
        log.debug("Global list, for the guest");
    }

    if (!generalPublicLists.isEmpty()) {
        hash.put("General Public Lists", generalPublicLists);
        names.add("General Public Lists");
        log.debug("General public lists");
    }

    if (currentUser.isMember("Exec")) {
        // admin level lists
        List<GroupModel> adminLists = Helpers.getNationalRepLists(true, true);
        adminLists.add(0, Helpers.getGroup("ProChaptersExec"));
        adminLists.add(0, Helpers.getGroup("UniChaptersExec"));
        adminLists.add(0, Helpers.getGroup("Exec"));

        adminLists.removeAll(currentLists);

        if (!adminLists.isEmpty()) {
            hash.put("Exec and Natl Rep Lists", adminLists);
            names.add("Exec and Natl Rep Lists");
        }
    }

    if (currentUser.isAdmin()) {

        {
            //general private lists
            crit = hibernateSession.createCriteria(GroupModel.class);
            crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
            crit.add(Restrictions.eq("admin", new Boolean(false)));
            crit.add(Restrictions.eq("visible", new Boolean(true)));

            crit.add(Restrictions.isNull("parent"));
            crit.add(Restrictions.eq("public", new Boolean(false)));

            List<GroupModel> generalPrivateLists = (new SafeHibList<GroupModel>(crit)).list();
            generalPrivateLists.removeAll(currentLists);

            if (!generalPrivateLists.isEmpty()) {
                hash.put("General Private Lists", generalPrivateLists);
                names.add("General Private Lists");
                log.debug("General private lists");
            } else {
                log.debug("General private lists was empty");
            }
        }

        {
            //all chapter public lists
            crit = hibernateSession.createCriteria(GroupModel.class);
            crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
            crit.add(Restrictions.eq("admin", new Boolean(false)));
            crit.add(Restrictions.eq("visible", new Boolean(true)));

            crit.add(Restrictions.isNotNull("parent"));
            crit.add(Restrictions.eq("public", new Boolean(true)));
            crit.addOrder(Order.asc("parent"));

            List<GroupModel> chapterPublicLists = (new SafeHibList<GroupModel>(crit)).list();
            chapterPublicLists.removeAll(currentLists);

            if (!chapterPublicLists.isEmpty()) {
                hash.put("Chapter Public Lists (any chapter)", chapterPublicLists);
                names.add("Chapter Public Lists (any chapter)");
                log.debug("Chapter public lists for admin");
            } else {
                log.debug("Chapter public lists for admin; empty");
            }
        }

        {
            //all chapter private lists
            crit = hibernateSession.createCriteria(GroupModel.class);
            crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
            crit.add(Restrictions.eq("admin", new Boolean(false)));
            crit.add(Restrictions.eq("visible", new Boolean(true)));

            crit.add(Restrictions.isNotNull("parent"));
            crit.add(Restrictions.eq("public", new Boolean(false)));
            crit.addOrder(Order.asc("parent"));

            List<GroupModel> chapterPrivateLists = (new SafeHibList<GroupModel>(crit)).list();
            chapterPrivateLists.removeAll(currentLists);

            if (!chapterPrivateLists.isEmpty()) {
                hash.put("Chapter Private Lists (any chapter)", chapterPrivateLists);
                names.add("Chapter Private Lists (any chapter)");
                log.debug("Chapter private lists, admin");
            } else {
                log.debug("Chapter private lists, admin, empty");
            }
        }
    } else {
        if (chapter != null) {
            //chapter public lists
            crit = hibernateSession.createCriteria(GroupModel.class);
            crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
            crit.add(Restrictions.eq("admin", new Boolean(false)));
            crit.add(Restrictions.eq("visible", new Boolean(true)));

            crit.add(Restrictions.eq("parent", chapter));
            crit.add(Restrictions.eq("public", new Boolean(true)));

            List<GroupModel> chapterPublicLists = (new SafeHibList<GroupModel>(crit)).list();
            chapterPublicLists.removeAll(currentLists);

            if (!chapterPublicLists.isEmpty()) {
                hash.put("Chapter Public Lists", chapterPublicLists);
                names.add("Chapter Public Lists");
                log.debug("Chapter public lists");
            } else {
                log.debug("Chapter public lists was empty");
            }

            if (currentUser.isLeader(chapter, false)) {
                //own chapter's private lists
                crit = hibernateSession.createCriteria(GroupModel.class);
                crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
                crit.add(Restrictions.eq("admin", new Boolean(false)));
                crit.add(Restrictions.eq("visible", new Boolean(true)));

                crit.add(Restrictions.eq("parent", chapter));
                crit.add(Restrictions.eq("public", new Boolean(false)));

                List<GroupModel> chapterPrivateLists = (new SafeHibList<GroupModel>(crit)).list();
                chapterPrivateLists.removeAll(currentLists);

                if (!chapterPrivateLists.isEmpty()) {
                    hash.put("Chapter Private Lists", chapterPrivateLists);
                    names.add("Chapter Private Lists");
                    log.debug("Chapter private lists");
                } else {
                    log.debug("Chapter private lists was empty");
                }
            }
        }
    }

    if (!chapterLists.isEmpty()) {
        hash.put("Chapter Lists", chapterLists);
        names.add("Chapter Lists");
        log.debug("Chapter lists");
    }

    // Stick it all in the context
    ctx.put("names", names);
    ctx.put("names2", names);
    ctx.put("hash", hash);
}