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:ca.myewb.controllers.mailing.ListMember.java

License:Open Source License

private List<GroupModel> getControllableGroups() {
    List<GroupModel> lists;

    if (currentUser.isAdmin()) {
        lists = (new SafeHibList<GroupModel>(hibernateSession
                .createQuery("SELECT g FROM GroupModel g where g.visible=true and g.admin=false"))).list();
    } else {//from  w ww . j  a  v  a  2s .  c  om
        Criteria crit = hibernateSession.createCriteria(GroupModel.class);

        crit.createAlias("roles", "r");
        crit.add(Restrictions.eq("r.user", currentUser));
        crit.add(Restrictions.isNull("r.end"));
        crit.add(Restrictions.eq("r.level", new Character('l')));
        crit.add(Restrictions.eq("visible", new Boolean(true)));
        crit.add(Restrictions.eq("admin", new Boolean(false)));

        crit.setProjection(Projections.groupProperty("id"));
        lists = (new SafeHibList<GroupModel>(crit)).list();

        Iterator it = lists.iterator();
        List<GroupModel> lists2 = new ArrayList<GroupModel>();

        while (it.hasNext()) {
            lists2.add((GroupModel) hibernateSession.get(GroupModel.class, (Integer) it.next()));
        }

        lists = lists2;
        lists.addAll(currentUser.getChapter().getVisibleChildren());
    }

    return lists;
}

From source file:ca.myewb.logic.PlacementLogic.java

License:Open Source License

public static List<PlacementModel> getUnassignedPlacements() {
    Criteria crit = HibernateUtil.currentSession().createCriteria(PlacementModel.class);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    crit.add(Restrictions.eq("active", new Boolean(false)));
    crit.add(Restrictions.eq("deleted", new Boolean(false)));
    crit.add(Restrictions.isNull("ov"));
    crit.addOrder(Order.asc("name"));
    return (new SafeHibList<PlacementModel>(crit)).list();
}

From source file:ca.myewb.logic.PlacementLogic.java

License:Open Source License

public static Object getDeletedPlacements() {
    Criteria crit = HibernateUtil.currentSession().createCriteria(PlacementModel.class);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    crit.add(Restrictions.eq("active", new Boolean(false)));
    crit.add(Restrictions.eq("deleted", new Boolean(true)));
    crit.add(Restrictions.isNull("ov"));
    crit.addOrder(Order.asc("name"));
    return (new SafeHibList<PlacementModel>(crit)).list();
}

From source file:ca.myewb.logic.UserLogic.java

License:Open Source License

public Date getAccountCreationDate() {
    Criteria criteria = session.createCriteria(RoleModel.class);
    criteria.add(Restrictions.eq("user", this));
    criteria.add(Restrictions.eq("group", Helpers.getGroup("Org")));
    criteria.add(Restrictions.isNull("end"));
    Iterator it = criteria.list().iterator();

    if (it.hasNext()) {
        return ((RoleModel) it.next()).getStart();
    } else {/*from  www .j ava 2  s.  com*/
        return null;
    }
}

From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java

License:Open Source License

