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:com.qcadoo.model.api.search.SearchRestrictions.java

License:Open Source License

/**
 * Creates criterion which checks if field is null.
 * //w ww  . j a va  2  s  . co m
 * @param field
 *            field
 * @return criterion
 */
public static SearchCriterion isNull(final String field) {
    return new SearchCriterionImpl(Restrictions.isNull(field));
}

From source file:com.qcadoo.model.internal.PriorityServiceImpl.java

License:Open Source License

private void setPriorityIfNotPresent(final InternalDataDefinition dataDefinition,
        final FieldDefinition fieldDefinition, final Object databaseEntity, int currentPriority) {
    Criteria criteria = getCriteria(dataDefinition, fieldDefinition, databaseEntity)
            .add(Restrictions.isNull(fieldDefinition.getName()))
            .add(Restrictions.not(Restrictions.idEq(entityService.getId(databaseEntity))));

    List<Object> entitiesToDecrement = criteria.list();

    int index = currentPriority + 1;
    for (Object entity : entitiesToDecrement) {
        Integer priorityInteger = (Integer) entityService.getField(entity, fieldDefinition);
        int priority = priorityInteger != null ? priorityInteger.intValue() : index;

        entityService.setField(entity, fieldDefinition, priority);
        hibernateService.getCurrentSession().update(entity);
        index++;/*from  www  .j av a 2 s  .  c o  m*/
    }
}

From source file:com.redhat.rhn.domain.channel.ChannelFamilyFactory.java

License:Open Source License

/**
 * Lookup a ChannelFamily by its label//from  w  ww  .  j a v  a2s.c  o  m
 * @param label the label to search for
 * @param org the Org the Family belongs to, use null if looking for
 *        official RedHat ChannelFamilies
 * @return the ChannelFamily found
 */
public static ChannelFamily lookupByLabel(String label, Org org) {
    Session session = getSession();
    Criteria c = session.createCriteria(ChannelFamily.class);
    c.add(Restrictions.eq("label", label));
    c.add(Restrictions.or(Restrictions.eq("org", org), Restrictions.isNull("org")));
    return (ChannelFamily) c.uniqueResult();
}

From source file:com.redhat.rhn.domain.channel.ChannelFamilyFactory.java

License:Open Source License

/**
 * Lookup the List of ChannelFamily objects that are labled starting
 * with the passed in label param/*from  w  ww. j a  v a2  s. c  om*/
 * @param label to query against
 * @param orgIn owning the Channel.  Pass in NULL if you want a NULL org channel
 * @return List of Channel objects
 */
public static List lookupByLabelLike(String label, Org orgIn) {
    Session session = getSession();
    Criteria c = session.createCriteria(ChannelFamily.class);
    c.add(Restrictions.like("label", label + "%"));
    c.add(Restrictions.or(Restrictions.eq("org", orgIn), Restrictions.isNull("org")));
    return c.list();
}

From source file:com.reignite.parser.QueryParser.java

License:Open Source License

private Criterion processField(JSONObject where) throws ParserException {
    String field = JSONObject.getNames(where)[0];
    JSONObject exp;//from   w w  w .j a  va2s.com
    try {
        exp = where.getJSONObject(field);
    } catch (JSONException e) {
        throw new ParserException("field expressions must be JSON Object: " + field);
    }
    ExpressionType type = ExpressionType.get(JSONObject.getNames(exp)[0]);
    Object value = null;
    // if the field is a join
    if (field.indexOf(".") > -1) {
        String join = field.substring(0, field.indexOf("."));
        query.createJoin(join);
    }
    switch (type) {
    case IN:
    case NOT_IN:
        try {
            value = createArray(exp.getJSONArray(type.getName()));
        } catch (JSONException e) {
            throw new ParserException("in and not in expressions must be arrays: " + exp);
        }
        break;
    default:
        try {
            value = createValue(exp.get(type.getName()));
        } catch (JSONException e) {
            throw new ParserException("expressions must have a value: " + exp);
        }
    }

    switch (type) {
    case GREATER_THAN:
        return Restrictions.gt(field, value);
    case IN:
        return Restrictions.in(field, (Object[]) value);
    case LESS_THAN:
        return Restrictions.lt(field, value);
    case LIKE:
        MatchMode match = MatchMode.EXACT;
        String toMatch = value.toString();
        if (value.toString().startsWith("%")) {
            match = MatchMode.END;
            toMatch = toMatch.substring(1);
        }
        if (value.toString().endsWith("%")) {
            toMatch = toMatch.substring(0, toMatch.length() - 1);
            if (match == MatchMode.END) {
                match = MatchMode.ANYWHERE;
            } else {
                match = MatchMode.START;
            }
        }
        return Restrictions.ilike(field, toMatch, match);
    case NOT_EQUAL:
        if (value == null) {
            return Restrictions.isNotNull(field);
        }
        return Restrictions.ne(field, value);
    case NOT_IN:
        return Restrictions.not(Restrictions.in(field, (Object[]) value));
    case EQUAL:
    default:
        if (value == null) {
            return Restrictions.isNull(field);
        }
        return Restrictions.eq(field, value);
    }

}

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

