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:de.cosmocode.hibernate.CustomRestrictions.java

License:Apache License

/**
 * Apply an "empty" constraint on the named property.
 * /*from   w w w  .j  a  v  a 2s  .c om*/
 * <p>
 *   See also {@link StringUtils#isEmpty(String)}
 * </p>
 * 
 * @param propertyName the name of the property the constraint should be applied to
 * @return a new {@link Criterion}
 */
public static Criterion isEmpty(String propertyName) {
    return Restrictions.or(Restrictions.eq(propertyName, ""), Restrictions.isNull(propertyName));
}

From source file:de.decidr.model.commands.tenant.GetTenantsToApproveCommand.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from   w  w w  .j  av a 2 s  .  co  m
public void transactionAllowed(TransactionStartedEvent evt) throws TransactionException {

    result = new ArrayList<TenantWithAdminView>();

    PaginatingCriteria c = new PaginatingCriteria(TenantWithAdminView.class, evt.getSession());
    c.add(Restrictions.isNull("approvedSince"));

    Filters.apply(c, filters, paginator);

    result = c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY).list();
}

From source file:de.decidr.model.filters.EqualsFilter.java

License:Apache License

@Override
public void apply(Criteria criteria) {
    if (propertyValue == null) {
        // checking against null is a special case
        if (include) {
            criteria.add(Restrictions.isNull(propertyName));
        } else {//  w  ww.j a  v a 2 s. co m
            criteria.add(Restrictions.isNotNull(propertyName));
        }
    } else {
        if (include) {
            criteria.add(Restrictions.eq(propertyName, propertyValue));
        } else {
            criteria.add((Restrictions.not(Restrictions.eq(propertyName, propertyValue))));
        }
    }
}

From source file:de.escidoc.core.aa.business.persistence.hibernate.HibernateUserAccountDao.java

License:Open Source License

/**
 * See Interface for functional description.
 *
 * @see UserAccountDaoInterface #retrieveCurrentGrant(java.lang.String, EscidocRole, java.lang.String)
 *//*from   w  w w.j  av  a  2s.c  o  m*/
@Override
public RoleGrant retrieveCurrentGrant(final UserAccount userAccount, final EscidocRole role, final String objId)
        throws SqlDatabaseSystemException {

    RoleGrant result = null;
    if (userAccount != null && role != null) {

        try {
            DetachedCriteria criteria = DetachedCriteria.forClass(RoleGrant.class)
                    .add(Restrictions.eq("userAccountByUserId", userAccount))
                    .add(Restrictions.eq("escidocRole", role)).add(Restrictions.isNull("revocationDate"));
            if (objId != null) {
                criteria = criteria.add(Restrictions.eq("objectId", objId));
            }
            result = (RoleGrant) getUniqueResult(getHibernateTemplate().findByCriteria(criteria));
        } catch (final DataAccessException e) {
            throw new SqlDatabaseSystemException(e);
        } catch (final IllegalStateException e) {
            throw new SqlDatabaseSystemException(e);
        } catch (final HibernateException e) {
            //noinspection ThrowableResultOfMethodCallIgnored
            throw new SqlDatabaseSystemException(convertHibernateAccessException(e)); // Ignore FindBugs
        }
    }
    return result;
}

From source file:de.escidoc.core.aa.business.persistence.hibernate.HibernateUserAccountDao.java

License:Open Source License

/**
 * get an in-restriction. Eventually concatenated with an isNull-restriction if criteria-set contains a null-value.
 *
 * @param criteria  criteria to put in in-restriction
 * @param fieldName field-name for in-restriction
 * @return Criterion/*from w ww .j a va  2s  .c om*/
 */
private static Criterion getInRestrictions(final Collection<String> criteria, final String fieldName) {
    if (criteria.contains("")) {
        criteria.remove("");
        return criteria.isEmpty() ? Restrictions.isNull(fieldName)
                : Restrictions.or(Restrictions.isNull(fieldName),
                        Restrictions.in(fieldName, criteria.toArray()));
    } else {
        return Restrictions.in(fieldName, criteria.toArray());
    }
}

From source file:de.escidoc.core.aa.business.persistence.hibernate.HibernateUserGroupDao.java

License:Open Source License

/**
 * See Interface for functional description.
 *
 * @see UserGroupDaoInterface #retrieveCurrentGrant(java.lang.String, EscidocRole, java.lang.String)
 *//*from  w  ww. j a  v  a 2 s.  co  m*/
