List of usage examples for org.hibernate SQLQuery scroll
ScrollableResults scroll(ScrollMode scrollMode);
From source file:ubic.gemma.persistence.service.association.phenotype.PhenotypeAssociationDaoImpl.java
License:Apache License
@Override public Set<Long> findPrivateEvidenceId(Long taxonId, Integer limit) { String limitAbs;//from w w w. j a v a2 s. com String orderBy; if (limit < 0) { limitAbs = "limit " + limit * -1; orderBy = "order by LAST_UPDATED asc "; } else { orderBy = "order by LAST_UPDATED desc "; limitAbs = "limit " + limit; } Set<Long> ids = new HashSet<>(); String sqlQuery = "select distinct phen.ID "; sqlQuery += this.getPhenotypesGenesAssociationsBeginQuery(false); if (!SecurityUtil.isUserAdmin()) { // admins have no restrictions. if (!sqlQuery.trim().endsWith("where")) { sqlQuery += " AND "; } sqlQuery += EntityUtils.addGroupAndUserNameRestriction(true, false); } if (taxonId != null) { if (!sqlQuery.trim().endsWith("where")) { sqlQuery += " AND "; } sqlQuery += " tax.ID = :taxonId "; } sqlQuery += orderBy + limitAbs; SQLQuery queryObject = this.getSessionFactory().getCurrentSession().createSQLQuery(sqlQuery); if (taxonId != null) { queryObject.setParameter("taxonId", taxonId); } EntityUtils.addUserAndGroupParameters(queryObject, this.getSessionFactory()); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { Long phenotypeId = ((BigInteger) results.get(0)).longValue(); ids.add(phenotypeId); } results.close(); return ids; }
From source file:ubic.gemma.persistence.service.association.phenotype.PhenotypeAssociationDaoImpl.java
License:Apache License
/** * @param queryObject execute sqlQuery and populate phenotypesGenesAssociations is : phenotype --> genes * @return map//w w w. ja va2 s . c om */ private Map<String, Set<Integer>> populateGenesAssociations(SQLQuery queryObject) { Map<String, Set<Integer>> phenotypesGenesAssociations = new HashMap<>(); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { Integer geneNcbiId = (Integer) results.get(0); String valueUri = (String) results.get(1); EntityUtils.populateMapSet(phenotypesGenesAssociations, valueUri, geneNcbiId); } results.close(); return phenotypesGenesAssociations; }
From source file:ubic.gemma.persistence.service.association.phenotype.PhenotypeAssociationDaoImpl.java
License:Apache License
/** * @param queryObject execute sqlQuery and populate phenotypesGenesAssociations is : phenotype --> genes * @return collection/*from w w w.j a va2 s . com*/ */ private Collection<GeneEvidenceValueObject> populateGenesWithPhenotypes(SQLQuery queryObject) { StopWatch sw = new StopWatch(); sw.start(); // we accumulate the phenotypes for a gene in one VO Map<Long, GeneEvidenceValueObject> genesWithPhenotypes = new HashMap<>(); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { /* 0: gene id 1: ncbi id 2: name 3: symbol 4: taxon id 5: taxon name 6: characteristic value URI */ Long geneId = ((BigInteger) results.get(0)).longValue(); Integer nbciGeneId = (Integer) results.get(1); String officialName = (String) results.get(2); String officialSymbol = (String) results.get(3); Long taxonId = ((BigInteger) results.get(4)).longValue(); String taxonCommonName = (String) results.get(5); String valueUri = (String) results.get(6); if (genesWithPhenotypes.get(geneId) != null) { genesWithPhenotypes.get(geneId).getPhenotypesValueUri().add(valueUri); } else { GeneEvidenceValueObject g = new GeneEvidenceValueObject(geneId); g.setNcbiId(nbciGeneId); g.setOfficialName(officialName); g.setOfficialSymbol(officialSymbol); g.setTaxonCommonName(taxonCommonName); g.setTaxonId(taxonId); g.getPhenotypesValueUri().add(valueUri); genesWithPhenotypes.put(geneId, g); } } results.close(); if (sw.getTime() > 500) { PhenotypeAssociationDaoImpl.log .info("Get " + genesWithPhenotypes.size() + " genes with phenotypes: " + sw.getTime() + "ms"); } return genesWithPhenotypes.values(); }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param session session// w ww .j a v a 2s . c o 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
/** * @param session session/*w ww. j av a 2 s.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; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
public static Collection<Long> filterProbesByPlatform(Collection<Long> probes, Collection<Long> arrayDesignIds, Session session) {/*from w w w .j a va 2 s . co m*/ assert probes != null && !probes.isEmpty(); assert arrayDesignIds != null && !arrayDesignIds.isEmpty(); String queryString = "SELECT CS AS csid FROM GENE2CS WHERE AD IN (:adids) AND CS IN (:probes)"; org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.addScalar("csid", LongType.INSTANCE); queryObject.setParameterList("probes", probes, LongType.INSTANCE); queryObject.setParameterList("adids", arrayDesignIds, LongType.INSTANCE); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); List<Long> r = new ArrayList<>(); while (results.next()) { r.add(results.getLong(0)); } results.close(); return r; }