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:de.iteratec.iteraplan.businesslogic.reports.query.node.AbstractLeafNode.java

License:Open Source License

/**
 * Returns the {@link Criterion} for the specified {@code effectivePropertyName} and {@code comparator}.
 * //  w  ww .  ja  v a2  s. co  m
 * @param effectivePropertyName the property name path
 * @param comparator the comparator describing the compare operation
 * @param attrType string representation of the property's attribute type as in {@link BBAttribute#getTypeOfAttribute(String)} 
 * @return the newly created {@link Criterion} for the specified {@code comparator} or {@code null} if the 
 *    comparator is not supported
 */
protected Criterion getCriterionForComparator(String effectivePropertyName, Comparator comparator,
        String attrType) {
    Criterion criterion = null;
    switch (comparator) {
    case EQ:
        criterion = Restrictions.eq(effectivePropertyName, getProcessedPattern());
        break;
    case GEQ:
        criterion = Restrictions.ge(effectivePropertyName, getProcessedPattern());
        break;
    case LEQ:
        criterion = Restrictions.le(effectivePropertyName, getProcessedPattern());
        break;
    case GT:
        criterion = Restrictions.gt(effectivePropertyName, getProcessedPattern());
        break;
    case LT:
        criterion = Restrictions.lt(effectivePropertyName, getProcessedPattern());
        break;
    case LIKE:
        criterion = new IteraplanLikeExpression(effectivePropertyName, getProcessedPattern().toString(), true);
        break;
    case NOT_LIKE:
        criterion = Restrictions.not(
                new IteraplanLikeExpression(effectivePropertyName, getProcessedPattern().toString(), true));
        break;
    case IS:
        // see Type#getSpecialPropertyHQLStrings
        criterion = "null".equals(getPattern()) ? Restrictions.isNull(effectivePropertyName)
                : Restrictions.isNotNull(effectivePropertyName);
        break;
    case ANY_ASSIGNMENT:
        criterion = getAnyAssignmentCriterion(effectivePropertyName, attrType);
        break;
    case NO_ASSIGNMENT:
        criterion = getNoAssignmentCriterion(effectivePropertyName, attrType);
        break;
    case NEQ:
        criterion = Restrictions.ne(effectivePropertyName, getProcessedPattern());
        break;
    default:
        break;
    }

    return criterion;
}

From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.AbstractLeafNode.java

License:Open Source License

private Criterion getAnyAssignmentCriterion(String effectivePropertyName, String attrType) {
    Criterion criterion;//from  www. j a v  a2s.  c o m
    criterion = Restrictions.not(Restrictions.isNull(effectivePropertyName));
    if (!BBAttribute.FIXED_ATTRIBUTE_DATETYPE.equals(attrType)) {
        criterion = Restrictions.and(criterion,
                Restrictions.not(Restrictions.eq(effectivePropertyName, Constants.DB_NU1L)));
    }
    return criterion;
}

From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.SealLeafNode.java

License:Open Source License

/** {@inheritDoc} */
@Override/*w  w w  .j  a va  2s  .c  o  m*/
DetachedCriteria getWhereCriteria(DetachedCriteria criteria) {
    String effectivePropertyName = null;

    if (getExtensionSize() == 0) {
        effectivePropertyName = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), getPropertyName());
    } else {
        effectivePropertyName = String.format("%s.%s", getLeafTypeDBNameShortWithSuffix(), getPropertyName());
    }

    final String[] properties = StringUtils.split(getPropertyName(), '.');
    if (!getResultType().isSpecialProperty(getPropertyName()) && properties != null && properties.length > 1) {
        final String associationPath = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(),
                properties[0]);
        final String alias = String.format("%sAlias", properties[0]);
        criteria.createAlias(associationPath, alias);
        effectivePropertyName = String.format("%s.%s", alias, properties[1]);
    }

    SealState sealState = (SealState) getPattern();
    switch (sealState) {
    case VALID:
        Criterion validCriterion = getCriterionForComparator(effectivePropertyName, Comparator.EQ, null);
        Criterion notOutdatedCriterion = Restrictions.not(getOutdatedCriterion(effectivePropertyName));
        criteria.add(Restrictions.and(validCriterion, notOutdatedCriterion));
        break;
    case INVALID:
        criteria.add(getCriterionForComparator(effectivePropertyName, Comparator.EQ, null));
        break;
    case NOT_AVAILABLE:
        Criterion isNull = Restrictions.isNull(effectivePropertyName);
        Criterion eqCriterion = getCriterionForComparator(effectivePropertyName, Comparator.EQ, null);
        criteria.add(Restrictions.or(isNull, eqCriterion));
        break;
    case OUTDATED:
        criteria.add(getOutdatedCriterion(effectivePropertyName));
        break;
    default:
        throw new IllegalStateException("The seal state " + sealState + " is not supported!");
    }

    return criteria;
}