@Override
public RoleGrant retrieveCurrentGrant(final UserGroup userGroup, final EscidocRole role, final String objId)
        throws SqlDatabaseSystemException {
    RoleGrant result = null;

    if (userGroup != null && role != null) {
        try {
            DetachedCriteria criteria = DetachedCriteria.forClass(RoleGrant.class)
                    .add(Restrictions.eq("userGroupByGroupId", userGroup))
                    .add(Restrictions.eq("escidocRole", role)).add(Restrictions.isNull("revocationDate"));
            if (objId != null) {
                criteria = criteria.add(Restrictions.eq("objectId", objId));
            }
            result = (RoleGrant) getUniqueResult(getHibernateTemplate().findByCriteria(criteria));
        } catch (final DataAccessException e) {
            throw new SqlDatabaseSystemException(e);
        } catch (final IllegalStateException e) {
            throw new SqlDatabaseSystemException(e);
        } catch (final HibernateException e) {
            //noinspection ThrowableResultOfMethodCallIgnored
            throw new SqlDatabaseSystemException(convertHibernateAccessException(e)); // Ignore FindBugs
        }
    }
    return result;
}

From source file:de.escidoc.core.aa.business.persistence.hibernate.HibernateUserGroupDao.java

License:Open Source License

/**
 * See Interface for functional description.
 *
 * @see UserGroupDaoInterface #retrieveGrants(List)
 *///from w  ww  . j ava 2  s.  co  m
@Override
public Map<String, List<RoleGrant>> retrieveCurrentGrants(final List<String> groupIds)
        throws SqlDatabaseSystemException {

    final Map<String, List<RoleGrant>> orderedResult = new HashMap<String, List<RoleGrant>>();

    final DetachedCriteria detachedCriteria = DetachedCriteria.forClass(RoleGrant.class);
    detachedCriteria.add(Restrictions.in("groupId", groupIds.toArray()));
    detachedCriteria.add(Restrictions.isNull("revocationDate"));
    detachedCriteria.addOrder(Order.desc("objectId"));

    final List<RoleGrant> roleGrants;
    try {
        roleGrants = getHibernateTemplate().findByCriteria(detachedCriteria);
    } catch (final DataAccessException e) {
        throw new SqlDatabaseSystemException(e);
    }
    if (roleGrants != null) {
        for (final RoleGrant roleGrant : roleGrants) {
            if (orderedResult.get(roleGrant.getGroupId()) == null) {
                orderedResult.put(roleGrant.getGroupId(), new ArrayList<RoleGrant>());
            }
            orderedResult.get(roleGrant.getGroupId()).add(roleGrant);
        }
    }

    return orderedResult;
}

From source file:de.escidoc.core.common.business.filter.CqlFilter.java

License:Open Source License

/**
 * Evaluate a CQL relation./*from www.  ja  v  a2  s .  c o  m*/
 * 
 * @param relation
 *            CQL relation
 * @param propertyName
 *            left side of the statement
 * @param value
 *            right side of the statement
 * @param useLike
 *            use LIKE instead of = in case of an equality relation
 * @return Hibernate query reflecting the given CQL query
 * @throws InvalidSearchQueryException
 *             thrown if the given search query could not be translated into a SQL query
 */
protected Criterion evaluate(final CQLRelation relation, final String propertyName, final Object value,
        final boolean useLike) throws InvalidSearchQueryException {
    final Criterion result;
    final String rel = relation.getBase();

    if (value == null || value.toString().length() == 0) {
        result = Restrictions.isNull(propertyName);
    } else {
        if ("<".equals(rel)) {
            result = Restrictions.lt(propertyName, value);
        } else if ("<=".equals(rel)) {
            result = Restrictions.le(propertyName, value);
        } else if ("=".equals(rel)) {
            result = useLike ? Restrictions.like(propertyName, value) : Restrictions.eq(propertyName, value);
        } else if (">=".equals(rel)) {
            result = Restrictions.ge(propertyName, value);
        } else if (">".equals(rel)) {
            result = Restrictions.gt(propertyName, value);
        } else if ("<>".equals(rel)) {
            result = Restrictions.ne(propertyName, value);
        } else {
            throw new InvalidSearchQueryException(rel + ": relation not implemented");
        }
    }
    return result;
}

From source file:de.escidoc.core.common.business.filter.CqlFilter.java

License:Open Source License

/**
 * get an in-restriction. Eventually concatenated with an isNull-restriction if criteria-set contains a null-value.
 * /* www .  j a  va 2  s .c om*/
 * @param criteria
 *            criteria to put in in-restriction
 * @param fieldName
 *            field-name for in-restriction
 * @return Criterion
 */
protected Criterion getInRestrictions(final Collection<String> criteria, final String fieldName) {
    if (criteria.contains("")) {
        criteria.remove("");
        return criteria.isEmpty() ? Restrictions.isNull(fieldName)
                : Restrictions.or(Restrictions.isNull(fieldName),
                        Restrictions.in(fieldName, criteria.toArray()));
    } else {
        return Restrictions.in(fieldName, criteria.toArray());
    }
}

From source file:de.iew.framework.persistence.hibernate.HbmTreeOperationDaoImpl.java

License:Apache License

public Node findRootNodeForTree(long treeId) {
    Criteria crit = getCurrentSession().createCriteria(Node.class);
    crit.add(Restrictions.eq("tree.id", treeId)).add(Restrictions.isNull("parent"));

    return (Node) crit.uniqueResult();
}