Example usage for org.hibernate.criterion Restrictions not

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

Introduction

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

Prototype

public static Criterion not(Criterion expression) 

Source Link

Document

Return the negation of an expression

Usage

From source file:org.evolizer.famix.model.utils.SnapshotAnalyzer.java

License:Apache License

/**
 * Query incoming or outgoing FAMIX associations of the given type and set of entities.
 * //ww  w . ja  va  2  s  .  c o  m
 * @param entities   The set of entities.
 * @param associationType   FamixAssociation type - if null all associations are queried.
 * @param direction   The direction of associations either "from" (i.e., outgoing) or "to" (i.e., incoming).
 * @return   The list of associations.
 * 
 * TODO: Handle null values for direction or introduce constants
 */
@SuppressWarnings("unchecked")
public <T extends FamixAssociation> List<T> queryAssociationsOfEntities(
        Collection<? extends AbstractFamixEntity> entities, java.lang.Class<T> associationType,
        String direction) throws EvolizerRuntimeException {
    associationType = (associationType != null) ? associationType
            : (Class<T>) org.evolizer.famix.model.entities.FamixAssociation.class;

    String oppositeDirection = "";
    if (direction.equals("from")) {
        oppositeDirection = "to";
    } else if (direction.equals("to")) {
        oppositeDirection = "from";
    }

    List<T> associations = new ArrayList<T>();
    try {
        if (entities.size() > 0) {
            Criteria invocationQuery = getHibernateSession().createCriteria(associationType)
                    .add(Restrictions.and(Restrictions.in(direction, entities),
                            Restrictions.not(Restrictions.in(oppositeDirection, entities))));
            invocationQuery.createAlias("from", "f");
            invocationQuery.createAlias("to", "t");

            invocationQuery.add(
                    Restrictions.and(Restrictions.isNotNull("f.parent"), Restrictions.isNotNull("t.parent")));

            associations = invocationQuery.list();
        }
    } catch (HibernateException he) {
        fLogger.error("Error in queryAssociationsOfEntities " + he.getMessage());
        throw new EvolizerRuntimeException("Error in queryAssociationsOfEntities", he);
    } catch (EvolizerException ee) {
        fLogger.error("Error in queryAssociationsOfEntities " + ee.getMessage());
        throw new EvolizerRuntimeException("Error in queryAssociationsOfEntities", ee);
    }

    return associations;
}

From source file:org.faster.orm.service.hibernate.HibernateValidateService.java

License:Open Source License

@Override
public void validatesUniquenessOf(PO po, String propertyName, ID excludeId, Errors<PO> errors) {
    Object value = Beans.getProperty(po, propertyName);
    if (Beans.isNullOrEmpty(value)) {
        return;//  w  w  w . j a v a 2s  .c  o  m
    }

    DetachedCriteria dc = buildCriteriaByPropertyAndValue(propertyName, value);
    if (excludeId != null) {
        dc.add(Restrictions.not(Restrictions.idEq(excludeId)));
    }

    if (existsByCriteria(dc)) {
        errors.addErrorCode(propertyName.toUpperCase() + "_ALREADY_EXISTS");
    }
}

From source file:org.fornax.cartridges.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionAccessImpl.java

License:Apache License

