Example usage for org.hibernate.criterion Restrictions eqOrIsNull

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

Introduction

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

Prototype

public static Criterion eqOrIsNull(String propertyName, Object value) 

Source Link

Document

Apply an "equal" constraint to the named property.

Usage

From source file:br.com.muranodesign.dao.impl.RoteiroDAOImpl.java

License:Creative Commons License

@Override
@SuppressWarnings("unchecked")
public List<Roteiro> listarAnoEstudoLazy(int anoEstudo) {
    Criteria criteria = getSession().createCriteria(Roteiro.class);
    ProjectionList projList = Projections.projectionList();

    criteria.createAlias("anoEstudo", "anoEstudo");
    criteria.add(Restrictions.eq("anoEstudo.idanoEstudo", anoEstudo));
    criteria.add(Restrictions.eqOrIsNull("ativo", 1));
    projList.add(Projections.property("idroteiro"), "idroteiro");
    projList.add(Projections.property("nome"), "nome");
    criteria.setProjection(projList).setCacheable(true);
    criteria.setResultTransformer(Transformers.aliasToBean(Roteiro.class));
    List<Roteiro> result = criteria.list();

    return result;

}

From source file:com.romeikat.datamessie.core.base.dao.impl.CrawlingDao.java

License:Open Source License

public List<CrawlingDto> getAsDtos(final SharedSessionContract ssc, final Long projectId) {
    // Query: Crawling
    final EntityWithIdQuery<Crawling> crawlingQuery = new EntityWithIdQuery<>(Crawling.class);
    crawlingQuery.addRestriction(Restrictions.eqOrIsNull("projectId", projectId));
    crawlingQuery.addOrder(Order.desc("started"));
    crawlingQuery.setResultTransformer(new AliasToBeanResultTransformer(CrawlingDto.class));

    // Done//from  ww w. j a  v a  2 s .com
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("id"), "id");
    projectionList.add(Projections.property("started"), "started");
    projectionList.add(Projections.property("completed"), "completed");
    @SuppressWarnings("unchecked")
    final List<CrawlingDto> dtos = (List<CrawlingDto>) crawlingQuery.listForProjection(ssc, projectionList);

    // Set duration
    setDurationForDtos(dtos);

    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.CrawlingDao.java

License:Open Source License

public List<CrawlingOverviewDto> getAsOverviewDtos(final SharedSessionContract ssc, final Long projectId,
        final Long first, final Long count) {
    // Query: Crawling
    final EntityWithIdQuery<Crawling> crawlingQuery = new EntityWithIdQuery<>(Crawling.class);
    crawlingQuery.addRestriction(Restrictions.eqOrIsNull("projectId", projectId));
    crawlingQuery.setFirstResult(first == null ? null : first.intValue());
    crawlingQuery.setMaxResults(count == null ? null : count.intValue());
    crawlingQuery.addOrder(Order.desc("started"));
    crawlingQuery.setResultTransformer(new AliasToBeanResultTransformer(CrawlingOverviewDto.class));

    // Done/*from  ww w .  j ava  2s.  com*/
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("id"), "id");
    projectionList.add(Projections.property("started"), "started");
    projectionList.add(Projections.property("completed"), "completed");
    @SuppressWarnings("unchecked")
    final List<CrawlingOverviewDto> dtos = (List<CrawlingOverviewDto>) crawlingQuery.listForProjection(ssc,
            projectionList);

    // Set duration
    setDurationForOverviewDtos(dtos);

    return dtos;
}

From source file:kltn.dao.ATMLocationDAO.java

public List<AtmLocation> findByGeocodingStatus(char status) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    List<AtmLocation> list = null;
    Transaction tx = null;/*from w  w w  . j a  v a2 s. c  o m*/
    try {

        tx = session.beginTransaction();
        Criteria cr = session.createCriteria(AtmLocation.class);
        if (status == '1') {
            cr.add(Restrictions.neOrIsNotNull("latd", ""));
        } else if (status == '0') {
            cr.add(Restrictions.eqOrIsNull("latd", ""));
        }
        cr.addOrder(Order.asc("id"));
        list = cr.list();
        tx.commit();
    } catch (HibernateException he) {
        if (tx != null && tx.isActive()) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return list;
}

From source file:org.balisunrise.daa.hibernate.HCriteria.java

License:Open Source License

