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.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java

License:Open Source License

public VolumeManagement getVolumeFromImage(final Integer idImage) {
    Criteria criteria = createCriteria(Restrictions.eq(
            VolumeManagement.VIRTUAL_MACHINE_TEMPLATE_PROPERTY + "." + PersistentEntity.ID_PROPERTY, idImage),
            Restrictions.isNull(RasdManagement.TEMPORAL_PROPERTY));
    Object obj = criteria.uniqueResult();
    return (VolumeManagement) obj;
}

From source file:com.abiquo.server.core.scheduler.FitPolicyRuleDAO.java

License:Open Source License

/**
 * Gets the global {@link FitPolicyRuleHB}.
 * // w w w.j av  a  2s .  c  om
 * @return The global <code>FitPolicyRuleHB</code>.
 */
public FitPolicyRule getGlobalFitPolicy() {
    Criteria criteria = getSession().createCriteria(FitPolicyRule.class);
    Criterion noDatacenter = Restrictions.isNull(FitPolicyRule.DATACENTER_PROPERTY);
    criteria.add(noDatacenter);

    FitPolicyRule result = getSingleResult(criteria);

    return result;
}

From source file:com.abiquo.server.core.scheduler.MachineLoadRuleDAO.java

License:Open Source License

private Criterion nullMachine() {
    return Restrictions.isNull(MachineLoadRule.MACHINE_PROPERTY);
}

From source file:com.abssh.util.GenericDao.java

License:Apache License

/**
 * ??Criterion,./*from   w  w  w .j a v  a  2  s .  c  o  m*/
 */
protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object[] propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName should not be null!");
    Criterion criterion = null;
    try {
        // ?MatchTypecriterion
        if (MatchType.EQ.equals(matchType)) {
            criterion = Restrictions.eq(propertyName, propertyValue[0]);
        } else if (MatchType.LIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.ANYWHERE);
        } else if (MatchType.ELIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.END);
        } else if (MatchType.SLIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.START);
        } else if (MatchType.LE.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue[0]);
        } else if (MatchType.LT.equals(matchType)) {
            criterion = Restrictions.lt(propertyName, propertyValue[0]);
        } else if (MatchType.GE.equals(matchType)) {
            criterion = Restrictions.ge(propertyName, propertyValue[0]);
        } else if (MatchType.GT.equals(matchType)) {
            criterion = Restrictions.gt(propertyName, propertyValue[0]);
        } else if (MatchType.NE.equals(matchType)) {
            criterion = Restrictions.ne(propertyName, propertyValue[0]);
        } else if (MatchType.ISNULL.equals(matchType)) {
            criterion = Restrictions.isNull(propertyName);
        } else if (MatchType.ISNOTNULL.equals(matchType)) {
            criterion = Restrictions.isNotNull(propertyName);
        } else if (MatchType.ISEMPTY.equals(matchType)) {
            criterion = Restrictions.isEmpty(propertyName);
        } else if (MatchType.ISNOTEMPTY.equals(matchType)) {
            criterion = Restrictions.isNotEmpty(propertyName);
        } else if (MatchType.IN.equals(matchType)) {
            criterion = Restrictions.in(propertyName, propertyValue);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
    return criterion;
}

From source file:com.abssh.util.GenericDao.java

License:Apache License

/**
 * ??//from w  ww . j a v a2s  .  co m
 */