@Override
public List<Category> getCategories(Category parent, Boolean includeUnclassified) throws PigeException {

    logger.debug("Rcupration des catgories...");

    Transaction tx = null;/*  w  w  w . j  a v a 2 s.  c o m*/
    List<Category> categories = null;
    Session session = null;

    try {
        session = PigeHibernateUtil.openSession();
        tx = session.beginTransaction();

        Criteria criteria = session.createCriteria(Category.class);
        if (parent != null) {
            logger.debug("category != null: " + parent.getName());
            criteria.add(Restrictions.eq(Category.PARENT_REF, parent));
        } else {
            criteria.add(Restrictions.isNull(Category.PARENT_REF));
        }
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        categories = (List) criteria.addOrder(Order.asc(Category.NAME_REF)).list();

        if (categories != null) {
            for (Category c : categories) {
                Criteria itemCrit = session.createCriteria(Item.class);
                itemCrit.createCriteria(Item.CATEGORIES_REF)
                        .add(Restrictions.like(Category.PATH_REF, c.getPath(), MatchMode.START));
                itemCrit.setProjection(Projections.distinct(Projections.rowCount()));
                c.setItemCount((Integer) itemCrit.uniqueResult());
            }
        }

        //  la racine seulement.
        if (includeUnclassified && parent == null) {
            Category unclassified = new Category();
            unclassified.setId(Category.UNCLASSIFIED_CATEGORY_ID);
            Criteria itemCrit = session.createCriteria(Item.class);
            itemCrit.add(Restrictions.sizeEq(Item.CATEGORIES_REF, 0));
            itemCrit.setProjection(Projections.distinct(Projections.rowCount()));
            unclassified.setItemCount((Integer) itemCrit.uniqueResult());
            categories.add(unclassified);
        }

        tx.commit();
        logger.debug("Rcupration russie!");
    } catch (Exception hex) {
        logger.error(hex);
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }

    return categories;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.SampleDAO.java

License:Apache License

private void addSampleCodeCriterion(Criteria criteria, String sampleCode) {
    String[] sampleCodeTokens = sampleCode.split(SampleIdentifier.CONTAINED_SAMPLE_CODE_SEPARARTOR_STRING);
    if (sampleCodeTokens.length > 1) {
        final String containerCode = sampleCodeTokens[0];
        final String code = sampleCodeTokens[1];
        criteria.add(Restrictions.eq("code", CodeConverter.tryToDatabase(code)));
        criteria.createAlias("container", "c");
        criteria.add(Restrictions.eq("c.code", CodeConverter.tryToDatabase(containerCode)));
    } else {/*  w  ww  .  j a v a2 s.  c o  m*/
        criteria.add(Restrictions.eq("code", CodeConverter.tryToDatabase(sampleCode)));
        criteria.add(Restrictions.isNull("container"));
    }

}

From source file:chiron.maxscore.service.impl.MenuServiceImpl.java

@Override
public Menu getRoot() {
    DetachedCriteria criteria = DetachedCriteria.forClass(Menu.class);

    criteria.add(Restrictions.isNull("menuParent"));
    List<Menu> list = menuDAO.search(0, 1, criteria);
    return list.size() > 0 ? list.get(0) : null;
}

From source file:chiron.maxscore.service.impl.OptionServiceImpl.java

@Override
public List<Option> getRootOptionsByCidAndVer(int cid, int ver) {
    DetachedCriteria criteria = DetachedCriteria.forClass(OptionMapping.class);

    criteria.createAlias("course", "c");
    criteria.createAlias("option", "o");
    criteria.createAlias("parentOption", "p");

    criteria.add(Restrictions.isNull("p"));
    criteria.add(Restrictions.eq("c.id", cid));
    criteria.add(Restrictions.eq("optionVer", ver));

    //        criteria.setProjection(Projections.groupProperty("o.optionGroupId"));
    //        criteria.setProjection(Projections.max("optionVer"));
    List<OptionMapping> oms = optionMappingDAO.search(0, Integer.MAX_VALUE, criteria);
    List<Option> options = new ArrayList<>();
    for (OptionMapping om : oms) {
        options.add(om.getOption());/*  ww w  . j av a2 s.  com*/
    }
    return options;
}

From source file:cloudoutput.dao.ReportDataDAO.java

License:Open Source License

/** 
 * Gets a report of overall resources usage of a given datacenter.
 *
 * @param   type            the type of the used resource.
 * @param   datacenterName  the name of the datacenter.
 * @return                  a map with values of time as keys and values of
 *                          used resources as values.
 * @see                     ReportData/*from w  w  w.j  a va2 s  .com*/
 * @since                   1.0
 */
public TreeMap<Double, Double> getDatacenterOverallData(String type, String datacenterName) {
    List<ReportData> dataList = null;
    Session session = HibernateUtil.getSession();
    try {
        dataList = (List<ReportData>) session.createCriteria(ReportData.class)
                .add(Restrictions.conjunction().add(Restrictions.eq("type", type))
                        .add(Restrictions.eq("datacenterName", datacenterName))
                        .add(Restrictions.isNull("hostId")))
                .list();
    } catch (HibernateException ex) {
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }

    TreeMap<Double, Double> overallUsedResources = new TreeMap<Double, Double>();
    if (dataList == null)
        return overallUsedResources;
    for (ReportData rd : dataList) {
        if (type.equals("BANDWIDTH")) {
            //If bandwidth, convert from kbps to Mbps
            overallUsedResources.put(rd.getTime() / 60, rd.getAmount() / 1000);
        } else {
            overallUsedResources.put(rd.getTime() / 60, rd.getAmount());
        }
    }

    return overallUsedResources;
}

From source file:cloudoutput.dao.ReportDataDAO.java

License:Open Source License

/**
 * Gets a report of overall resources usage of a given customer.
 *
 * @param type          the type of the used resource.
 * @param customerName  the name of the customer.
 * @return              a map with values of time as keys and values of
 *                      used resources as values.
 * @see                 ReportData//from w  w w .  j  a v  a2s .  co m
 * @since               1.0
 */
public TreeMap<Double, Double> getCustomerOverallData(String type, String customerName) {
    List<ReportData> dataList = null;
    Session session = HibernateUtil.getSession();
    try {
        dataList = (List<ReportData>) session.createCriteria(ReportData.class)
                .add(Restrictions.conjunction().add(Restrictions.eq("type", type))
                        .add(Restrictions.eq("customerName", customerName)).add(Restrictions.isNull("vmId")))
                .list();
    } catch (HibernateException ex) {
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }

    TreeMap<Double, Double> overallUsedResources = new TreeMap<Double, Double>();
    if (dataList == null)
        return overallUsedResources;
    for (ReportData rd : dataList) {
        if (type.equals("BANDWIDTH")) {
            //If bandwidth, convert from kbps to Mbps
            overallUsedResources.put(rd.getTime() / 60, rd.getAmount() / 1000);
        } else {
            overallUsedResources.put(rd.getTime() / 60, rd.getAmount());
        }
    }

    return overallUsedResources;
}