private org.hibernate.criterion.Criterion makeCriterion(String propertyName, FilterType type, Object value,
        Object otherValue) {//  w w w.j a va  2s . c o  m

    switch (type) {
    case EQUALS:
        return Restrictions.eq(propertyName, value);
    case EQUALS_OR_NULL:
        return Restrictions.eqOrIsNull(propertyName, value);
    case DIFFERENT:
        return Restrictions.ne(propertyName, value);
    case DIFFERENT_OR_NOT_NULL:
        return Restrictions.neOrIsNotNull(propertyName, value);
    case GREATHER:
        return Restrictions.gt(propertyName, value);
    case GREATHER_EQUALS:
        return Restrictions.ge(propertyName, value);
    case LESS:
        return Restrictions.lt(propertyName, value);
    case LESS_EQUALS:
        return Restrictions.le(propertyName, value);
    case LIKE:
        return Restrictions.like(propertyName, value + "%");
    case ILIKE:
        return Restrictions.ilike(propertyName, "%" + value + "%");
    case BETWEEN:
        return Restrictions.between(propertyName, value, otherValue);
    case IN:
        if (value instanceof Collection)
            return Restrictions.in(propertyName, (Collection) value);
        else if (value instanceof Object[])
            return Restrictions.in(propertyName, (Object[]) value);
        else
            return Restrictions.in(propertyName, new Object[] { value });
    case NULL:
        return Restrictions.isNull(propertyName);
    case NOT_NULL:
        return Restrictions.isNotNull(propertyName);
    default:
        return null;
    }
}

From source file:org.candlepin.model.PoolCurator.java

License:Open Source License

/**
 * Attempts to find pools which are over subscribed after the creation or modification
 * of the given entitlement.//from  w w  w  .  j  a v  a2 s.co m
 *
 * To do this we search for only the pools related to the subscription ID which
 * could have changed, the two cases where this can happen are:
 *
 * 1. Bonus pool (not derived from any entitlement) after a bind. (in cases such as
 * exporting to downstream)
 * 2. A derived pool whose source entitlement just had it's quantity reduced.
 *
 * This has to be done carefully to avoid potential performance problems with
 * virt_bonus on-site subscriptions where one pool is created per physical
 * entitlement.
 *
 * @param subId Subscription ID of the pool.
 * @param ent Entitlement just created or modified.
 * @return Pools with too many entitlements for their new quantity.
 */
@SuppressWarnings("unchecked")
public List<Pool> lookupOversubscribedBySubscriptionId(String subId, Entitlement ent) {
    return currentSession().createCriteria(Pool.class).createAlias("sourceSubscription", "sourceSub")
            .add(Restrictions.eq("sourceSub.subscriptionId", subId)).add(Restrictions.ge("quantity", 0L))
            .add(Restrictions.gtProperty("consumed", "quantity"))
            .add(Restrictions.or(Restrictions.isNull("sourceEntitlement"),
                    Restrictions.eqOrIsNull("sourceEntitlement", ent)))
            .list();
}

From source file:org.dspace.content.dao.impl.MetadataFieldDAOImpl.java

License:BSD License

@Override
public MetadataField find(Context context, int metadataFieldId, MetadataSchema metadataSchema, String element,
        String qualifier) throws SQLException {
    Criteria criteria = createCriteria(context, MetadataField.class);
    criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq("id", metadataFieldId)),
            Restrictions.eq("metadataSchema.id", metadataSchema.getSchemaID()),
            Restrictions.eq("element", element), Restrictions.eqOrIsNull("qualifier", qualifier)));
    criteria.setCacheable(true);/*from   w w  w.j a va  2 s  .  c  o m*/

    return singleResult(criteria);
}

From source file:org.dspace.content.dao.impl.MetadataFieldDAOImpl.java

License:BSD License

@Override
public MetadataField findByElement(Context context, MetadataSchema metadataSchema, String element,
        String qualifier) throws SQLException {
    Criteria criteria = createCriteria(context, MetadataField.class);
    criteria.add(Restrictions.and(Restrictions.eq("metadataSchema.id", metadataSchema.getSchemaID()),
            Restrictions.eq("element", element), Restrictions.eqOrIsNull("qualifier", qualifier)));
    criteria.setCacheable(true);/*from www. j a  va2 s . c o m*/

    return singleResult(criteria);
}

From source file:org.dspace.content.dao.impl.MetadataFieldDAOImpl.java

License:BSD License

@Override
public MetadataField findByElement(Context context, String metadataSchema, String element, String qualifier)
        throws SQLException {
    Criteria criteria = createCriteria(context, MetadataField.class);
    criteria.createAlias("metadataSchema", "s").add(Restrictions.and(Restrictions.eq("s.name", metadataSchema),
            Restrictions.eq("element", element), Restrictions.eqOrIsNull("qualifier", qualifier)));
    criteria.setCacheable(true);//from w  ww .  j  a  va 2 s.  co  m

    return singleResult(criteria);
}

From source file:org.faster.orm.service.hibernate.HibernateDaoSupport.java

License:Open Source License

protected DetachedCriteria buildCriteriaByPropertyValueMap(Map<String, Object> propertyValueMap) {
    DetachedCriteria dc = buildCriteria();
    if (propertyValueMap != null) {
        for (String propertyName : propertyValueMap.keySet()) {
            Object propertyValue = propertyValueMap.get(propertyName);
            dc.add(Restrictions.eqOrIsNull(propertyName, propertyValue));
        }//  w w  w.  j ava  2s.  com
    }
    return dc;
}