private Criterion getCriterion(String propertyName, Object[] propertyValue, MatchType matchType) {
    Criterion criterion = null;
    try {
        // ?MatchTypecriterion
        if (MatchType.EQ.equals(matchType)) {
            criterion = Restrictions.eq(propertyName, propertyValue[0]);
        } else if (MatchType.LIKE.equals(matchType)) {
            criterion = RestrictionsUtils.ilike(propertyName, String.valueOf(propertyValue[0]),
                    MatchMode.ANYWHERE);
        } else if (MatchType.ELIKE.equals(matchType)) {
            criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.END);
        } else if (MatchType.SLIKE.equals(matchType)) {
            criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.START);
        } else if (MatchType.LE.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue[0]);
        } else if (MatchType.LT.equals(matchType)) {
            criterion = Restrictions.lt(propertyName, propertyValue[0]);
        } else if (MatchType.GE.equals(matchType)) {
            criterion = Restrictions.ge(propertyName, propertyValue[0]);
        } else if (MatchType.GT.equals(matchType)) {
            criterion = Restrictions.gt(propertyName, propertyValue[0]);
        } else if (MatchType.NE.equals(matchType)) {
            criterion = Restrictions.ne(propertyName, propertyValue[0]);
        } else if (MatchType.ISNULL.equals(matchType)) {
            criterion = Restrictions.isNull(propertyName);
        } else if (MatchType.ISNOTNULL.equals(matchType)) {
            criterion = Restrictions.isNotNull(propertyName);
        } else if (MatchType.ISEMPTY.equals(matchType)) {
            criterion = Restrictions.isEmpty(propertyName);
        } else if (MatchType.ISNOTEMPTY.equals(matchType)) {
            criterion = Restrictions.isNotEmpty(propertyName);
        } else if (MatchType.IN.equals(matchType)) {
            criterion = Restrictions.in(propertyName, propertyValue);
        } else if (MatchType.LEN.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue[0]);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
    return criterion;
}

From source file:com.algoTrader.CriteriaSearch.java

/**
 * Adds an <code>Restrictions</code> to a <code>Criteria</code>.
 *
 * @param criteria/*from  w  w  w  . j  av a 2  s.c  om*/
 * @param parameterName
 * @param parameterValue
 * @param comparator
 * @param matchMode
 */
private void addExpression(Criteria criteria, String parameterName, Object parameterValue, int comparator,
        MatchMode matchMode) {
    switch (comparator) {
    case SearchParameter.NOT_NULL_COMPARATOR: {
        criteria.add(Restrictions.isNotNull(parameterName));
        break;
    }
    case SearchParameter.NULL_COMPARATOR: {
        criteria.add(Restrictions.isNull(parameterName));
        break;
    }
    case SearchParameter.EMPTY_COMPARATOR: {
        criteria.add(Restrictions.isEmpty(parameterName));
        break;
    }
    case SearchParameter.NOT_EMPTY_COMPARATOR: {
        criteria.add(Restrictions.isNotEmpty(parameterName));
        break;
    }
    default: {
        if (parameterValue != null) {
            switch (comparator) {
            case SearchParameter.LIKE_COMPARATOR: {
                if ((matchMode != null) && (parameterValue instanceof String)) {
                    criteria.add(Restrictions.like(parameterName, (String) parameterValue, matchMode));
                } else {
                    criteria.add(Restrictions.like(parameterName, parameterValue));
                }
                break;
            }
            case SearchParameter.NOT_LIKE_COMPARATOR: {
                SimpleExpression expression;
                if ((matchMode != null) && (parameterValue instanceof String)) {
                    expression = Restrictions.like(parameterName, (String) parameterValue, matchMode);
                } else {
                    expression = Restrictions.like(parameterName, parameterValue);
                }
                criteria.add(Restrictions.not(expression));
                break;
            }
            case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: {
                if ((matchMode != null) && (parameterValue instanceof String)) {
                    criteria.add(Restrictions.ilike(parameterName, (String) parameterValue, matchMode));
                } else {
                    criteria.add(Restrictions.ilike(parameterName, parameterValue));
                }
                break;
            }
            case SearchParameter.NOT_INSENSITIVE_LIKE_COMPARATOR: {
                Criterion criterion;
                if ((matchMode != null) && (parameterValue instanceof String)) {
                    criterion = Restrictions.ilike(parameterName, (String) parameterValue, matchMode);
                } else {
                    criterion = Restrictions.ilike(parameterName, parameterValue);
                }
                criteria.add(Restrictions.not(criterion));
                break;
            }
            case SearchParameter.EQUAL_COMPARATOR: {
                criteria.add(Restrictions.eq(parameterName, parameterValue));
                break;
            }
            case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: {
                criteria.add(Restrictions.ge(parameterName, parameterValue));
                break;
            }
            case SearchParameter.GREATER_THAN_COMPARATOR: {
                criteria.add(Restrictions.gt(parameterName, parameterValue));
                break;
            }
            case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: {
                criteria.add(Restrictions.le(parameterName, parameterValue));
                break;
            }
            case SearchParameter.LESS_THAN_COMPARATOR: {
                criteria.add(Restrictions.lt(parameterName, parameterValue));
                break;
            }
            case SearchParameter.IN_COMPARATOR: {
                if (parameterValue instanceof Collection) {
                    criteria.add(Restrictions.in(parameterName, (Collection) parameterValue));
                }
                break;
            }
            case SearchParameter.NOT_IN_COMPARATOR: {
                if (parameterValue instanceof Collection) {
                    criteria.add(Restrictions.not(Restrictions.in(parameterName, (Collection) parameterValue)));
                }
                break;
            }
            case SearchParameter.NOT_EQUAL_COMPARATOR: {
                criteria.add(Restrictions.ne(parameterName, parameterValue));
                break;
            }
            }
        } else {
            criteria.add(Restrictions.isNull(parameterName));
        }
    }
    }
}

