List of usage examples for org.hibernate ScrollMode FORWARD_ONLY
ScrollMode FORWARD_ONLY
To view the source code for org.hibernate ScrollMode FORWARD_ONLY.
Click Source Link
From source file:org.zanata.dao.HTextFlowTargetStreamingDAO.java
License:Open Source License
/** * * @return scrollable result set of HTextFlowTarget under a project * iteration, with all of its fields(locale, textflow, document, * document locale, project iteration and project) eagerly fetched. */// www . j ava2s .c o m public ScrollableResults getTargetsWithAllFieldsEagerlyFetchedForProjectIteration(HProjectIteration iteration) { Query query = getSession() .createQuery("from HTextFlowTarget tft " + "join fetch tft.locale " + "join fetch tft.textFlow " + "join fetch tft.textFlow.document " + "join fetch tft.textFlow.document.locale " + "join fetch tft.textFlow.document.projectIteration iter " + "join fetch tft.textFlow.document.projectIteration.project where iter = :iteration"); return query.setFetchSize(Integer.MIN_VALUE).setParameter("iteration", iteration) .scroll(ScrollMode.FORWARD_ONLY); }
From source file:org.zanata.search.HTextFlowTargetIndexingStrategy.java
License:Open Source License
@Override protected ScrollableResults queryResults(int ignoredOffset, FullTextSession session) { // TODO move this query into something like HTextFlowTargetStreamingDAO Query query = session.createQuery("from HTextFlowTarget tft " + "join fetch tft.locale " + "join fetch tft.textFlow " + "join fetch tft.textFlow.document " + "join fetch tft.textFlow.document.locale " + "join fetch tft.textFlow.document.projectIteration " + "join fetch tft.textFlow.document.projectIteration.project"); query.setFetchSize(Integer.MIN_VALUE); return query.scroll(ScrollMode.FORWARD_ONLY); }
From source file:org.zanata.search.SimpleClassIndexingStrategy.java
License:Open Source License
@Override protected ScrollableResults queryResults(int offset, FullTextSession session) { Query query = session.createQuery("from " + getEntityType().getName()); query.setFirstResult(offset);/*from w w w. j a v a 2s . c om*/ query.setMaxResults(MAX_QUERY_ROWS); return query.scroll(ScrollMode.FORWARD_ONLY); }
From source file:ubic.gemma.persistence.service.association.phenotype.PhenotypeAssociationDaoImpl.java
License:Apache License
/** * find category terms currently used in the database by evidence *//* w w w . j ava2 s . c o m*/ @Override public Collection<CharacteristicValueObject> findEvidenceCategoryTerms() { Collection<CharacteristicValueObject> mgedCategory = new TreeSet<>(); String queryString = "SELECT DISTINCT CATEGORY_URI, category FROM PHENOTYPE_ASSOCIATION " + "JOIN INVESTIGATION ON PHENOTYPE_ASSOCIATION.EXPERIMENT_FK = INVESTIGATION.ID " + "JOIN CHARACTERISTIC ON CHARACTERISTIC.INVESTIGATION_FK= INVESTIGATION.ID"; org.hibernate.SQLQuery queryObject = this.getSessionFactory().getCurrentSession() .createSQLQuery(queryString); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { CharacteristicValueObject characteristicValueObject = new CharacteristicValueObject(-1L); characteristicValueObject.setCategoryUri((String) results.get(0)); characteristicValueObject.setCategory((String) results.get(1)); mgedCategory.add(characteristicValueObject); } results.close(); return mgedCategory; }
From source file:ubic.gemma.persistence.service.association.phenotype.PhenotypeAssociationDaoImpl.java
License:Apache License
/** * return the list of the owners that have evidence in the system *//*from w w w . j a va 2 s . c o m*/ @Override public Collection<String> findEvidenceOwners() { Set<String> owners = new HashSet<>(); String sqlQuery = "SELECT DISTINCT sid.PRINCIPAL FROM ACLOBJECTIDENTITY aoi JOIN ACLENTRY ace ON ace.OBJECTIDENTITY_FK = " + "aoi.ID JOIN ACLSID sid ON sid.ID = aoi.OWNER_SID_FK WHERE aoi.OBJECT_CLASS " + "IN " + PhenotypeAssociationDaoImpl.DISCRIMINATOR_CLAUSE; SQLQuery queryObject = this.getSessionFactory().getCurrentSession().createSQLQuery(sqlQuery); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { String owner = (String) results.get(0); owners.add(owner); } return owners; }
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 ww w .j av a 2 s . c o m*/ 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 ww . j av a 2 s .c o m */ 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 www .ja va 2 s. c o m */ 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);//from ww w. j a v a 2s . co 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.util.CommonQueries.java
License:Apache License
/** * @param session session//w ww . j a v a 2 s. 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; }