List of usage examples for org.hibernate ScrollableResults get
Object get(int i);
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 ww. j a v a2s .c om*/ */ 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.service.expression.bioAssayData.DesignElementDataVectorDaoImpl.java
License:Apache License
private void getVectorsBatch(Map<Long, Collection<Long>> cs2gene, org.hibernate.Query queryObject, Map<T, Collection<Long>> dedv2genes, Collection<Long> batch) { queryObject.setParameterList("cs", batch); queryObject.setFlushMode(FlushMode.MANUAL); queryObject.setReadOnly(true);/*ww w .j av a 2 s . c o m*/ ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { @SuppressWarnings("unchecked") T dedv = (T) results.get(0); Long cs = (Long) results.get(1); Collection<Long> associatedGenes = cs2gene.get(cs); if (!dedv2genes.containsKey(dedv)) { dedv2genes.put(dedv, associatedGenes); } else { Collection<Long> mappedGenes = dedv2genes.get(dedv); mappedGenes.addAll(associatedGenes); } } results.close(); }
From source file:ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentDaoImpl.java
License:Apache License
@Override public Map<Taxon, Long> getPerTaxonCount() { Map<Taxon, Long> taxonCount = new LinkedHashMap<>(); String queryString = "select t, count(distinct ee) from ExpressionExperiment " + "ee inner join ee.bioAssays as ba inner join ba.sampleUsed su " + "inner join su.sourceTaxon t group by t order by t.scientificName "; // it is important to cache this, as it gets called on the home page. Though it's actually fast. org.hibernate.Query queryObject = this.getSessionFactory().getCurrentSession().createQuery(queryString); queryObject.setCacheable(true);// w w w .j av a 2 s . co m ScrollableResults list = queryObject.scroll(); while (list.next()) { Taxon taxon = (Taxon) list.get(0); Long count = list.getLong(1); taxonCount.put(taxon, count); } return taxonCount; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
private static void addGenes(Map<CompositeSequence, Collection<Gene>> cs2gene, ScrollableResults results) { while (results.next()) { CompositeSequence cs = (CompositeSequence) results.get(0); Gene g = (Gene) results.get(1);//from w w w. j a va 2 s . c om if (!cs2gene.containsKey(cs)) { cs2gene.put(cs, new HashSet<Gene>()); } cs2gene.get(cs).add(g); } }
From source file:uit.qabpss.util.dao.orm.hibernate.QueryUtil.java
License:Open Source License
public static List<?> randomList(Query query, Dialect dialect, int total, int num, boolean unmodifiable) { if ((total == 0) || (num == 0)) { return new ArrayList<Object>(); }//from ww w .j av a 2 s.com if (num >= total) { return list(query, ALL_POS, ALL_POS); } int[] scrollIds = Randomizer.getInstance().nextInt(total, num); List<Object> list = new ArrayList<Object>(); ScrollableResults sr = query.scroll(); for (int i = 0; i < scrollIds.length; i++) { if (sr.scroll(scrollIds[i])) { Object obj = sr.get(0); list.add(obj); sr.first(); } } return list; }
From source file:vnpt.media.efinder.model.PaginationResult.java
public PaginationResult(Query query, int page, int maxResult, int maxNavigationPage) { final int pageIndex = page - 1 < 0 ? 0 : page - 1; int fromRecordIndex = pageIndex * maxResult; int maxRecordIndex = fromRecordIndex + maxResult; ScrollableResults resultScroll = query.scroll(ScrollMode.SCROLL_INSENSITIVE); //resultScroll.g List results = new ArrayList<>(); boolean hasResult = resultScroll.first(); if (hasResult) { // Cuon toi vi tri hasResult = resultScroll.scroll(fromRecordIndex); if (hasResult) { do {//www . jav a 2 s . co m E record = (E) resultScroll.get(0); results.add(record); } while (resultScroll.next()// && resultScroll.getRowNumber() >= fromRecordIndex && resultScroll.getRowNumber() < maxRecordIndex); } // chuyen toi ban ghi cuoi resultScroll.last(); } // Tong so ban ghi this.totalRecords = resultScroll.getRowNumber() + 1; this.currentPage = pageIndex + 1; this.list = results; this.maxResult = maxResult; this.totalPages = (this.totalRecords / this.maxResult); if (totalRecords % this.maxResult != 0) { this.totalPages = this.totalPages + 1; } this.maxNavigationPage = totalPages; if (maxNavigationPage < totalPages) { this.maxNavigationPage = maxNavigationPage; } this.calcNavigationPages(); }