License:Open Source License

public List<Crawling> getIncompleted(final SharedSessionContract ssc) {
    // Query: Crawling
    final EntityWithIdQuery<Crawling> crawlingQuery = new EntityWithIdQuery<>(Crawling.class);
    crawlingQuery.addRestriction(Restrictions.isNull("completed"));
    crawlingQuery.addOrder(Order.asc("started"));

    // Done//from   w w  w.  j  a  v  a  2s.  c o  m
    final List<Crawling> crawlings = crawlingQuery.listObjects(ssc);
    return crawlings;
}

From source file:com.rta.vsd.data.service.impl.InspectionDataServiceImpl.java

/**
 * /* w  w w . ja v a 2 s. c om*/
 * Gets those inspections which occurred between the given dates that did not lead to a violation
 * 
 * @author Eldon Barrows
 * @param dsContext
 * @param retrieveArabicData
 * @param plateDetails
 * @param startDate
 * @param endDate
 * @return List<VsdInspection>
 * @throws VSDDataAccessException
 */
public List<VsdInspection> getInspectionsWithNoViolationsByVehiclePlateAndReportedDate(
        DataServiceContext dsContext, boolean retrieveArabicData, VehiclePlate plateDetails, Date startDate,
        Date endDate) throws VSDDataAccessException {
    logger.info("getInspectionsWithNoViolationsByVehiclePlateAndReportedDate -- START");
    List<VsdInspection> inspections = null;
    try {

        Session session = (Session) dsContext.getInternalContext();
        inspections = session.createCriteria(VsdInspection.class, "i")
                .add(Restrictions.eq("i.isDeleted", IDataService.BOOL_FALSE))
                .add(Restrictions.between("i.inspectionTimestamp", startDate, endDate))
                .add(Restrictions.isNull("i.vsdViolation"))
                .createCriteria("i.vsdVehicleInfo", "vi", Criteria.LEFT_JOIN,
                        Restrictions.eq("vi.isDeleted", IDataService.BOOL_FALSE))
                .add(Restrictions.eq("vi.vehiclePlateCategory", plateDetails.getPlateCategory()).ignoreCase())
                .add(Restrictions.eq("vi.vehiclePlateCode", plateDetails.getPlateCode()).ignoreCase())
                .add(Restrictions.eq("vi.vehiclePlateSource", plateDetails.getPlateSource()).ignoreCase())
                .add(Restrictions.eq("vi.vehiclePlateNumber", plateDetails.getPlateNumber()).ignoreCase())
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
        logger.info("getInspectionsWithNoViolationsByVehiclePlateAndReportedDate -- END");
        return inspections;
    } catch (Exception ex) {
        logger.error("An error occured in getInspectionsWithNoViolationsByVehiclePlateAndReportedDate()");
        throw new VSDDataAccessException(ex.getMessage(), ex);
    }
}

