List of usage examples for org.hibernate.criterion Restrictions or
public static LogicalExpression or(Criterion lhs, Criterion rhs)
From source file:de.iteratec.iteraplan.businesslogic.service.UserEntityServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ public List<UserEntity> getUserEntityBySearch(UserEntity userEntity) { //FIXME push this down to DAO and additionally escape T-SQL control characters DetachedCriteria crit = DetachedCriteria.forClass(UserEntity.class); if (userEntity != null && !StringUtils.isEmpty(userEntity.getIdentityString())) { String sqlSearchTerm = SqlHqlStringUtils.processGuiFilterForSql(userEntity.getIdentityString()); crit.add(Restrictions.or(new IteraplanLikeExpression("name", sqlSearchTerm, true), new IteraplanLikeExpression("loginName", sqlSearchTerm, true))); }/*from w w w . jav a 2 s . co m*/ // don't add order constraint to count criteria! crit.addOrder(Order.asc("loginName")); crit.addOrder(Order.asc("name")); return this.userEntityDAO.findByCriteria(crit); }
From source file:de.iteratec.iteraplan.persistence.dao.CheckBuildingBlocksWithNoAssociationsHelper.java
License:Open Source License
/** * Helper method to add restrictions imposing that all associations of a building block either do * not exist (null) or are empty./* w w w.ja v a 2 s .c o m*/ * * @param c * the Criteria object * @param alias * the alias of the building block * @param associations * the set of associations * @param properties * the set of properties */ public static void addRestrictionForAssociations(Criteria c, String alias, String[] associations, String[] properties) { for (String association : Arrays.asList(associations)) { //path to retrieve associated element String associationPath = alias + "." + association; //add restriction of this specific association c.add(Restrictions.or(Restrictions.isNull(associationPath), Restrictions.isEmpty(associationPath))); //mind that several c.add() produced from this iteration are implicitly combined by a logical AND } for (String property : properties) { //add restriction of this specific property c.add(Restrictions.or(Restrictions.isNull(property), Restrictions.isEmpty(property))); } }
From source file:de.sub.goobi.forms.StatistikForm.java
License:Open Source License
@SuppressWarnings("unchecked") private int getAnzahlAktuelleSchritte(boolean inOffen, boolean inBearbeitet) { /* aktuellen Benutzer ermitteln */ LoginForm login = (LoginForm) Helper.getManagedBeanValue("#{LoginForm}"); if (login.getMyBenutzer() == null) { return 0; }// www . jav a 2 s . co m try { Session session = Helper.getHibernateSession(); Criteria crit = session.createCriteria(Task.class); /* Liste der IDs */ List<Integer> trefferListe = new ArrayList<Integer>(); /* * die Treffer der Benutzergruppen */ Criteria critGruppen = session.createCriteria(Task.class); if (!inOffen && !inBearbeitet) { critGruppen.add(Restrictions.or(Restrictions.eq("processingStatus", Integer.valueOf(1)), Restrictions.like("processingStatus", Integer.valueOf(2)))); } if (inOffen) { critGruppen.add(Restrictions.eq("processingStatus", Integer.valueOf(1))); } if (inBearbeitet) { critGruppen.add(Restrictions.eq("processingStatus", Integer.valueOf(2))); } /* nur Prozesse, die keine Vorlagen sind */ critGruppen.createCriteria("process", "proz"); critGruppen.add(Restrictions.eq("proz.template", Boolean.FALSE)); /* * nur Schritte, wo Benutzergruppen des aktuellen Benutzers * eingetragen sind */ critGruppen.createCriteria("userGroups", "gruppen").createCriteria("users", "gruppennutzer"); critGruppen.add(Restrictions.eq("gruppennutzer.id", login.getMyBenutzer().getId())); /* die Treffer sammeln */ for (Iterator<Task> iter = critGruppen.list().iterator(); iter.hasNext();) { Task step = iter.next(); trefferListe.add(step.getId()); } /* * Treffer der Benutzer */ Criteria critBenutzer = session.createCriteria(Task.class); if (!inOffen && !inBearbeitet) { critBenutzer.add(Restrictions.or(Restrictions.eq("processingStatus", Integer.valueOf(1)), Restrictions.like("processingStatus", Integer.valueOf(2)))); } if (inOffen) { critBenutzer.add(Restrictions.eq("processingStatus", Integer.valueOf(1))); } if (inBearbeitet) { critBenutzer.add(Restrictions.eq("processingStatus", Integer.valueOf(2))); } /* nur Prozesse, die keine Vorlagen sind */ critBenutzer.createCriteria("process", "proz"); critBenutzer.add(Restrictions.eq("proz.template", Boolean.FALSE)); /* nur Schritte, wo der aktuelle Benutzer eingetragen ist */ critBenutzer.createCriteria("user", "nutzer"); critBenutzer.add(Restrictions.eq("nutzer.id", login.getMyBenutzer().getId())); /* die Treffer sammeln */ for (Iterator<Task> iter = critBenutzer.list().iterator(); iter.hasNext();) { Task step = iter.next(); trefferListe.add(step.getId()); } /* * nun nur die Treffer bernehmen, die in der Liste sind */ crit.add(Restrictions.in("id", trefferListe)); return crit.list().size(); } catch (HibernateException he) { Helper.setFehlerMeldung("fehlerBeimEinlesen", he.getMessage()); return 0; } }
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.ParticipationDAO.java
License:Open Source License
@Override public List<Participation> getMarkersAvailableParticipations(Group group) { if (group.getTutors().size() > 0) { Integer[] ids = new Integer[group.getTutors().size()]; int i = 0; for (Participation participation : group.getTutors()) { ids[i++] = participation.getId(); }// ww w . ja v a2 s. c om return getSession().createCriteria(Participation.class) .add(Restrictions.eq("lecture", group.getLecture())) .add(Restrictions.or(Restrictions.eq("role", ParticipationRole.TUTOR.toString()), Restrictions.eq("role", ParticipationRole.ADVISOR.toString()))) .add(Restrictions.not(Restrictions.in("id", ids))).createCriteria("user") .addOrder(Order.asc("lastName")).addOrder(Order.asc("firstName")).list(); } else { return getSession().createCriteria(Participation.class) .add(Restrictions.eq("lecture", group.getLecture())) .add(Restrictions.or(Restrictions.eq("role", ParticipationRole.TUTOR.toString()), Restrictions.eq("role", ParticipationRole.ADVISOR.toString()))) .createCriteria("user").addOrder(Order.asc("lastName")).addOrder(Order.asc("firstName")).list(); } }
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.SimilarityDAO.java
License:Open Source License
@Override public void addSimilarityResult(SimilarityTest similarityTest, Submission submissionOne, Submission submissionTwo, int percentage) { // TODO: check in plaggie that only submissiondirectories are considered if (submissionOne != null && submissionTwo != null) { Session session = getSession();// w w w. java 2 s .com Transaction tx = session.beginTransaction(); for (Similarity similarity : (List<Similarity>) session.createCriteria(Similarity.class) .add(Restrictions.eq("similarityTest", similarityTest)) .add(Restrictions.or( Restrictions.and(Restrictions.eq("submissionOne", submissionOne), Restrictions.eq("submissionTwo", submissionTwo)), Restrictions.and(Restrictions.eq("submissionOne", submissionTwo), Restrictions.eq("submissionTwo", submissionOne)))) .list()) { session.delete(similarity); } Similarity simularity; simularity = new Similarity(similarityTest, submissionOne, submissionTwo, percentage); session.save(simularity); simularity = new Similarity(similarityTest, submissionTwo, submissionOne, percentage); session.save(simularity); tx.commit(); } }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * This method retrieves all {@link SenseAxis} which bind the specified {@link Sense}. * * @param sense//from ww w . j a v a 2 s.com * all returned sense axes should bind this sense * * @return all sense axes (sense alignments) that contain the consumed sense.<br> * This method returns an empty list if the accessed UBY-LMF database does not contain * any alignments of the specified sense, or the specified sense is null. */ public List<SenseAxis> getSenseAxesBySense(Sense sense) { if (sense != null && sense.getId() != null && !sense.getId().equals("")) { Criteria criteria = session.createCriteria(SenseAxis.class); criteria = criteria .add(Restrictions.or(Restrictions.eq("senseOne", sense), Restrictions.eq("senseTwo", sense))); @SuppressWarnings("unchecked") List<SenseAxis> result = criteria.list(); return result; } else { return new ArrayList<SenseAxis>(0); } }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * This method retrieves all {@link PredicateArgumentAxis} which bind the specified {@link SemanticPredicate}. * * @param predicate/*w w w . j av a2s. com*/ * all returned predicate-argument axes should bind this semantic predicate * * @return all predicate-argument axes that contain the consumed semantic predicate.<br> * This method returns an empty list if the accessed UBY-LMF database does not contain * any alignments of the specified semantic predicate, or the specified semantic predicate is null. */ public List<PredicateArgumentAxis> getPredicateArgumentAxesByPredicate(SemanticPredicate predicate) { if (predicate != null && predicate.getId() != null && !predicate.getId().equals("")) { Criteria criteria = session.createCriteria(PredicateArgumentAxis.class); criteria = criteria.add(Restrictions.or(Restrictions.eq("semanticPredicateOne", predicate), Restrictions.eq("semanticPredicateTwo", predicate))); @SuppressWarnings("unchecked") List<PredicateArgumentAxis> result = criteria.list(); return result; } else { return new ArrayList<PredicateArgumentAxis>(0); } }
From source file:edu.duke.cabig.c3pr.dao.ParticipantDao.java
License:BSD License
/** * Searches based on an example object. Typical usage from your service class: - If you want * to search based on diseaseCode, monitorCode, * <li><code>Participant participant = new Participant();</li></code> * <li>code>participant.setLastName("last_namee");</li> * </code>/*from w w w .j av a2 s . c o m*/ * <li>code>participantDao.searchByExample(study)</li> * </code> * * @param participant the participant * @param isWildCard the is wild card * @param useAddress if set to true and {@link Address} is present, use it for the search. * @param useContactInfo if set to true and {@link ContactMechanism} is present, use it for the search. * @return list of matching participant objects based on your sample participant object */ public List<Participant> searchByExample(Participant participant, boolean isWildCard, boolean useAddress, boolean useContactInfo, boolean forceEager) { Example example = Example.create(participant).excludeZeroes().ignoreCase(); Criteria participantCriteria = getSession().createCriteria(Participant.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); example.excludeProperty("doNotUse").enableLike(MatchMode.ANYWHERE); if (forceEager) { // TODO: The following lines may cause Participant.identifiers to contain duplicate entries! // In order to avoid that, Participant.identifiers will need to be changed from List to Set. // Related to http://www.jroller.com/eyallupu/entry/hibernate_exception_simultaneously_fetch_multiple. participantCriteria.setFetchMode("identifiers", FetchMode.JOIN); participantCriteria.setFetchMode("raceCodeAssociations", FetchMode.JOIN); participantCriteria.setFetchMode("contactMechanisms", FetchMode.JOIN); } if (isWildCard) { participantCriteria.add(example); if (participant.getIdentifiers().size() > 0) { Criterion identifierValueCriterion = Restrictions.ilike("value", "%" + participant.getIdentifiers().get(0).getValue() + "%"); Criterion identifierTypeCriterion = Restrictions.ilike("typeInternal", "%" + participant.getIdentifiers().get(0).getTypeInternal() + "%"); if (participant.getIdentifiers().get(0) instanceof SystemAssignedIdentifier) { Criterion identifierSourceCriterion = Restrictions.ilike("systemName", "%" + ((SystemAssignedIdentifier) participant.getIdentifiers().get(0)).getSystemName() + "%"); participantCriteria.createCriteria("identifiers").add(identifierValueCriterion) .add(identifierSourceCriterion).add(identifierTypeCriterion); } else { Criteria identifiersCriteria = participantCriteria.createCriteria("identifiers"); identifiersCriteria.add(identifierValueCriterion).add(identifierTypeCriterion); if (((OrganizationAssignedIdentifier) participant.getIdentifiers().get(0)).getHealthcareSite() .getIdentifiersAssignedToOrganization().size() > 0) { Criteria organizationCriteria = identifiersCriteria.createCriteria("healthcareSite"); organizationCriteria.createCriteria("identifiersAssignedToOrganization") .add(Restrictions.ilike("value", "%" + ((OrganizationAssignedIdentifier) participant.getIdentifiers().get(0)) .getHealthcareSite().getIdentifiersAssignedToOrganization().get(0) .getValue() + "%")); } } for (int i = 1; i < participant.getIdentifiers().size(); i++) { identifierValueCriterion = Restrictions.or(identifierValueCriterion, Restrictions.ilike("value", "%" + participant.getIdentifiers().get(i).getValue() + "%")); } } final Address address = participant.getAddressInternal(); if (useAddress && address != null) { final Criteria addrCrit = participantCriteria.createCriteria("addresses"); if (StringUtils.isNotBlank(address.getStreetAddress())) addrCrit.add(Restrictions.ilike("streetAddress", "%" + address.getStreetAddress() + "%")); if (StringUtils.isNotBlank(address.getCity())) addrCrit.add(Restrictions.ilike("city", "%" + address.getCity() + "%")); if (StringUtils.isNotBlank(address.getStateCode())) addrCrit.add(Restrictions.ilike("stateCode", "%" + address.getStateCode() + "%")); if (StringUtils.isNotBlank(address.getCountryCode())) addrCrit.add(Restrictions.ilike("countryCode", "%" + address.getCountryCode() + "%")); if (StringUtils.isNotBlank(address.getPostalCode())) addrCrit.add(Restrictions.ilike("postalCode", "%" + address.getPostalCode() + "%")); } if (useContactInfo) { List<Criterion> criterions = new ArrayList<Criterion>(); if (StringUtils.isNotBlank(participant.getEmail())) { criterions.add( Example.create(new ContactMechanism(ContactMechanismType.EMAIL, participant.getEmail())) .enableLike().ignoreCase()); } if (StringUtils.isNotBlank(participant.getPhone())) { criterions.add( Example.create(new ContactMechanism(ContactMechanismType.PHONE, participant.getPhone())) .enableLike().ignoreCase()); } if (StringUtils.isNotBlank(participant.getFax())) { criterions.add( Example.create(new ContactMechanism(ContactMechanismType.Fax, participant.getFax())) .enableLike().ignoreCase()); } if (!criterions.isEmpty()) { Disjunction disjunction = Restrictions.disjunction(); for (Criterion criterion : criterions) { disjunction.add(criterion); } final Criteria contactCrit = participantCriteria.createCriteria("contactMechanisms"); contactCrit.add(disjunction); } } return participantCriteria.list(); } return participantCriteria.add(example).list(); }
From source file:edu.ku.brc.specify.dbsupport.customqueries.CustomStatQueries.java
License:Open Source License
protected boolean overdueLoans() { //String sql = "select loanId from Loan where (not (currentDueDate is null)) and (IsClosed = false or IsClosed is null) and datediff(CURDATE(), currentduedate) > 0; //select count(loanid) as OpenLoanCount from loan where loanid in (select loanid from loan where (not (currentduedate is null)) and loan.IsGift = false and (IsClosed = false or IsClosed is null) and datediff(CURDATE(), currentduedate) > 0) Session session = HibernateUtil.getNewSession(); Calendar today = Calendar.getInstance(); Criteria criteria = session.createCriteria(Loan.class); criteria.add(Restrictions.isNotNull("currentDueDate")); criteria.add(Restrictions.lt("currentDueDate", today)); criteria.add(Restrictions.or(Restrictions.isNull("isClosed"), Restrictions.eq("isClosed", false))); Criteria dsp = criteria.createCriteria("discipline"); dsp.add(Restrictions.eq("disciplineId", AppContextMgr.getInstance().getClassObject(Discipline.class).getDisciplineId())); criteria.setProjection(Projections.rowCount()); resultsList = criteria.list();//from w w w .java 2s . c om /*for (Object data : resultsList) { System.out.println("overdueLoans "+data); }*/ session.close(); return true; }
From source file:edu.northwestern.bioinformatics.studycalendar.dao.ActivityDao.java
License:BSD License
protected Criteria getActivitiesBySearchTextCriteria(final String searchText, final ActivityType type, final Source source, Integer limit, Integer offset, ActivitySearchCriteria sort, String order) { Criteria criteria;//ww w. j a v a 2s. co m if (sort != null) { order = (order == null) ? "asc" : order; if (asList("asc", "desc").contains(order)) { criteria = sort.getHibernateCriteria(getSession(), order); } else { criteria = defaultCriteria(); } } else { criteria = defaultCriteria(); } if (searchText != null) { String like = new StringBuilder().append("%").append(searchText.toLowerCase()).append("%").toString(); criteria.add(Restrictions.or(Restrictions.ilike("name", like), Restrictions.ilike("code", like))); } if (type != null) { criteria.add(Restrictions.eq("type", type)); } if (source != null) { criteria.add(Restrictions.eq("source", source)); } if (limit != null) { criteria.setMaxResults(limit); } if (offset != null) { criteria.setFirstResult(offset); } return criteria; }