private Criterion makeCriterion(ConditionalCriteria crit) {
    if (crit == null) {
        return null;
    }//from ww w . j ava 2  s. c  o m

    ConditionalCriteria.Operator operator = crit.getOperator();
    if (Operator.Equal.equals(operator)) {
        return Restrictions.eq(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant());
    } else if (Operator.IgnoreCaseEqual.equals(operator)) {
        return Restrictions.eq(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant())
                .ignoreCase();
    } else if (Operator.LessThan.equals(operator)) {
        return Restrictions.lt(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant());
    } else if (Operator.LessThanOrEqual.equals(operator)) {
        return Restrictions.le(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant());
    } else if (Operator.GreatThan.equals(operator)) {
        return Restrictions.gt(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant());
    } else if (Operator.GreatThanOrEqual.equals(operator)) {
        return Restrictions.ge(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant());
    } else if (Operator.Like.equals(operator)) {
        return Restrictions.like(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant());
    } else if (Operator.IgnoreCaseLike.equals(operator)) {
        return Restrictions.ilike(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant());
    } else if (Operator.IsNull.equals(operator)) {
        return Restrictions.isNull(makePathWithAlias(crit.getPropertyFullName()));
    } else if (Operator.IsNotNull.equals(operator)) {
        return Restrictions.isNotNull(makePathWithAlias(crit.getPropertyFullName()));
    } else if (Operator.IsEmpty.equals(operator)) {
        return Restrictions.isEmpty(makePathWithAlias(crit.getPropertyFullName()));
    } else if (Operator.IsNotEmpty.equals(operator)) {
        return Restrictions.isNotEmpty(makePathWithAlias(crit.getPropertyFullName()));
    } else if (Operator.Not.equals(operator)) {
        return Restrictions.not(makeCriterion((ConditionalCriteria) crit.getFirstOperant()));
    } else if (Operator.Or.equals(operator) && crit.getFirstOperant() instanceof List<?>) {
        Disjunction disj = Restrictions.disjunction();
        List<?> disjList = (List<?>) crit.getFirstOperant();
        for (Object disjPart : disjList) {
            disj.add(makeCriterion((ConditionalCriteria) disjPart));
        }
        return disj;
    } else if (Operator.Or.equals(operator)) {
        return Restrictions.or(makeCriterion((ConditionalCriteria) crit.getFirstOperant()),
                makeCriterion((ConditionalCriteria) crit.getSecondOperant()));
    } else if (Operator.And.equals(operator) && crit.getFirstOperant() instanceof List<?>) {
        Conjunction conj = Restrictions.conjunction();
        List<?> conjList = (List<?>) crit.getFirstOperant();
        for (Object conjPart : conjList) {
            conj.add(makeCriterion((ConditionalCriteria) conjPart));
        }
        return conj;
    } else if (Operator.And.equals(operator)) {
        return Restrictions.and(makeCriterion((ConditionalCriteria) crit.getFirstOperant()),
                makeCriterion((ConditionalCriteria) crit.getSecondOperant()));
    } else if (Operator.In.equals(operator)) {
        if (crit.getFirstOperant() instanceof Collection<?>) {
            return Restrictions.in(makePathWithAlias(crit.getPropertyFullName()),
                    (Collection<?>) crit.getFirstOperant());
        } else {
            return Restrictions.in(makePathWithAlias(crit.getPropertyFullName()),
                    (Object[]) crit.getFirstOperant());
        }
    } else if (Operator.Between.equals(operator)) {
        return Restrictions.between(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant(),
                crit.getSecondOperant());
    } else if (Operator.DistinctRoot.equals(operator)) {
        realDistinctRoot = true;
        return null;
    } else if (Operator.ProjectionRoot.equals(operator)) {
        resultTransformer = Criteria.PROJECTION;
        return null;
    } else if (Operator.EqualProperty.equals(operator)) {
        return Restrictions.eqProperty(makePathWithAlias(crit.getPropertyFullName()),
                (String) crit.getFirstOperant());
    } else if (Operator.LessThanProperty.equals(operator)) {
        return Restrictions.eqProperty(makePathWithAlias(crit.getPropertyFullName()),
                (String) crit.getFirstOperant());
    } else if (Operator.LessThanOrEqualProperty.equals(operator)) {
        return Restrictions.eqProperty(makePathWithAlias(crit.getPropertyFullName()),
                (String) crit.getFirstOperant());
    } else if (Operator.GreatThanProperty.equals(operator)) {
        return Restrictions.eqProperty(makePathWithAlias(crit.getPropertyFullName()),
                (String) crit.getFirstOperant());
    } else if (Operator.GreatThanOrEqualProperty.equals(operator)) {
        return Restrictions.eqProperty(makePathWithAlias(crit.getPropertyFullName()),
                (String) crit.getFirstOperant());
    } else {
        return null;
    }
}