From source file:de.iteratec.iteraplan.persistence.util.CriteriaUtil.java

License:Open Source License

public static <T> Criterion createNotInRestrictions(String propName, final Iterable<T> elements) {
    final Iterable<List<T>> partitions = Iterables.partition(elements, Constants.DB_ORACLE_MAX_IN);
    final Disjunction disjunction = Restrictions.disjunction();
    for (List<T> partition : partitions) {
        disjunction.add(Restrictions.in(propName, partition));
    }/*from w w w.ja  v a2  s  .  c  o m*/

    return Restrictions.not(disjunction);
}

From source file:de.sub.goobi.forms.AktuelleSchritteForm.java

License:Open Source License

/**
 * Anzeige der Schritte./*from   w  ww . j a  va2  s .  c  o  m*/
 */
public String FilterAlleStart() {
    try {
        this.myFilteredDataSource = new UserDefinedStepFilter(true);

        this.myFilteredDataSource.getObservable().addObserver(new Helper().createObserver());
        ((UserDefinedStepFilter) this.myFilteredDataSource).setFilterModes(this.nurOffeneSchritte,
                this.nurEigeneSchritte);
        this.myFilteredDataSource.setFilter(this.filter);

        Criteria crit = this.myFilteredDataSource.getCriteria();
        if (!this.showAutomaticTasks) {
            crit.add(Restrictions.eq("typeAutomatic", false));
        }
        if (hideCorrectionTasks) {
            crit.add(Restrictions.not(Restrictions.eq("priority", 10)));
        }

        sortList(crit);
        this.page = new Page(crit, 0);
    } catch (HibernateException he) {
        Helper.setFehlerMeldung("error on reading database", he.getMessage());
        return "";
    }
    return "AktuelleSchritteAlle";
}

From source file:de.sub.goobi.forms.ProzessverwaltungForm.java

License:Open Source License

/**
 * Filter current processes.//w w  w . j  av  a2  s .com
 */
public String FilterAktuelleProzesse() {
    this.statisticsManager = null;
    this.myAnzahlList = null;

    try {
        this.myFilteredDataSource = new UserProcessesFilter(true);
        Criteria crit = this.myFilteredDataSource.getCriteria();
        if (!this.showClosedProcesses) {
            crit.add(Restrictions.not(Restrictions.eq("sortHelperStatus", "100000000")));
        }
        if (!this.showArchivedProjects) {
            crit.add(Restrictions.not(Restrictions.eq("proj.projectIsArchived", true)));
        }
        sortList(crit, false);
        this.page = new Page(crit, 0);

    } catch (HibernateException he) {
        Helper.setFehlerMeldung("ProzessverwaltungForm.FilterAktuelleProzesse", he);
        return "";
    }
    this.modusAnzeige = "aktuell";
    return "ProzessverwaltungAlle";
}

From source file:de.sub.goobi.forms.ProzessverwaltungForm.java

License:Open Source License

/**
 * Filter processes./*from   w  w  w .j av a2s . c o m*/
 */
public String FilterVorlagen() {
    this.statisticsManager = null;
    this.myAnzahlList = null;
    try {
        this.myFilteredDataSource = new UserTemplatesFilter(true);
        Criteria crit = this.myFilteredDataSource.getCriteria();
        if (!this.showArchivedProjects) {
            crit.add(Restrictions.not(Restrictions.eq("proj.projectIsArchived", true)));
        }
        sortList(crit, false);
        this.page = new Page(crit, 0);
    } catch (HibernateException he) {
        Helper.setFehlerMeldung("ProzessverwaltungForm.FilterVorlagen", he);
        return "";
    }
    this.modusAnzeige = "vorlagen";
    return "ProzessverwaltungAlle";
}

