List of usage examples for org.hibernate.criterion Restrictions sizeEq
public static Criterion sizeEq(String propertyName, int size)
From source file:org.openbravo.costing.LCMatchingProcess.java
License:Open Source License
private void doChecks(LandedCostCost lcCost, JSONObject message) { // Check there are Matching Lines. OBCriteria<LandedCostCost> critLCMatched = OBDal.getInstance().createCriteria(LandedCostCost.class); critLCMatched.add(Restrictions.sizeEq(LandedCostCost.PROPERTY_LANDEDCOSTMATCHEDLIST, 0)); critLCMatched.add(Restrictions.eq(LandedCostCost.PROPERTY_ID, lcCost.getId())); if (critLCMatched.uniqueResult() != null) { throw new OBException(OBMessageUtils.messageBD("LCCostNoMatchings")); }//from ww w. j a v a 2s . co m // Execute checks added implementing LandedCostProcessCheck interface. for (LCMatchingProcessCheck checksInstance : LCMatchingProcessChecks) { checksInstance.doCheck(lcCost, message); } }
From source file:ubic.gemma.persistence.service.expression.bioAssayData.BioAssayDimensionDaoImpl.java
License:Apache License
@Override public BioAssayDimension find(BioAssayDimension bioAssayDimension) { if (bioAssayDimension.getBioAssays().isEmpty()) { throw new IllegalArgumentException("BioAssayDimension had no BioAssays"); }/*from w ww .j ava 2s .c o m*/ Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(BioAssayDimension.class); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); if (StringUtils.isNotBlank(bioAssayDimension.getName())) { queryObject.add(Restrictions.eq("name", bioAssayDimension.getName())); } if (StringUtils.isNotBlank(bioAssayDimension.getDescription())) { queryObject.add(Restrictions.eq("description", bioAssayDimension.getDescription())); } queryObject.add(Restrictions.sizeEq("bioAssays", bioAssayDimension.getBioAssays().size())); Collection<String> names = new HashSet<>(); for (BioAssay bioAssay : bioAssayDimension.getBioAssays()) { names.add(bioAssay.getName()); } queryObject.createCriteria("bioAssays").add(Restrictions.in("name", names)); BioAssayDimension candidate = (BioAssayDimension) queryObject.uniqueResult(); if (candidate == null) return null; // Now check that the bioassays and order are exactly the same. Collection<BioAssay> desiredBioAssays = bioAssayDimension.getBioAssays(); Collection<BioAssay> candidateBioAssays = candidate.getBioAssays(); assert desiredBioAssays.size() == candidateBioAssays.size(); Iterator<BioAssay> dit = desiredBioAssays.iterator(); Iterator<BioAssay> cit = candidateBioAssays.iterator(); while (dit.hasNext()) { BioAssay d = dit.next(); BioAssay c = cit.next(); if (!c.equals(d)) return null; } return candidate; }
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 w w w . ja va 2 s . c o m*/ * 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); }
From source file:ubic.gemma.persistence.util.BusinessKey.java
License:Apache License
public static void createQueryObject(Criteria queryObject, ExpressionExperimentSubSet entity) { /*//from w w w . j a v a2 s . c o m * Note that we don't match on name. */ queryObject.add(Restrictions.eq("sourceExperiment", entity.getSourceExperiment())); queryObject.add(Restrictions.sizeEq("bioAssays", entity.getBioAssays().size())); queryObject.createCriteria("bioAssays") .add(Restrictions.in("id", EntityUtils.getIds(entity.getBioAssays()))); }