List of usage examples for org.hibernate.criterion Restrictions conjunction
public static Conjunction conjunction()
From source file:org.unitime.timetable.model.Staff.java
License:Open Source License
/** * Search staff list for instructors with matching names * @param fname First Name /* w w w .jav a 2 s .c o m*/ * @param lname Last Name * @return */ public static List findMatchingName(String fname, String lname) { List list = null; if ((fname == null || fname.trim().length() == 0) && (lname == null || lname.trim().length() == 0)) return list; Conjunction and = Restrictions.conjunction(); if (fname != null && fname.trim().length() > 0) and.add(Restrictions.ilike("firstName", fname, MatchMode.START)); if (lname != null && lname.trim().length() > 0) and.add(Restrictions.ilike("lastName", lname, MatchMode.START)); StaffDAO sdao = new StaffDAO(); list = sdao.getSession().createCriteria(Staff.class).add(and).list(); Collections.sort(list); return list; }
From source file:ubc.pavlab.aspiredb.server.dao.CriteriaBuilder.java
License:Apache License
private static Criterion createCharacteristicCriterion(CharacteristicProperty property, Operator operator, TextValue value, EntityType target) { DetachedCriteria subquery = DetachedCriteria.forClass(target.clazz); addCharacteristicAlias(subquery, target); Junction conjunction = Restrictions.conjunction() .add(Restrictions.eq("characteristic.key", property.getName())); switch (operator) { case TEXT_EQUAL: case TEXT_NOT_EQUAL: conjunction.add(createTextCriterion(operator, "characteristic.value", value.toString())); break;//from w w w . j a v a2 s.c o m case NUMERIC_EQUAL: case NUMERIC_GREATER: case NUMERIC_LESS: case NUMERIC_NOT_EQUAL: NumericValue numValue = new NumericValue(Integer.valueOf(value.getValue())); conjunction.add(createNumericalCriterion(operator, "characteristic.value", numValue)); break; default: throw new IllegalArgumentException("Operator type not supported."); } subquery.add(conjunction); subquery.setProjection(Projections.distinct(Projections.id())); return Subqueries.propertyIn("id", subquery); }
From source file:ubc.pavlab.aspiredb.server.dao.CriteriaBuilder.java
License:Apache License
/** * @param range//from w ww . j a va2 s . c o m * @return */ private static Criterion overlapsGenomicRegionCriterion(GenomicRange range) { List<Integer> bins = GenomeBin.relevantBins(range.getChromosome(), range.getBaseStart(), range.getBaseEnd()); // debug code - generates native SQL to check things relating to a test // System.err.println( range + " " + " length=" + ( range.getBaseEnd() - range.getBaseStart() ) + " bins=" // + StringUtils.join( bins, "," ) ); // if ( range.getChromosome().equals( "17" ) ) { // System.err.println( range // + " >> " // + String.format( "select distinct location1_.* from GENOMIC_LOC location1_ where " // + "location1_.BIN in (%s) and " + "( (location1_.START>=%d and location1_.END<=%d) " // + "or (location1_.START<=%d and location1_.END>=%d) " // + "or (location1_.START<=%d and location1_.END>=%d) ); ", StringUtils.join( bins, "," ), // range.getBaseStart(), range.getBaseEnd(), range.getBaseStart(), range.getBaseStart(), // range.getBaseEnd(), range.getBaseEnd() ) ); // } Junction variantInsideRegion = Restrictions.conjunction() .add(Restrictions.ge("location.start", range.getBaseStart())) .add(Restrictions.le("location.end", range.getBaseEnd())); Junction variantHitsStartOfRegion = Restrictions.conjunction() .add(Restrictions.le("location.start", range.getBaseStart())) .add(Restrictions.ge("location.end", range.getBaseStart())); Junction variantHitsEndOfRegion = Restrictions.conjunction() .add(Restrictions.le("location.start", range.getBaseEnd())) .add(Restrictions.ge("location.end", range.getBaseEnd())); // Note addition of bin restriction. We only care about variants that fall into one of the bins touched by the // given range Criterion rangeCriterion = Restrictions.conjunction().add(Restrictions.in("location.bin", bins)) // the same bin may exist in different chromosomes .add(Restrictions.eq("location.chromosome", range.getChromosome())).add(Restrictions.disjunction() .add(variantInsideRegion).add(variantHitsStartOfRegion).add(variantHitsEndOfRegion)); log.debug("RangeCriterion=" + rangeCriterion); return rangeCriterion; }
From source file:ubc.pavlab.aspiredb.server.dao.CriteriaBuilder.java
License:Apache License
private static Criterion processRestrictionExpression(Conjunction conjunction, EntityType target) { Junction criteriaConjunction = Restrictions.conjunction(); for (RestrictionExpression restriction : conjunction.getRestrictions()) { criteriaConjunction.add(buildCriteriaRestriction(restriction, target)); }/*from w w w .j a v a2s. com*/ return criteriaConjunction; }
From source file:ubc.pavlab.aspiredb.server.dao.CriteriaBuilder.java
License:Apache License
private static Criterion processRestrictionExpression(PhenotypeRestriction restriction, EntityType target) { DetachedCriteria subquery = DetachedCriteria.forClass(target.clazz); addPhenotypeAlias(subquery, target); subquery.add(Restrictions.conjunction().add(Restrictions.eq("phenotype.name", restriction.getName())) .add(Restrictions.eq("phenotype.value", restriction.getValue()))); subquery.setProjection(Projections.distinct(Projections.id())); return Subqueries.propertyIn("id", subquery); }
From source file:ubic.gemma.persistence.util.BusinessKey.java
License:Apache License
public static void createQueryObject(Criteria queryObject, FactorValue factorValue) { ExperimentalFactor ef = factorValue.getExperimentalFactor(); if (ef == null) throw new IllegalArgumentException("Must have experimentalfactor on factorvalue to search"); Criteria innerQuery = queryObject.createCriteria("experimentalFactor"); BusinessKey.addRestrictions(innerQuery, ef); if (factorValue.getValue() != null) { queryObject.add(Restrictions.eq("value", factorValue.getValue())); } else if (factorValue.getCharacteristics().size() > 0) { /*/*from ww w. j av a 2s. c om*/ * All the characteristics have to match ones in the result, and the result cannot have any extras. In other * words there has to be a one-to-one match between the characteristics. */ // this takes care of the size check queryObject.add(Restrictions.sizeEq("characteristics", factorValue.getCharacteristics().size())); // now the equivalence. Criteria characteristicsCriteria = queryObject.createCriteria("characteristics"); /* * Note that this isn't exactly correct, but it should work okay: "If all the characteristics in the * candidate are also in the query", along with the size restriction. The only problem would be if the same * characteristic were added to an object more than once - so the sizes would be the same, but a * characteristic in the query might not show up in the candidate. Multiple entries of the same * characteristic shouldn't be allowed, and even if it did happen the chance of a problem is small.... but a * formal possibility. */ Disjunction vdj = Restrictions.disjunction(); for (Characteristic characteristic : factorValue.getCharacteristics()) { Conjunction c = Restrictions.conjunction(); if (StringUtils.isNotBlank(characteristic.getCategoryUri())) { c.add(Restrictions.eq("categoryUri", characteristic.getCategoryUri())); } if (StringUtils.isNotBlank(characteristic.getValueUri())) { c.add(Restrictions.eq("valueUri", characteristic.getValueUri())); } if (StringUtils.isNotBlank(characteristic.getValue())) c.add(Restrictions.eq("value", characteristic.getValue())); if (StringUtils.isNotBlank(characteristic.getCategory())) c.add(Restrictions.eq("category", characteristic.getCategory())); vdj.add(c); } characteristicsCriteria.add(vdj); } else if (factorValue.getMeasurement() != null) { queryObject.add(Restrictions.eq("measurement", factorValue.getMeasurement())); } queryObject.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); }