Example usage for org.hibernate.criterion Restrictions isNotNull

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

Introduction

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

Prototype

public static Criterion isNotNull(String propertyName) 

Source Link

Document

Apply an "is not null" constraint to the named property

Usage

From source file:com.abiquo.server.core.enterprise.DatacenterLimitsDAO.java

License:Open Source License

public Collection<DatacenterLimits> findByEnterprise(final Enterprise enterprise) {
    return findByCriterions(sameEnterprise(enterprise),
            Restrictions.isNotNull(DatacenterLimits.DATACENTER_PROPERTY));
}

From source file:com.abiquo.server.core.enterprise.EnterpriseDAO.java

License:Open Source License

private Criterion withPricingTemplate() {
    Disjunction filterDisjunction = Restrictions.disjunction();
    filterDisjunction.add(Restrictions.isNotNull(Enterprise.PRICING_PROPERTY));

    return filterDisjunction;
}

From source file:com.abiquo.server.core.infrastructure.MachineDAO.java

License:Open Source License

public List<Machine> findRackEnabledForHAMachines(final Rack rack) {
    if (rack instanceof UcsRack) {
        return findRackEnabledForHAMachinesInUcs((UcsRack) rack);
    }/*from  w w  w  . j a v  a  2s .  c  om*/
    Criteria criteria = createCriteria(sameRack(rack));
    criteria.createAlias(Machine.HYPERVISOR_PROPERTY, "hypervisor");

    // Is a managed one
    criteria.add(Restrictions.eq(Machine.STATE_PROPERTY, MachineState.MANAGED));

    // Has fencing capabilities
    criteria.add(Restrictions.isNotNull(Machine.IPMI_IP_PROPERTY));
    criteria.add(Restrictions.isNotNull(Machine.IPMI_USER_PROPERTY));
    criteria.add(Restrictions.isNotNull(Machine.IPMI_PASSWORD_PROPERTY));

    // XenServer does not support HA
    criteria.add(Restrictions.ne("hypervisor." + Hypervisor.TYPE_PROPERTY, HypervisorType.XENSERVER));

    // Order by name
    criteria.addOrder(Order.asc(Machine.NAME_PROPERTY));

    return getResultList(criteria);
}

From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java

License:Open Source License

/**
 * Return the list of IPs purchased by an enterprise in a public VLAN. Any IP in a public VLAN
 * with VirtualDatacenter not null/* w ww .j  a v a  2 s. c o m*/
 * 
 * @param vlan network to search into.
 * @return the list of with IPs purchased.
 */
public List<IpPoolManagement> findPublicIpsPurchasedByVlan(final VLANNetwork vlan) {
    return findByCriterions(Restrictions.eq(IpPoolManagement.VLAN_NETWORK_PROPERTY, vlan),
            Restrictions.isNotNull(RasdManagement.VIRTUAL_DATACENTER_PROPERTY));
}

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

License:Open Source License

/**
 * Gets the global {@link FitPolicyRuleHB}.
 * /*w ww.  j a  v a2  s. c o  m*/
 * @return The global <code>FitPolicyRuleHB</code>.
 */
public List<FitPolicyRule> getDatacenterFitPolicies() {
    Criteria criteria = getSession().createCriteria(FitPolicyRule.class);
    Criterion anyDatacenter = Restrictions.isNotNull(FitPolicyRule.DATACENTER_PROPERTY);
    criteria.add(anyDatacenter);

    // criteria.addOrder(Order.asc(FitPolicyRule.ID_PROPERTY));

    List<FitPolicyRule> result = getResultList(criteria);

    return result;

}

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

License:Apache License

/**
 * ??Criterion,./*from   ww  w.ja 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

/**
 * ??/*  ww  w  .  ja  v  a  2 s. c  o 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.aistor.modules.cms.service.ArticleService.java

License:Open Source License

public Page<Article> find(Page<Article> page, Article article) {
    DetachedCriteria dc = articleDao.createDetachedCriteria();
    dc.createAlias("category", "category");
    dc.createAlias("category.site", "category.site");
    if (article.getCategory() != null && article.getCategory().getId() != null
            && !Category.isRoot(article.getCategory().getId())) {
        Category category = categoryDao.findOne(article.getCategory().getId());
        if (category != null) {
            dc.add(Restrictions.or(Restrictions.eq("category.id", category.getId()),
                    Restrictions.eq("category.parent.id", category.getId()),
                    Restrictions.like("category.parentIds", "%," + category.getId() + ",%")));
            dc.add(Restrictions.eq("category.site.id", category.getSite().getId()));
            article.setCategory(category);
        } else {/*from   w w  w .  j a va 2 s .co m*/
            dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
        }
    } else {
        dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
    }
    if (StringUtils.isNotEmpty(article.getTitle())) {
        dc.add(Restrictions.like("title", "%" + article.getTitle() + "%"));
    }
    if (StringUtils.isNotEmpty(article.getPosid())) {
        dc.add(Restrictions.like("posid", "%," + article.getPosid() + ",%"));
    }
    if (StringUtils.isNotEmpty(article.getThumb()) && "1".equals(article.getThumb())) {
        dc.add(Restrictions.and(Restrictions.isNotNull("thumb"), Restrictions.ne("thumb", "")));
    }
    if (article.getUser() != null && article.getUser().getId() > 0) {
        dc.add(Restrictions.eq("user.id", article.getUser().getId()));
    }
    dc.add(Restrictions.eq("status", article.getStatus()));
    dc.addOrder(Order.desc("weight"));
    dc.addOrder(Order.desc("updateDate"));
    return articleDao.find(page, dc);
}

From source file:com.algoTrader.CriteriaSearch.java

/**
 * Adds an <code>Restrictions</code> to a <code>Criteria</code>.
 *
 * @param criteria// w  w w.ja  v  a2 s . co  m
 * @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   ww w .  j ava  2s  . 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));
        }
        }
    }
}