From source file:org.generationcp.middleware.dao.LocationDAO.java

License:Open Source License

public List<Location> getByUniqueIDAndExcludeLocationTypes(final String programUUID,
        final List<Integer> locationTypesToExclude) {

    List<Location> locations = new ArrayList<>();

    if (programUUID == null || programUUID.isEmpty()) {
        return locations;
    }//from ww  w. ja va 2s .  c  o m

    try {
        final Criteria criteria = this.getSession().createCriteria(Location.class);
        criteria.add(Restrictions.or(Restrictions.eq(LocationDAO.UNIQUE_ID, programUUID),
                Restrictions.isNull(LocationDAO.UNIQUE_ID)));
        if (locationTypesToExclude != null && !locationTypesToExclude.isEmpty()) {
            criteria.add(Restrictions.not(Restrictions.in(LocationDAO.LTYPE, locationTypesToExclude)));
        }
        locations = criteria.list();
    } catch (final HibernateException e) {
        throw new MiddlewareQueryException(this.getLogExceptionMessage("getByUniqueIDAndExcludeLocationTypes",
                "", null, e.getMessage(), LocationDAO.CLASS_NAME_LOCATION), e);
    }

    return locations;
}

From source file:org.geolatte.common.cql.hibernate.HibernateCriteriaBuilder.java

License:Open Source License

@Override
public void outANotExpr(ANotExpr node) {

    translatedExpressions.put(node, Restrictions.not(translatedExpressions.get(node.getExpr())));
}

From source file:org.geolatte.common.cql.hibernate.HibernateCriteriaBuilder.java

License:Open Source License

@Override
public void outANotLikeExpr(ANotLikeExpr node) {

    String propertyAlias = createAlias(node.getLeft());
    EscapingLikeExpression likeExpression = new EscapingLikeExpression(propertyAlias,
            translatedLiterals.get(node.getRight()).toString());
    translatedExpressions.put(node, Restrictions.not(likeExpression));
}

From source file:org.geolatte.common.cql.hibernate.HibernateCriteriaBuilder.java

License:Open Source License

@Override
public void outANotIlikeExpr(ANotIlikeExpr node) {

    String propertyAlias = createAlias(node.getLeft());
    EscapingLikeExpression likeExpression = new EscapingLikeExpression(propertyAlias,
            translatedLiterals.get(node.getRight()).toString(), true);
    translatedExpressions.put(node, Restrictions.not(likeExpression));
}

From source file:org.geomajas.layer.hibernate.CriteriaVisitor.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from w w w  .  j  a v  a 2s .  c  o  m*/
public Object visit(Not filter, Object userData) {
    Criterion c = (Criterion) filter.getFilter().accept(this, userData);
    return Restrictions.not(c);
}

From source file:org.geomajas.layer.hibernate.CriteriaVisitor.java

License:Open Source License

/** {@inheritDoc} */
@Override
public Object visit(ExcludeFilter filter, Object userData) {
    return Restrictions.not(Restrictions.conjunction());
}

From source file:org.geoserver.taskmanager.data.impl.TaskManagerDaoImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from www.  ja v  a 2  s .  c om
public List<Batch> getBatches(boolean hideSpecial) {
    Criteria criteria = getSession().createCriteria(BatchImpl.class)
            .createAlias("configuration", "configuration", CriteriaSpecification.LEFT_JOIN)
            .add(Restrictions.eq("removeStamp", 0L))
            .add(Restrictions.or(Restrictions.isNull("configuration"),
                    Restrictions.and(Restrictions.eq("configuration.removeStamp", 0L),
                            Restrictions.eq("configuration.validated", true))));
    if (hideSpecial) {
        criteria.add(Restrictions.or(Restrictions.isNull("configuration"),
                Restrictions.not(Restrictions.like("name", "@%"))));
    }
    return criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
}