Example usage for org.hibernate.criterion Subqueries lt

List of usage examples for org.hibernate.criterion Subqueries lt

Introduction

In this page you can find the example usage for org.hibernate.criterion Subqueries lt.

Prototype

public static Criterion lt(Object value, DetachedCriteria dc) 

Source Link

Document

Creates a criterion which checks that the value of a given literal as being less-than the value in the subquery result.

Usage

From source file:com.qcadoo.model.api.search.SearchSubqueries.java

License:Open Source License

public static SearchCriterion lt(final Object value, final SearchCriteriaBuilder criteria) {
    return new SearchCriterionImpl(
            Subqueries.lt(value, ((SearchCriteria) criteria).getHibernateDetachedCriteria()));
}

From source file:de.escidoc.core.aa.business.filter.RoleFilter.java

License:Open Source License

/**
 * Evaluate a CQL term node.//from  w ww.  j  a  va 2  s. com
 *
 * @param node CQL node
 * @return Hibernate query reflecting the given CQL query
 * @throws InvalidSearchQueryException thrown if the given search query could not be translated into a SQL query
 */
@Override
protected Criterion evaluate(final CQLTermNode node) throws InvalidSearchQueryException {
    Criterion result = null;
    final Object[] parts = criteriaMap.get(node.getIndex());
    final String value = node.getTerm();

    if (parts != null && !specialCriteriaNames.contains(node.getIndex())) {
        result = evaluate(node.getRelation(), (String) parts[1], value, (Integer) parts[0] == COMPARE_LIKE);
    } else {
        final String columnName = node.getIndex();

        if (columnName != null) {
            if ("limited".equals(columnName)) {
                result = Boolean.parseBoolean(value) ? Restrictions.isNotEmpty("scopeDefs")
                        : Restrictions.isEmpty("scopeDefs");
            } else if ("granted".equals(columnName)) {
                final DetachedCriteria subQuery = DetachedCriteria.forClass(RoleGrant.class, "rg");

                subQuery.setProjection(Projections.rowCount());
                subQuery.add(Restrictions.eqProperty("escidocRole.id", "r.id"));

                result = Boolean.parseBoolean(value) ? Subqueries.lt(0L, subQuery)
                        : Subqueries.eq(0L, subQuery);
            } else if (columnName.equals(Constants.FILTER_CREATION_DATE)
                    || columnName.equals(Constants.FILTER_PATH_CREATION_DATE)) {
                result = evaluate(node.getRelation(), "creationDate",
                        value != null && value.length() > 0 ? new Date(new DateTime(value).getMillis()) : null,
                        false);
            } else {
                throw new InvalidSearchQueryException("unknown filter criteria: " + columnName);
            }
        }
    }
    return result;
}

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

License:Open Source License

/**
 * See Interface for functional description.
 *
 * @see EscidocRoleDaoInterface #retrieveRoles(java.util.Map, int, int, java.lang.String,
 *      de.escidoc.core.common.util.list.ListSorting)
 *//*from  ww w.j a  va  2s .co  m*/
@Override
public List<EscidocRole> retrieveRoles(final Map<String, Object> criterias, final int offset,
        final int maxResults, final String orderBy, final ListSorting sorting)
        throws SqlDatabaseSystemException {

    final DetachedCriteria detachedCriteria = DetachedCriteria.forClass(EscidocRole.class, "r");
    detachedCriteria.add(Restrictions.ne("id", EscidocRole.DEFAULT_USER_ROLE_ID));

    if (criterias != null && !criterias.isEmpty()) {
        // ids
        final Set<String> roleIds = mergeSets((Set<String>) criterias.remove(Constants.DC_IDENTIFIER_URI),
                (Set<String>) criterias.remove(Constants.FILTER_PATH_ID));
        if (roleIds != null && !roleIds.isEmpty()) {
            detachedCriteria.add(Restrictions.in("id", roleIds.toArray()));
        }

        // limited
        final String limited = (String) criterias.remove("limited");
        if (limited != null) {
            if (Boolean.parseBoolean(limited)) {
                detachedCriteria.add(Restrictions.isNotEmpty("scopeDefs"));
            } else {
                detachedCriteria.add(Restrictions.isEmpty("scopeDefs"));
            }
        }

        // granted
        final String granted = (String) criterias.remove("granted");
        if (granted != null) {
            final DetachedCriteria subQuery = DetachedCriteria.forClass(RoleGrant.class, "rg");
            subQuery.setProjection(Projections.rowCount());
            subQuery.add(Restrictions.eqProperty("escidocRole.id", "r.id"));

            if (Boolean.parseBoolean(granted)) {
                detachedCriteria.add(Subqueries.lt(0, subQuery));
            } else {
                detachedCriteria.add(Subqueries.eq(0, subQuery));
            }
        }

        for (final Entry<String, Object[]> stringEntry : criteriaMap.entrySet()) {
            final Object criteriaValue = criterias.remove(stringEntry.getKey());
            if (criteriaValue != null) {
                final Object[] parts = stringEntry.getValue();
                if (parts[0].equals(COMPARE_EQ)) {
                    detachedCriteria.add(Restrictions.eq((String) parts[1], criteriaValue));
                } else {
                    detachedCriteria.add(Restrictions.like((String) parts[1], criteriaValue));
                }
            }
        }
    }

    if (orderBy != null) {
        if (sorting == ListSorting.ASCENDING) {
            detachedCriteria.addOrder(Order.asc(propertiesNamesMap.get(orderBy)));
        } else if (sorting == ListSorting.DESCENDING) {
            detachedCriteria.addOrder(Order.desc(propertiesNamesMap.get(orderBy)));
        }
    }

    if (criterias != null && criterias.isEmpty()) {

        final List<EscidocRole> result;
        try {
            result = getHibernateTemplate().findByCriteria(detachedCriteria, offset, maxResults);
        } catch (final DataAccessException e) {
            throw new SqlDatabaseSystemException(e);
        }

        return result;
    } else {
        // unsupported filter criteria has been found, therefore the result
        // list must be empty.
        return new ArrayList<EscidocRole>(0);
    }
}