List of usage examples for org.hibernate ScrollableResults getLong
Long getLong(int col);
From source file:org.dcm4chee.archive.query.impl.StudyQuery.java
License:LGPL
@Override public Attributes toAttributes(ScrollableResults results, QueryContext context) { Long studyPk = results.getLong(0); Integer numberOfInstancesI = results.getInteger(1); int numberOfStudyRelatedInstances; int numberOfStudyRelatedSeries; String modalitiesInStudy;/*from w ww. j a v a 2 s.co m*/ String sopClassesInStudy; String retrieveAETs; Availability availability; int numberOfStudyVisibleInstances; Date studyLastUpdateTime; if (numberOfInstancesI != null) { numberOfStudyRelatedInstances = numberOfInstancesI; if (numberOfStudyRelatedInstances == 0) return null; numberOfStudyRelatedSeries = results.getInteger(2); modalitiesInStudy = results.getString(3); sopClassesInStudy = results.getString(4); retrieveAETs = results.getString(5); availability = (Availability) results.get(6); numberOfStudyVisibleInstances = results.getInteger(7); studyLastUpdateTime = results.getDate(8); } else { StudyQueryAttributes studyView = context.getQueryService().createStudyView(studyPk, context.getQueryParam()); numberOfStudyRelatedInstances = studyView.getNumberOfInstances(); if (numberOfStudyRelatedInstances == 0) return null; numberOfStudyRelatedSeries = studyView.getNumberOfSeries(); modalitiesInStudy = studyView.getRawModalitiesInStudy(); sopClassesInStudy = studyView.getRawSOPClassesInStudy(); retrieveAETs = studyView.getRawRetrieveAETs(); availability = studyView.getAvailability(); numberOfStudyVisibleInstances = studyView.getNumberOfVisibleInstances(); studyLastUpdateTime = studyView.getLastUpdateTime(); } byte[] studyByteAttributes = results.getBinary(9); byte[] patientByteAttributes = results.getBinary(10); Attributes patientAttrs = new Attributes(); Attributes studyAttrs = new Attributes(); Utils.decodeAttributes(patientAttrs, patientByteAttributes); Utils.decodeAttributes(studyAttrs, studyByteAttributes); Attributes attrs = Utils.mergeAndNormalize(patientAttrs, studyAttrs); ArchiveDeviceExtension ade = context.getArchiveAEExtension().getApplicationEntity().getDevice() .getDeviceExtension(ArchiveDeviceExtension.class); Utils.setStudyQueryAttributes(attrs, numberOfStudyRelatedSeries, numberOfStudyRelatedInstances, modalitiesInStudy, sopClassesInStudy, numberOfStudyVisibleInstances, ade.getPrivateDerivedFields().findStudyNumberOfVisibleInstancesTag(), studyLastUpdateTime, ade.getPrivateDerivedFields().findStudyUpdateTimeTag()); Utils.setRetrieveAET(attrs, retrieveAETs); Utils.setAvailability(attrs, availability); return attrs; }
From source file:ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentDaoImpl.java
License:Apache License
@Override public Collection<ExpressionExperiment> findByExpressedGene(Gene gene, Double rank) { //language=MySQL final String queryString = "SELECT DISTINCT ee.ID AS eeID FROM " + "GENE2CS g2s, COMPOSITE_SEQUENCE cs, PROCESSED_EXPRESSION_DATA_VECTOR dedv, INVESTIGATION ee " + "WHERE g2s.CS = cs.ID AND cs.ID = dedv.DESIGN_ELEMENT_FK AND dedv.EXPRESSION_EXPERIMENT_FK = ee.ID" + " AND g2s.gene = :geneID AND dedv.RANK_BY_MEAN >= :rank"; Collection<Long> eeIds; try {/* w ww. j a v a2s . com*/ Session session = this.getSessionFactory().getCurrentSession(); org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.setLong("geneID", gene.getId()); queryObject.setDouble("rank", rank); queryObject.addScalar("eeID", new LongType()); ScrollableResults results = queryObject.scroll(); eeIds = new HashSet<>(); // Post Processing while (results.next()) eeIds.add(results.getLong(0)); session.clear(); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } return this.load(eeIds); }
From source file:ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentDaoImpl.java
License:Apache License
@Override public Collection<ExpressionExperiment> findByGene(Gene gene) { /*//from ww w . j a v a 2s . c o m * uses GENE2CS table. */ //language=MySQL final String queryString = "SELECT DISTINCT ee.ID AS eeID FROM " + "GENE2CS g2s, COMPOSITE_SEQUENCE cs, ARRAY_DESIGN ad, BIO_ASSAY ba, INVESTIGATION ee " + "WHERE g2s.CS = cs.ID AND ad.ID = cs.ARRAY_DESIGN_FK AND ba.ARRAY_DESIGN_USED_FK = ad.ID AND" + " ba.EXPRESSION_EXPERIMENT_FK = ee.ID AND g2s.GENE = :geneID"; Collection<Long> eeIds; Session session = this.getSessionFactory().getCurrentSession(); org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.setLong("geneID", gene.getId()); queryObject.addScalar("eeID", new LongType()); ScrollableResults results = queryObject.scroll(); eeIds = new HashSet<>(); while (results.next()) { eeIds.add(results.getLong(0)); } return this.load(eeIds); }
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);/*from ww w . j a va 2 s. com*/ 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 addGeneIds(Map<Long, Collection<Long>> cs2genes, ScrollableResults results) { while (results.next()) { Long csid = results.getLong(0); Long geneId = results.getLong(1); if (!cs2genes.containsKey(csid)) { cs2genes.put(csid, new HashSet<Long>()); }/*from ww w. j a v a2 s . co m*/ cs2genes.get(csid).add(geneId); } }
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) {//w ww .ja va2s .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; }