List of usage examples for org.hibernate.criterion Restrictions disjunction
public static Disjunction disjunction()
From source file:eu.ist_phosphorus.harmony.idb.database.hibernate.Reservation.java
License:Open Source License
/** * load all reservations from DB which lie in a given time-period. *//*from w w w .j a v a 2 s.c om*/ @SuppressWarnings("unchecked") public static final Set<Reservation> loadAllInPeriod(Date startTime, Date endTime) throws DatabaseException { return (Set<Reservation>) (new TransactionManager(new Tuple<Date, Date>(startTime, endTime)) { @Override protected void dbOperation() { Set<Reservation> result = new HashSet<Reservation>(); Tuple<Date, Date> times = (Tuple<Date, Date>) this.arg; // select all reservation-IDs from ReservationPeriod-view, which // lie in the given time-period DetachedCriteria ids = DetachedCriteria.forClass(VIEW_ReservationPeriod.class) .setProjection(Property.forName("reservationId")) .add(Restrictions.disjunction() .add(Restrictions.between("startTime", times.getFirstElement(), times.getSecondElement())) .add(Restrictions.between("endTime", times.getFirstElement(), times.getSecondElement())) .add(Restrictions.and(Restrictions.le("startTime", times.getFirstElement()), Restrictions.ge("endTime", times.getSecondElement())))); // select all reservations from DB accoring to the IDs from step // one final List<Reservation> tmpReservation = this.session.createCriteria(Reservation.class) .add(Subqueries.propertyIn("reservationId", ids)) // use join-select, because all infos will be // needed later .setFetchMode("Reservation", FetchMode.JOIN).list(); for (Reservation r : tmpReservation) { result.add(r); } this.result = result; } }).getResult(); }
From source file:eu.jangos.realm.controller.characters.CharacterService.java
License:Apache License
/** * Indicates whether the account given in parameter has characters already * created in the opposite faction.//from ww w.j av a 2 s . c o m * * @param account The account for which it needs to be checked. * @param faction The faction for which this account is trying to create a * character. * @return True if the account has already created characters in the enemy * faction. */ private boolean hasCharacterInEnemyFaction(Account account, FactionEnum faction) { try (Session session = HibernateUtil.getCharSession().openSession()) { Disjunction or = Restrictions.disjunction(); for (RaceEnum race : FactionEnum.getRacesForFactions(faction)) { or.add(Restrictions.eq("race", race.getValue())); } return (((long) session.createCriteria(Characters.class) .add(Restrictions.and(Restrictions.isNull("deleted"), Restrictions.eq("fkAccount", account.getId()), or)) .setProjection(Projections.rowCount()).uniqueResult()) != 0); } catch (HibernateException he) { return false; } }
From source file:gov.nih.nci.caarray.dao.ArrayDaoImpl.java
License:BSD License
/** * {@inheritDoc}/* w w w. j a v a 2 s . c om*/ */ @Override @SuppressWarnings({ "unchecked", "PMD.ExcessiveMethodLength", "PMD.NPathComplexity" }) public List<QuantitationType> searchForQuantitationTypes(PageSortParams<QuantitationType> params, QuantitationTypeSearchCriteria criteria) { final Criteria c = getCurrentSession().createCriteria(HybridizationData.class); c.createCriteria("hybridization").add(Restrictions.eq("id", criteria.getHybridization().getId())); c.createCriteria("dataSet").createAlias("quantitationTypes", "qt").createAlias("arrayData", "ad"); c.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); if (!criteria.getArrayDataTypes().isEmpty()) { final List<Long> ids = new LinkedList<Long>(); for (final ArrayDataType type : criteria.getArrayDataTypes()) { ids.add(type.getId()); } c.createCriteria("ad.type").add(Restrictions.in("id", ids)); } if (!criteria.getFileTypes().isEmpty() || !criteria.getFileCategories().isEmpty()) { c.createAlias("ad.dataFile", "df"); } if (!criteria.getFileTypes().isEmpty()) { c.add(Restrictions.in("df.type", Sets.newHashSet(FileTypeRegistryImpl.namesForTypes(criteria.getFileTypes())))); } if (!criteria.getFileCategories().isEmpty()) { final Disjunction categoryCriterion = Restrictions.disjunction(); if (criteria.getFileCategories().contains(FileCategory.DERIVED_DATA)) { categoryCriterion.add(Restrictions.in("df.type", Sets.newHashSet( FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getDerivedArrayDataTypes())))); } if (criteria.getFileCategories().contains(FileCategory.RAW_DATA)) { categoryCriterion.add(Restrictions.in("df.type", Sets .newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getRawArrayDataTypes())))); } c.add(categoryCriterion); } c.setFirstResult(params.getIndex()); if (params.getPageSize() > 0) { c.setMaxResults(params.getPageSize()); } c.addOrder(toOrder(params, "qt")); final List<Map<String, Object>> results = c.list(); final List<QuantitationType> qTypes = SetUniqueList.decorate(new LinkedList<QuantitationType>()); for (final Map<String, Object> row : results) { final QuantitationType qt = (QuantitationType) row.get("qt"); qTypes.add(qt); } return qTypes; }
From source file:gov.nih.nci.caarray.dao.FileDaoImpl.java
License:BSD License
/** * {@inheritDoc}//from www .j a v a2 s .c o m */ @Override @SuppressWarnings({ "unchecked", "PMD" }) public List<CaArrayFile> searchFiles(PageSortParams<CaArrayFile> params, FileSearchCriteria criteria) { final Criteria c = getCurrentSession().createCriteria(CaArrayFile.class); if (criteria.getExperiment() != null) { c.add(Restrictions.eq("project", criteria.getExperiment().getProject())); } if (!criteria.getTypes().isEmpty()) { c.add(Restrictions.in("type", Sets.newHashSet(FileTypeRegistryImpl.namesForTypes(criteria.getTypes())))); } if (criteria.getExtension() != null) { String extension = criteria.getExtension(); if (!extension.startsWith(".")) { extension = "." + extension; } c.add(Restrictions.ilike("name", "%" + extension)); } if (!criteria.getCategories().isEmpty()) { final Disjunction categoryCriterion = Restrictions.disjunction(); if (criteria.getCategories().contains(FileCategory.DERIVED_DATA)) { categoryCriterion.add(Restrictions.in("type", Sets.newHashSet( FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getDerivedArrayDataTypes())))); } if (criteria.getCategories().contains(FileCategory.RAW_DATA)) { categoryCriterion.add(Restrictions.in("type", Sets .newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getRawArrayDataTypes())))); } if (criteria.getCategories().contains(FileCategory.MAGE_TAB)) { categoryCriterion.add(Restrictions.in("type", Sets.newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getMageTabTypes())))); } if (criteria.getCategories().contains(FileCategory.ARRAY_DESIGN)) { categoryCriterion.add(Restrictions.in("type", Sets .newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getArrayDesignTypes())))); } if (criteria.getCategories().contains(FileCategory.OTHER)) { categoryCriterion.add(Restrictions.isNull("type")); } c.add(categoryCriterion); } if (!criteria.getExperimentNodes().isEmpty()) { final Collection<Long> fileIds = new LinkedList<Long>(); for (final AbstractExperimentDesignNode node : criteria.getExperimentNodes()) { for (final CaArrayFile f : node.getAllDataFiles()) { fileIds.add(f.getId()); } } if (!fileIds.isEmpty()) { c.add(Restrictions.in("id", fileIds)); } else { return Collections.emptyList(); } } c.setFirstResult(params.getIndex()); if (params.getPageSize() > 0) { c.setMaxResults(params.getPageSize()); } c.addOrder(toOrder(params)); return c.list(); }
From source file:gov.nih.nci.cabig.ctms.tools.hibernate.MoreRestrictions.java
License:BSD License
public static Criterion in(String propertyName, Collection<?> values, int maxLength) { if (maxLength < 1) throw new IllegalArgumentException("maxLength must be positive"); Disjunction result = Restrictions.disjunction(); for (Collection<?> part : partitionCollection(values, maxLength)) { result.add(Restrictions.in(propertyName, part)); }//from ww w . ja v a 2s . co m return result; }
From source file:gov.nih.nci.cabio.annotations.ArrayAnnotationServiceImpl.java
License:BSD License
public Collection<SNP> getSnpsNearGene(String symbol, Long kbUpstream, Long kbDownstream, String assembly) throws ApplicationException { List params = new ArrayList(); params.add(assembly);/*from www .j a v a 2 s . c om*/ params.add(symbol); params.add(symbol); params.add(taxon); Collection<GenePhysicalLocation> result = appService.query(new HQLCriteria(GET_SNPS_NEAR_GENE_HQL, QueryUtils.createCountQuery(GET_SNPS_NEAR_GENE_HQL), params)); if (result == null || result.isEmpty()) throw new ApplicationException("No genes found for symbol " + symbol); Collection<GenomeRange> rawRanges = new TreeSet<GenomeRange>(); Long upPad = kbUpstream * 1000; Long downPad = kbDownstream * 1000; Long chromosomeId = null; // construct all padded ranges for (GenePhysicalLocation pl : result) { if (chromosomeId == null) chromosomeId = pl.getChromosome().getId(); rawRanges.add(new GenomeRange(pl.getChromosomalStartPosition() - upPad, pl.getChromosomalEndPosition() + downPad)); } // combine overlapping ranges Collection<GenomeRange> ranges = new ArrayList<GenomeRange>(); GenomeRange last = null; for (GenomeRange gr : rawRanges) { if ((last == null) || (last.getEnd() < gr.getStart() - 1)) { ranges.add(gr); last = gr; } else if (gr.getEnd() > last.getEnd()) { last.setEnd(gr.getEnd()); } } // query for SNPs on the given assembly in the combined ranges DetachedCriteria dc = DetachedCriteria.forClass(SNP.class).createCriteria("physicalLocationCollection") .add(Restrictions.eq("assembly", assembly)); Disjunction or = Restrictions.disjunction(); for (GenomeRange gr : ranges) { or.add(Restrictions.and(Restrictions.ge("chromosomalStartPosition", gr.getStart()), Restrictions.le("chromosomalEndPosition", gr.getEnd()))); } dc.add(or).addOrder(Order.asc("chromosomalStartPosition")) .add(Restrictions.sqlRestriction("{alias}.chromosome_id = ?", chromosomeId, Hibernate.LONG)); List<SNP> results = appService.query(dc); return results; }
From source file:gov.nih.nci.caintegrator.data.CaIntegrator2DaoImpl.java
License:BSD License
/** * {@inheritDoc}//w w w . j a va2 s. c om */ @Override @SuppressWarnings(UNCHECKED) // Hibernate operations are untyped public List<SegmentData> findMatchingSegmentDatasByLocation(List<SegmentData> segmentDatasToMatch, Study study, Platform platform) { Criteria segmentDataCrit = getCurrentSession().createCriteria(SegmentData.class); Criteria arrayDataCrit = segmentDataCrit.createCriteria("arrayData"); Criteria reporterListsCrit = arrayDataCrit.createCriteria("reporterLists"); reporterListsCrit.add(Restrictions.eq(PLATFORM_ASSOCIATION, platform)); arrayDataCrit.add(Restrictions.eq(STUDY_ASSOCIATION, study)); Junction overallOrStatement = Restrictions.disjunction(); for (SegmentData segmentData : segmentDatasToMatch) { ChromosomalLocation location = segmentData.getLocation(); overallOrStatement.add(Restrictions.conjunction() .add(Restrictions.eq("Location.startPosition", location.getStartPosition())) .add(Restrictions.eq("Location.endPosition", location.getEndPosition()))); } segmentDataCrit.add(overallOrStatement); return segmentDataCrit.list(); }
From source file:gov.nih.nci.caintegrator.data.CaIntegrator2DaoImpl.java
License:BSD License
/** * {@inheritDoc}/*from www . j av a 2s . c o m*/ */ @Override @SuppressWarnings(UNCHECKED) // Hibernate operations are untyped public List<Gene> findGenesByLocation(String chromosome, Integer startPosition, Integer endPosition, GenomeBuildVersionEnum genomeBuildVersion) { String locStartPosition = "location.startPosition"; String locEndPosition = "location.endPosition"; Criteria geneLocationCriteria = getCurrentSession().createCriteria(GeneChromosomalLocation.class); // (gene.startPos <= startPosition && gene.endPos >= startPosition) // || (gene.startPos >= lowerInput && gene.startPos <= higherInput) Junction overallOrStatement = Restrictions.disjunction(); overallOrStatement.add(Restrictions.conjunction().add(Restrictions.le(locStartPosition, startPosition)) .add(Restrictions.ge(locEndPosition, startPosition))); overallOrStatement.add(Restrictions.conjunction().add(Restrictions.ge(locStartPosition, startPosition)) .add(Restrictions.le(locStartPosition, endPosition))); geneLocationCriteria.add(overallOrStatement); geneLocationCriteria.add(getChromosomeRestriction(chromosome)); geneLocationCriteria.createCriteria("geneLocationConfiguration") .add(Restrictions.eq("genomeBuildVersion", genomeBuildVersion)); geneLocationCriteria.setProjection(Projections.property("geneSymbol")); List<String> geneSymbols = geneLocationCriteria.list(); return geneSymbols.isEmpty() ? new ArrayList<Gene>() : getCurrentSession().createCriteria(Gene.class) .setProjection(Projections.distinct(Projections.property(SYMBOL_ATTRIBUTE))) .add(Restrictions.in(SYMBOL_ATTRIBUTE, geneSymbols)).addOrder(Order.asc(SYMBOL_ATTRIBUTE)) .list(); }
From source file:gov.nih.nci.caintegrator.data.CopyNumberAlterationCriterionConverter.java
License:BSD License
private void addSegmentValueCriterion(Criteria segmentDataCrit) { // First case, if both are null. if (copyNumberCriterion.getUpperLimit() == null && copyNumberCriterion.getLowerLimit() == null) { return;/*w w w . ja va2 s .c o m*/ } SimpleExpression upperLimitExpression = Restrictions.le("segmentValue", copyNumberCriterion.getUpperLimit()); SimpleExpression lowerLimitExpression = Restrictions.ge("segmentValue", copyNumberCriterion.getLowerLimit()); // Second case, upper limit is higher than lower limit, value is in between the two if (copyNumberCriterion.isInsideBoundaryType()) { segmentDataCrit.add(Restrictions.conjunction().add(upperLimitExpression).add(lowerLimitExpression)); return; } // Third case, lower limit is higher than upper limit, value is outside of the limits if (copyNumberCriterion.isOutsideBoundaryType()) { segmentDataCrit.add(Restrictions.disjunction().add(upperLimitExpression).add(lowerLimitExpression)); return; } // Fourth case, upper limit has a value, lower limit is null. if (copyNumberCriterion.getUpperLimit() != null) { segmentDataCrit.add(upperLimitExpression); return; } // Fifth case, lower limit has a value, upper limit is null. if (copyNumberCriterion.getLowerLimit() != null) { segmentDataCrit.add(lowerLimitExpression); } }
From source file:gov.nih.nci.caintegrator.data.CopyNumberAlterationCriterionConverter.java
License:BSD License
private void addChromosomeCoordinatesToCriterion(Integer chromosomeCoordinateHigh, Integer chromosomeCoordinateLow, Criteria segmentDataCrit, String chromosomeNumber) { if (chromosomeCoordinateHigh == null || chromosomeCoordinateLow == null) { segmentDataCrit.add(chromosomeNumberExpression(chromosomeNumber)); if (chromosomeCoordinateHigh != null) { segmentDataCrit.add(segmentEndLessThanHigh(chromosomeCoordinateHigh)); }/*from w w w . jav a 2 s . c o m*/ if (chromosomeCoordinateLow != null) { segmentDataCrit.add(segmentStartGreaterThanLow(chromosomeCoordinateLow)); } } else { Junction overallOrStatement = Restrictions.disjunction(); // (loc.startPos <= lowerInput && loc.endPos >= lowerInput && loc.chromosome == chromosomeInput) // || (loc.startPos >= lowerInput && loc.startPos <= higherInput && loc.chromosome == chromosomeInput) overallOrStatement.add(Restrictions.conjunction().add(segmentStartLessThanLow(chromosomeCoordinateLow)) .add(segmentEndGreaterThanLow(chromosomeCoordinateLow)) .add(chromosomeNumberExpression(chromosomeNumber))); overallOrStatement .add(Restrictions.conjunction().add(segmentStartGreaterThanLow(chromosomeCoordinateLow)) .add(segmentStartLessThanHigh(chromosomeCoordinateHigh)) .add(chromosomeNumberExpression(chromosomeNumber))); segmentDataCrit.add(overallOrStatement); } }