List of usage examples for org.hibernate Query setFlushMode
@Override Query<R> setFlushMode(FlushModeType flushMode);
From source file:ubic.gemma.persistence.service.expression.bioAssayData.ProcessedExpressionDataVectorDaoImpl.java
License:Apache License
/** * @param limit if non-null and positive, you will get a random set of vectors for the experiment * @param ee ee/*from w w w . ja v a 2s .c o m*/ * @return processed data vectors */ private Collection<ProcessedExpressionDataVector> getProcessedVectors(ExpressionExperiment ee, Integer limit) { if (limit == null || limit < 0) { return this.getProcessedVectors(ee); } StopWatch timer = new StopWatch(); timer.start(); List<ProcessedExpressionDataVector> result; Integer availableVectorCount = ee.getNumberOfDataVectors(); if (availableVectorCount == null || availableVectorCount == 0) { AbstractDao.log.info("Experiment does not have vector count populated."); // cannot fix this here, because we're read-only. } Query q = this.getSessionFactory().getCurrentSession() .createQuery(" from ProcessedExpressionDataVector dedv where dedv.expressionExperiment.id = :ee"); q.setParameter("ee", ee.getId(), LongType.INSTANCE); q.setMaxResults(limit); if (availableVectorCount != null && availableVectorCount > limit) { q.setFirstResult(new Random().nextInt(availableVectorCount - limit)); } // we should already be read-only, so this is probably pointless. q.setReadOnly(true); // and so this probably doesn't do anything useful. q.setFlushMode(FlushMode.MANUAL); //noinspection unchecked result = q.list(); if (timer.getTime() > 1000) AbstractDao.log .info("Fetch " + limit + " vectors from " + ee.getShortName() + ": " + timer.getTime() + "ms"); if (result.isEmpty()) { AbstractDao.log.warn("Experiment does not have any processed data vectors"); return result; } this.thaw(result); // needed? return result; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param ees collection of expression experiments. * @param session session/* ww w . j a va 2 s. com*/ * @return map of array designs to the experiments they were used in. */ public static Map<ArrayDesign, Collection<Long>> getArrayDesignsUsed(Collection<Long> ees, Session session) { Map<ArrayDesign, Collection<Long>> eeAdMap = new HashMap<>(); // Safety 1st.... if (ees == null || ees.isEmpty()) return eeAdMap; final String eeAdQuery = "select distinct ee.id,ad from ExpressionExperiment as ee inner join " + "ee.bioAssays b inner join b.arrayDesignUsed ad fetch all properties where ee.id in (:ees)"; org.hibernate.Query queryObject = session.createQuery(eeAdQuery); queryObject.setParameterList("ees", ees); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); List<?> qr = queryObject.list(); for (Object o : qr) { Object[] ar = (Object[]) o; Long ee = (Long) ar[0]; ArrayDesign ad = (ArrayDesign) ar[1]; if (!eeAdMap.containsKey(ad)) { eeAdMap.put(ad, new HashSet<Long>()); } eeAdMap.get(ad).add(ee); } return eeAdMap; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param ees experiments//from ww w. j a va2s. co m * @param session session * @return map of experiment to collection of array design ids. If any of the ids given are for subsets, then the * key in the return value will be for the subset, not the source experiment (so it is consistent with the * input) */ public static Map<Long, Collection<Long>> getArrayDesignsUsedEEMap(Collection<Long> ees, Session session) { Map<Long, Collection<Long>> ee2ads = new HashMap<>(); if (ees == null || ees.isEmpty()) return ee2ads; final String eeAdQuery = "select distinct ee.id,ad.id from ExpressionExperiment as ee inner join " + "ee.bioAssays b inner join b.arrayDesignUsed ad where ee.id in (:ees)"; org.hibernate.Query queryObject = session.createQuery(eeAdQuery); queryObject.setParameterList("ees", ees); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); List<?> qr = queryObject.list(); ee2ads = CommonQueries.addAllAds(ee2ads, qr); if (ee2ads.size() < ees.size()) { // ids might be invalid, but also might be subsets. Note that the output key is for the subset, not the // source. String subsetQuery = "select distinct ees.id,ad.id from ExpressionExperimentSubSet as ees join ees.sourceExperiment ee " + " join ee.bioAssays b join b.arrayDesignUsed ad where ees.id in (:ees)"; //noinspection unchecked Collection<Long> possibleEEsubsets = ListUtils.removeAll(ees, ee2ads.keySet()); // note: CollectionUtils.removeAll has a bug. qr = session.createQuery(subsetQuery).setParameterList("ees", possibleEEsubsets).list(); ee2ads = CommonQueries.addAllAds(ee2ads, qr); } return ee2ads; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param session session//from ww w . ja v a 2 s . c o m * @param eeId experiment id * @return list of array designs IDs used in given expression experiment */ @SuppressWarnings("unchecked") public static Collection<Long> getArrayDesignIdsUsed(Long eeId, Session session) { final String eeAdQuery = "select distinct ad.id from ExpressionExperiment as ee inner join " + "ee.bioAssays b inner join b.arrayDesignUsed ad where ee.id = :eeId"; org.hibernate.Query queryObject = session.createQuery(eeAdQuery); queryObject.setCacheable(true); queryObject.setParameter("eeId", eeId); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); List<?> list = queryObject.list(); return (Collection<Long>) list; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * Given a gene, get all the composite sequences that map to it. * * @param session session/* ww w.jav a 2s . co m*/ * @param gene gene * @return composite sequences */ public static Collection<CompositeSequence> getCompositeSequences(Gene gene, Session session) { final String csQueryString = "select distinct cs from Gene as gene" + " join gene.products gp, BioSequence2GeneProduct ba, CompositeSequence cs " + " where ba.bioSequence.id=cs.biologicalCharacteristic.id and ba.geneProduct.id = gp.id and gene.id = :gene "; org.hibernate.Query queryObject = session.createQuery(csQueryString); queryObject.setParameter("gene", gene.getId(), LongType.INSTANCE); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); //noinspection unchecked return queryObject.list(); }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
private static Query createGetADsUsedQueryObject(Long eeId, Session session) { final String eeAdQuery = "select distinct ad from ExpressionExperiment as ee inner join " + "ee.bioAssays b inner join b.arrayDesignUsed ad inner join ad.primaryTaxon fetch all properties where ee.id = :eeId"; Query queryObject = session.createQuery(eeAdQuery); queryObject.setCacheable(true);//www . j av a 2s . c o m queryObject.setParameter("eeId", eeId); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); return queryObject; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
public static Map<CompositeSequence, Collection<Gene>> getCs2GeneMap(Collection<Gene> genes, Collection<ArrayDesign> arrayDesigns, Session session) { StopWatch timer = new StopWatch(); timer.start();/*from ww w .jav a 2 s .c om*/ final String csQueryString = "select distinct cs, gene from Gene as gene" + " inner join gene.products gp, BioSequence2GeneProduct ba, CompositeSequence cs " + " where ba.bioSequence=cs.biologicalCharacteristic and ba.geneProduct = gp" + " and gene in (:genes) and cs.arrayDesign in (:ads) "; Map<CompositeSequence, Collection<Gene>> cs2gene = new HashMap<>(); Query queryObject = session.createQuery(csQueryString); queryObject.setCacheable(true); queryObject.setParameterList("genes", genes); queryObject.setParameterList("ads", arrayDesigns); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); CommonQueries.addGenes(cs2gene, results); results.close(); if (timer.getTime() > 200) { CommonQueries.log.info("Get cs2gene for " + genes.size() + " :" + timer.getTime() + "ms"); } return cs2gene; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param genes genes//from w w w. j av a 2s.c o m * @param session session * @return map of probes to input genes they map to. Other genes those probes might detect are not included. */ public static Map<CompositeSequence, Collection<Gene>> getCs2GeneMap(Collection<Gene> genes, Session session) { StopWatch timer = new StopWatch(); timer.start(); final String csQueryString = "select distinct cs, gene from Gene as gene" + " inner join gene.products gp, BioSequence2GeneProduct ba, CompositeSequence cs " + " where ba.bioSequence=cs.biologicalCharacteristic and ba.geneProduct = gp" + " and gene in (:genes) "; Map<CompositeSequence, Collection<Gene>> cs2gene = new HashMap<>(); org.hibernate.Query queryObject = session.createQuery(csQueryString); queryObject.setCacheable(true); queryObject.setParameterList("genes", genes); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); CommonQueries.addGenes(cs2gene, results); results.close(); if (timer.getTime() > 200) { CommonQueries.log.info("Get cs2gene for " + genes.size() + " :" + timer.getTime() + "ms"); } return cs2gene; }