From source file:com.algoTrader.CriteriaSearch.java

/**
 * Adds an <code>Restrictions</code> to a <code>Criteria</code>. The given <code>parameterValues</code>
 * represents either an array of <code>String</code> or another object. The different values in the
 * array are added to a disjunction or conjunction which is connected with logical and to the other criteria of the
 * search.//from  w  w  w. j  av a2  s. c  o m
 *
 * @param criteria
 * @param parameterName
 * @param parameterValues
 * @param searchIfNull
 * @param comparator
 * @param matchMode
 */
private void addExpression(Criteria criteria, String parameterName, Object[] parameterValues, int comparator,
        MatchMode matchMode) {
    if (parameterValues != null) {
        Disjunction disjunction = null;
        Conjunction conjunction = null;
        switch (comparator) {
        case SearchParameter.LIKE_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            if ((matchMode != null) && (parameterValues instanceof String[])) {
                String[] stringParameterValues = (String[]) parameterValues;
                for (int index = 0; index < parameterValues.length; index++) {
                    if (stringParameterValues[index] != null) {
                        disjunction
                                .add(Restrictions.like(parameterName, stringParameterValues[index], matchMode));
                    } else {
                        disjunction.add(Restrictions.isNull(parameterName));
                    }
                }
            } else {
                for (int index = 0; index < parameterValues.length; index++) {
                    if (parameterValues[index] != null) {
                        disjunction.add(Restrictions.like(parameterName, parameterValues[index]));
                    } else {
                        disjunction.add(Restrictions.isNull(parameterName));
                    }
                }
            }
            break;
        }
        case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            if ((matchMode != null) && (parameterValues instanceof String[])) {
                String[] stringParameterValues = (String[]) parameterValues;
                for (int index = 0; index < parameterValues.length; index++) {
                    if (stringParameterValues[index] != null) {
                        disjunction.add(
                                Restrictions.ilike(parameterName, stringParameterValues[index], matchMode));
                    } else {
                        disjunction.add(Restrictions.isNull(parameterName));
                    }
                }
            } else {
                for (int index = 0; index < parameterValues.length; index++) {
                    if (parameterValues[index] != null) {
                        disjunction.add(Restrictions.ilike(parameterName, parameterValues[index]));
                    } else {
                        disjunction.add(Restrictions.isNull(parameterName));
                    }
                }
            }
            break;
        }
        case SearchParameter.EQUAL_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.eq(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.ge(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.GREATER_THAN_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.gt(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.le(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.LESS_THAN_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.lt(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.IN_COMPARATOR: {
            criteria.add(Restrictions.in(parameterName, parameterValues));
            break;
        }
        case SearchParameter.NOT_IN_COMPARATOR: {
            criteria.add(Restrictions.not(Restrictions.in(parameterName, parameterValues)));
            break;
        }
        case SearchParameter.NOT_EQUAL_COMPARATOR: {
            conjunction = Restrictions.conjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    conjunction.add(Restrictions.ne(parameterName, parameterValues[index]));
                } else {
                    conjunction.add(Restrictions.isNotNull(parameterName));
                }
            }
            break;
        }
        }

        if (disjunction != null) {
            criteria.add(disjunction);
        }
        if (conjunction != null) {
            criteria.add(conjunction);
        }
    } else {
        switch (comparator) {
        case SearchParameter.EMPTY_COMPARATOR: {
            criteria.add(Restrictions.isEmpty(parameterName));
            break;
        }
        case SearchParameter.NOT_EMPTY_COMPARATOR: {
            criteria.add(Restrictions.isNotEmpty(parameterName));
            break;
        }
        default: {
            criteria.add(Restrictions.isNull(parameterName));
        }
        }
    }
}

From source file:com.bean.SearchBean.java

public void init() {
    Dao dao = new Dao();

    long pMin = 0, pMax = 0, aMin = 0, aMax = 0;
    try {//  w w  w. ja v  a  2s.c o  m
        pMin = Long.parseLong(this.priceMin);
    } catch (Exception ex) {

    }
    try {
        pMax = Long.parseLong(this.priceMax);
    } catch (Exception ex) {

    }
    try {
        aMin = Long.parseLong(this.areaMin);
    } catch (Exception ex) {

    }
    try {
        aMax = Long.parseLong(this.areaMax);
    } catch (Exception ex) {

    }

    LogicalExpression logic;
    Criterion district = null;
    Criterion province;
    Criterion propertyType = null;
    Criterion exchange = null;
    Criterion priceMin;
    Criterion priceMax;
    Criterion areaMin;
    Criterion areaMax;

    if (this.propertyType != 0) {
        PropertyType p = new PropertyType(this.propertyType);
        propertyType = Restrictions.eq("propertyType", p);
    } else {
        propertyType = Restrictions.isNotNull("propertyType");
    }

    if (this.exchangeType != 0) {
        ExchangeType e = new ExchangeType(this.exchangeType);
        exchange = Restrictions.eq("exchangeType", e);
    } else {
        exchange = Restrictions.isNotNull("exchangeType");
    }

    if (districtId != 0) {
        District d = new District(districtId);
        district = Restrictions.eq("district", d);
    } else {
        if (provinceId != 0) {
            Province p = (Province) dao.getById1(Province.class, provinceId);
            //Set<District> list = p.getDistricts();
            if (p != null && p.getDistricts().size() > 0) {
                district = Restrictions.in("district", p.getDistricts());
            } else {
                district = Restrictions.isNull("district");
            }
        }
    }
    Criterion cpub = Restrictions.eq("proPublish", true);
    Criterion stt = Restrictions.eq("proStatus", 0);
    logic = Restrictions.and(propertyType, exchange);
    logic = Restrictions.and(logic, stt);
    logic = Restrictions.and(logic, cpub);
    if (district != null) {
        logic = Restrictions.and(logic, district);
    }

    if (pMax > 0) {
        priceMax = Restrictions.between("proPrice", pMin, pMax);
        logic = Restrictions.and(logic, priceMax);
    } else {
        priceMin = Restrictions.gt("proPrice", pMin);
        logic = Restrictions.and(logic, priceMin);
    }

    if (aMax > 0) {
        areaMax = Restrictions.between("proArea", aMin, aMax);
        logic = Restrictions.and(logic, areaMax);
    } else {
        areaMin = Restrictions.gt("proArea", aMin);
        logic = Restrictions.and(logic, areaMin);
    }

    Order o = Order.desc("proPublishDate");

    listSearch = dao.getByCondition(Property.class, logic, o);

}

From source file:com.bloatit.data.queries.DaoFeatureQuery.java

License:Open Source License

/**
 * Add a WHERE close ensuring that there isn't a selected offer on each
 * returned daoFeature.
 */
public void withoutSelectedOffer() {
    add(Restrictions.isNull(SELECTED_OFFER));
}

From source file:com.bloatit.data.queries.DaoUserContentQuery.java

License:Open Source License

/**
 * Show content with no team
 */
public void withNoTeam() {
    add(Restrictions.isNull(AS_TEAM));
}