List of usage examples for org.hibernate FlushMode MANUAL
FlushMode MANUAL
To view the source code for org.hibernate FlushMode MANUAL.
Click Source Link
From source file:ubic.gemma.persistence.service.genome.taxon.TaxonDaoImpl.java
License:Apache License
@Override public Taxon find(Taxon taxon) { BusinessKey.checkValidKey(taxon);//from w w w .j ava2 s . c o m Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(Taxon.class) .setReadOnly(true); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); BusinessKey.addRestrictions(queryObject, taxon); List<?> results = queryObject.list(); Object result = null; if (results != null) { if (results.size() > 1) { throw new org.springframework.dao.InvalidDataAccessResourceUsageException( "More than one instance of '" + taxon.getClass().getName() + "' was found when executing query"); } else if (results.size() == 1) { result = results.iterator().next(); } } return (Taxon) result; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param ees collection of expression experiments. * @param session session/*from w w w . j a v a 2s. c om*/ * @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// ww w .j a va2 s . c o 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 w w w. j a v a 2 s .c om*/ * @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/*from w ww. j a v a 2s.c o 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);// ww w . j ava2 s .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
/** * @param session session/* w ww . j ava2s . co m*/ * @param genes genes * @param arrayDesigns array design * @return map of probe IDs to collections of gene IDs. */ public static Map<Long, Collection<Long>> getCs2GeneIdMap(Collection<Long> genes, Collection<Long> arrayDesigns, Session session) { Map<Long, Collection<Long>> cs2genes = new HashMap<>(); String queryString = "SELECT CS AS csid, GENE AS geneId FROM GENE2CS g WHERE g.GENE IN (:geneIds) AND g.AD IN (:ads)"; SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.addScalar("csid", LongType.INSTANCE); queryObject.addScalar("geneId", LongType.INSTANCE); queryObject.setParameterList("ads", arrayDesigns); queryObject.setParameterList("geneIds", genes); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); CommonQueries.addGeneIds(cs2genes, results); results.close(); return cs2genes; }
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 w w w . j a v a 2 s. c o m*/ 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 . ja v a 2s . c om * @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; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param session session/* www . j a v a 2s .c o m*/ * @param probes probes * @return map of probes to all the genes 'detected' by those probes. Probes that don't map to genes will have an * empty gene collection. */ public static Map<Long, Collection<Long>> getCs2GeneMapForProbes(Collection<Long> probes, Session session) { if (probes.isEmpty()) return new HashMap<>(); Map<Long, Collection<Long>> cs2genes = new HashMap<>(); String queryString = "SELECT CS AS csid, GENE AS geneId FROM GENE2CS g WHERE g.CS IN (:probes) "; org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.addScalar("csid", LongType.INSTANCE); queryObject.addScalar("geneId", LongType.INSTANCE); queryObject.setParameterList("probes", probes, LongType.INSTANCE); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); CommonQueries.addGeneIds(cs2genes, results); results.close(); return cs2genes; }