From source file:de.sub.goobi.forms.ProzessverwaltungForm.java

License:Open Source License

/**
 * Anzeige der Sammelbnde filtern./*  www. j av a 2s .  co m*/
 */
public String FilterAlleStart() {
    this.statisticsManager = null;
    this.myAnzahlList = null;
    /*
     * Filter fr die Auflistung anwenden
     */
    try {

        // ... Criteria will persist, because it gets passed on to the
        // PageObject
        // but in order to use the extended functions of the
        // UserDefinedFilter
        // for statistics, we will have to hold a reference to the instance
        // of UserDefinedFilter
        this.myFilteredDataSource = new UserDefinedFilter(this.filter);

        // set observable to replace helper.setMessage
        this.myFilteredDataSource.getObservable().addObserver(new Helper().createObserver());

        // // calling the criteria as the result of the filter
        Criteria crit = this.myFilteredDataSource.getCriteria();

        // first manipulation of the created criteria

        /* nur die Vorlagen oder alles */
        if (this.modusAnzeige.equals("vorlagen")) {
            crit.add(Restrictions.eq("template", Boolean.TRUE));
        } else {
            crit.add(Restrictions.eq("template", Boolean.FALSE));
        }
        /* alle Suchparameter miteinander kombinieren */
        if (!this.showClosedProcesses && !this.modusAnzeige.equals("vorlagen")) {
            crit.add(Restrictions.not(Restrictions.eq("sortHelperStatus", "100000000")));
        }

        if (!this.showArchivedProjects) {
            crit.createCriteria("project", "proj");
            crit.add(Restrictions.not(Restrictions.eq("proj.projectIsArchived", true)));
            sortList(crit, false);
        } else {
            /* noch sortieren */
            sortList(crit, true);
        }

        this.page = new Page(crit, 0);
    } catch (HibernateException he) {
        Helper.setFehlerMeldung("fehlerBeimEinlesen", he.getMessage());
        return "";
    } catch (NumberFormatException ne) {
        Helper.setFehlerMeldung("Falsche Suchparameter angegeben", ne.getMessage());
        return "";
    } catch (UnsupportedOperationException e) {
        logger.error(e);
    }

    return "ProzessverwaltungAlle";
}

From source file:de.sub.goobi.forms.SearchForm.java

License:Open Source License

/**
 * Initialise drop down list of projects.
 *//*from   w  w w.  j ava  2  s  .c  o m*/
protected void initProjects() {
    int restriction = ((LoginForm) Helper.getManagedBeanValue("#{LoginForm}")).getMaximaleBerechtigung();
    Session session = Helper.getHibernateSession();
    Criteria crit = session.createCriteria(Project.class);

    crit.addOrder(Order.asc("titel"));
    if (restriction > 2) {
        crit.add(Restrictions.not(Restrictions.eq("projectIsArchived", true)));
    }
    this.projects.add(Helper.getTranslation("notSelected"));

    try {
        @SuppressWarnings("unchecked")
        List<Project> projektList = crit.list();
        for (Project p : projektList) {
            this.projects.add(p.getTitle());
        }
    } catch (HibernateException hbe) {
        logger.warn("Catched HibernateException. List of projects could be empty!");
    }
}

From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.GroupDAO.java

License:Open Source License

@Override
public List<Group> getJoinAbleGroups(Lecture lecture, Group participationGroup) {
    if (participationGroup == null) {
        return getSession().createCriteria(Group.class).add(Restrictions.eq("lecture", lecture))
                .add(Restrictions.eq("allowStudentsToSignup", true))
                .add(Restrictions.sqlRestriction(
                        "(select count(*) from participations where groupid={alias}.gid) < this_.maxStudents"))
                .list();/*from ww  w  .j  a  v a  2  s . c  o m*/
    } else {
        return getSession().createCriteria(Group.class).add(Restrictions.eq("lecture", lecture))
                .add(Restrictions.eq("allowStudentsToSignup", true))
                .add(Restrictions.sqlRestriction(
                        "(select count(*) from participations where groupid={alias}.gid) < this_.maxStudents"))
                .add(Restrictions.not(Restrictions.eq("gid", participationGroup.getGid()))).list();
    }
}