From source file:com.sam.moca.job.dao.hibernate.JobDefinitionHibernateDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from w  w  w  .ja va  2 s  . c  o  m*/
public List<JobDefinition> readForAllNoRoleAndRoles(RoleDefinition... roles) {
    Criteria criteria = HibernateTools.getSession().createCriteria(JobDefinition.class);

    Criterion criterion = null;
    Criterion firstCrit = Restrictions.sqlRestriction("{alias}.role_id = '*'");
    Criterion secondCrit = Restrictions.isNull("role");

    if (roles.length > 0) {

        criterion = Restrictions.or(firstCrit, secondCrit, Restrictions.in("role", roles));
    } else {
        criterion = Restrictions.or(firstCrit, secondCrit);
    }

    criteria.add(criterion);
    return (List<JobDefinition>) criteria.list();
}

From source file:com.sapienter.jbilling.server.payment.blacklist.db.BlacklistDAS.java

License:Open Source License

/**
 * Considers comparing nulls as equal. Useful for some filters,
 * such as address, where not all fields may have a value.
 *//*from   ww w  . jav a  2  s.  c  om*/
private Criterion equals(String propertyName, Object value) {
    if (value != null) {
        return Restrictions.eq(propertyName, value);
    }
    return Restrictions.isNull(propertyName);
}

From source file:com.sccl.attech.common.service.BaseService.java

License:Open Source License

/**
 * ?//from  w w w. j  av a 2s . c o m
 * @param user ?UserUtils.getUser()??
 * @param officeAlias ??dc.createAlias("office", "office");
 * @param userAlias ???
 * @return ?
 */
protected static Junction dataScopeFilter(User user, String officeAlias, String userAlias) {

    // ????
    List<String> dataScope = Lists.newArrayList();
    Junction junction = Restrictions.disjunction();

    // ???
    if (!user.isAdmin()) {
        for (Role r : user.getRoleList()) {
            if (!dataScope.contains(r.getDataScope()) && StringUtils.isNotBlank(officeAlias)) {
                boolean isDataScopeAll = false;
                if (Role.DATA_SCOPE_ALL.equals(r.getDataScope())) {
                    isDataScopeAll = true;
                } else if (Role.DATA_SCOPE_COMPANY_AND_CHILD.equals(r.getDataScope())) {
                    junction.add(Restrictions.eq("company.id", user.getCompany().getId()));
                    //junction.add(Restrictions.like(officeAlias+".parentIds", "%"+user.getCompany().getParentIds()+","+user.getCompany().getId()+"%"));
                }
                //               else if (Role.DATA_SCOPE_COMPANY.equals(r.getDataScope())){
                //                  junction.add(Restrictions.eq(officeAlias+".id", user.getCompany().getId()));
                //                  junction.add(Restrictions.and(Restrictions.eq(officeAlias+".id", user.getCompany().getId()),
                //                        Restrictions.eq(officeAlias+".type", "2"))); // ?
                //               }
                else if (Role.DATA_SCOPE_OFFICE_AND_CHILD.equals(r.getDataScope())) {
                    junction.add(Restrictions.eq(officeAlias + ".id", user.getOffice().getId()));
                    junction.add(Restrictions.like(officeAlias + ".parentIds",
                            "%" + user.getOffice().getParentIds() + "," + user.getOffice().getId() + "%"));
                } else if (Role.DATA_SCOPE_OFFICE.equals(r.getDataScope())) {
                    junction.add(Restrictions.eq(officeAlias + ".id", user.getOffice().getId()));
                } else if (Role.DATA_SCOPE_CUSTOM.equals(r.getDataScope())) {
                    junction.add(Restrictions.in(officeAlias + ".id", r.getOfficeIdList()));
                }
                //else if (Role.DATA_SCOPE_SELF.equals(r.getDataScope())){
                if (!isDataScopeAll) {
                    if (StringUtils.isNotBlank(userAlias)) {
                        junction.add(Restrictions.eq(userAlias + ".id", user.getId()));
                    } else {
                        junction.add(Restrictions.isNull(officeAlias + ".id"));
                    }
                } else {
                    // ?????
                    junction = Restrictions.disjunction();
                    break;
                }

                dataScope.add(r.getDataScope());
            }
        }
    }

    return junction;
}