List of usage examples for org.hibernate ScrollableResults setRowNumber
boolean setRowNumber(int rowNumber);
From source file:com.reignite.query.StructuredQuery.java
License:Open Source License
private void join(List<Object> rows) { for (Join join : joins) { Set<Object> ids = new HashSet<Object>(); for (Object obj : rows) { if (obj instanceof Map) { ids.add(((Map<?, ?>) obj).get(join.getJoinId())); }/*from w w w . ja v a 2 s . c o m*/ } // prepare the join by setting the order and adding an "in" // clause join.prepare(ids); // if ids is size 1 then we are either doing a per row join or there is only 1 result to join to int firstRow = ids.size() == 1 ? join.getStartIndex() : 0; ScrollableResults scroll = join.getCriteria().scroll(ScrollMode.FORWARD_ONLY); if (scroll.setRowNumber(firstRow)) { do { Object[] row = scroll.get(); mergeResult(rows, row, join); } while (scroll.next()); } scroll.close(); } }
From source file:com.reignite.query.StructuredQuery.java
License:Open Source License
private int runQuery(Criteria criteria, QueryResult result, int maxResults) { ScrollableResults scroll = criteria.scroll(ScrollMode.FORWARD_ONLY); int count = 0; if (scroll.setRowNumber(startIndex)) { while (count < maxResults) { Object[] row = scroll.get(); count = fillResult(result, row) ? count += 1 : count; if (!scroll.next()) { break; }//w ww . j a v a 2s .co m } } int totalResultCount = 0; if (scroll.last()) { totalResultCount = scroll.getRowNumber() + 1; } result.setTotalResults(totalResultCount); scroll.close(); return count; }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public List<ResultType> getVFDBList(Map<String, String> key, Map<String, String> sort, int start, int end) { String sql = ""; sql += getVFDBSQL(key, "function"); sql += " GROUP BY vfg_id, gene_name, gene_product, vf_id, vf_name, vf_fullname, function "; if (sort != null && sort.containsKey("field") && sort.get("field") != null && sort.containsKey("direction") && sort.get("direction") != null) { sql += " ORDER BY " + sort.get("field") + " " + sort.get("direction"); } else {/*from www .j a v a2 s. c o m*/ sql += " ORDER BY b.vfg_id, b.gene_name"; } Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql); q = bindVFDBSQLValues(q, key); if (end > 0) { q.setMaxResults(end); } ScrollableResults scr = q.scroll(); List<ResultType> results = new ArrayList<>(); if (start > 1) { scr.setRowNumber(start - 1); } else { scr.beforeFirst(); } for (int i = start; (end > 0 && i < end && scr.next()) || (end == -1 && scr.next()); i++) { Object[] obj = scr.get(); ResultType row = new ResultType(); row.put("vfg_id", obj[0]); row.put("gene_name", obj[1]); row.put("gene_product", obj[2]); row.put("vf_id", obj[3]); row.put("vf_name", obj[4]); row.put("vf_fullname", obj[5]); row.put("function", obj[6]); row.put("feature_count", obj[7]); results.add(row); } session.getTransaction().commit(); return results; }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public List<ResultType> getVFDBFeatureList(Map<String, String> key, Map<String, String> sort, int start, int end) { String sql = ""; sql += getVFDBFeatureSQL(key, "function"); if (sort != null && sort.containsKey("field") && sort.get("field") != null && sort.containsKey("direction") && sort.get("direction") != null) { sql += " ORDER BY " + sort.get("field") + " " + sort.get("direction"); } else {// w w w. ja v a 2 s . co m sql += " ORDER BY na_feature_id"; } Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql); q = bindVFDBFeatureSQLValues(q, key); if (end > 0) { q.setMaxResults(end); } ScrollableResults scr = q.scroll(); List<ResultType> results = new ArrayList<>(); if (start > 1) { scr.setRowNumber(start - 1); } else { scr.beforeFirst(); } for (int i = start; (end > 0 && i < end && scr.next()) || (end == -1 && scr.next()); i++) { Object[] obj = scr.get(); ResultType row = new ResultType(); row.put("vf_id", obj[0]); row.put("vf_name", obj[1]); row.put("vfg_id", obj[2]); row.put("gene_name", obj[3]); row.put("na_feature_id", obj[4]); row.put("genome_info_id", obj[5]); row.put("genome_name", obj[6]); row.put("accession", obj[7]); row.put("locus_tag", obj[8]); row.put("product", obj[9]); row.put("genome_id", obj[10]); row.put("feature_id", obj[11]); row.put("patric_id", obj[12]); row.put("refseq_locus_tag", obj[13]); row.put("alt_locus_tag", obj[14]); results.add(row); } session.getTransaction().commit(); return results; }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public List<ResultType> getCTDList(Map<String, String> key, Map<String, String> sort, int start, int end) { String sql = ""; sql += getCTDSQL(key, "function"); if (sort != null && sort.containsKey("field") && sort.get("field") != null && sort.containsKey("direction") && sort.get("direction") != null) { sql += " ORDER BY " + sort.get("field") + " " + sort.get("direction"); } else {/* w w w . j a v a2s .com*/ sql += " ORDER BY cs.gene_sym, cs.disease_name"; } Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql); q = bindSQLValues(q, key); if (end > 0) { q.setMaxResults(end); } ScrollableResults scr = q.scroll(); List<ResultType> results = new ArrayList<>(); if (start > 1) { scr.setRowNumber(start - 1); } else { scr.beforeFirst(); } for (int i = start; (end > 0 && i < end && scr.next()) || (end == -1 && scr.next()); i++) { Object[] obj = scr.get(); ResultType row = new ResultType(); row.put("gene_sym", obj[0]); row.put("gene_id", obj[1]); row.put("gene_disease_rel", obj[2]); row.put("disease_name", obj[3]); row.put("pubmed_id", obj[4]); row.put("disease_id", obj[5]); row.put("gd_app_name", obj[6]); results.add(row); } session.getTransaction().commit(); return results; }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public List<ResultType> getCTDGraphList(Map<String, String> key, Map<String, String> sort, int start, int end) { String sql = ""; sql += getCTDSQL(key, "graphlist"); if (sort != null && sort.containsKey("field") && sort.get("field") != null && sort.containsKey("direction") && sort.get("direction") != null) { sql += " ORDER BY " + sort.get("field") + " " + sort.get("direction"); } else {//from ww w . j av a2 s . c o m sql += " ORDER BY cs.gene_sym, cs.disease_name"; } Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql); q = bindGraphCTDSQLValues(q, key); if (end > 0) { q.setMaxResults(end); } ScrollableResults scr = q.scroll(); List<ResultType> results = new ArrayList<>(); if (start > 1) { scr.setRowNumber(start - 1); } else { scr.beforeFirst(); } for (int i = start; (end > 0 && i < end && scr.next()) || (end == -1 && scr.next()); i++) { Object[] obj = scr.get(); ResultType row = new ResultType(); row.put("gene_sym", obj[0]); row.put("gene_id", obj[1]); row.put("gene_disease_rel", obj[2]); row.put("disease_name", obj[3]); row.put("pubmed_id", obj[4]); row.put("disease_id", obj[5]); row.put("gd_app_name", obj[6]); results.add(row); } session.getTransaction().commit(); return results; }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public List<ResultType> getGADGraphList(Map<String, String> key, Map<String, String> sort, int start, int end) { String sql = ""; sql += getGADSQL(key, "graphlist"); if (sort != null && sort.containsKey("field") && sort.get("field") != null && sort.containsKey("direction") && sort.get("direction") != null) { sql += " ORDER BY " + sort.get("field") + " " + sort.get("direction"); } else {/*from w w w.jav a2s. co m*/ sql += " ORDER BY gs.gene_sym"; } Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql); q = bindGraphGADSQLValues(q, key); if (end > 0) { q.setMaxResults(end); } ScrollableResults scr = q.scroll(); List<ResultType> results = new ArrayList<>(); if (start > 1) { scr.setRowNumber(start - 1); } else { scr.beforeFirst(); } for (int i = start; (end > 0 && i < end && scr.next()) || (end == -1 && scr.next()); i++) { Object[] obj = scr.get(); ResultType row = new ResultType(); row.put("gene_sym", obj[0]); row.put("gene_id", obj[1]); row.put("association", obj[2]); row.put("mesh_disease_terms", obj[3]); row.put("broad_phenotype", obj[4]); row.put("pubmed_id", obj[5]); row.put("conclusion", obj[6]); row.put("gd_app_name", obj[7]); results.add(row); } session.getTransaction().commit(); return results; }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public List<ResultType> getGADList(Map<String, String> key, Map<String, String> sort, int start, int end) { String sql = ""; sql += getGADSQL(key, "function"); if (sort != null && sort.containsKey("field") && sort.get("field") != null && sort.containsKey("direction") && sort.get("direction") != null) { sql += " ORDER BY " + sort.get("field") + " " + sort.get("direction"); } else {//from w ww . j ava 2s . c om sql += " ORDER BY gs.gene_sym"; } Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql); q = bindSQLValues(q, key); if (end > 0) { q.setMaxResults(end); } ScrollableResults scr = q.scroll(); List<ResultType> results = new ArrayList<>(); if (start > 1) { scr.setRowNumber(start - 1); } else { scr.beforeFirst(); } for (int i = start; (end > 0 && i < end && scr.next()) || (end == -1 && scr.next()); i++) { Object[] obj = scr.get(); ResultType row = new ResultType(); row.put("gene_sym", obj[0]); row.put("gene_id", obj[1]); row.put("association", obj[2]); row.put("mesh_disease_terms", obj[3]); row.put("broad_phenotype", obj[4]); row.put("pubmed_id", obj[5]); row.put("conclusion", obj[6]); row.put("gd_app_name", obj[7]); results.add(row); } session.getTransaction().commit(); return results; }
From source file:edu.vt.vbi.patric.dao.DBPRC.java
License:Apache License
public ArrayList<ResultType> getPRCData(String taxonId, String filter, int start, int end, String sort, String dir) {//from w w w . jav a 2s . c om String sql = "select distinct experiment_id, description, speciesname, processing_type, summary, pubmed_id, count(distinct sample_id) from app.post_genomic"; if (filter.equals("MS")) sql += " where processing_type = 'Mass spectrometry'"; else if (filter.equals("MA")) sql += " where processing_type = 'Microarray'"; else sql += " where processing_type = 'Protein interaction'"; sql += " and taxon_id in (" + DBSummary.getTaxonIdsInTaxonSQL(":taxonId") + ")"; sql += " group by experiment_id, description, speciesname, processing_type, summary, pubmed_id"; sql += " order by " + sort + " " + dir; Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql); q.setTimeout(SQL_TIMEOUT); q.setString("taxonId", taxonId); ScrollableResults scr = null; try { scr = q.scroll(); } catch (Exception ex) { System.out.println("[SQL error]" + taxonId); ex.printStackTrace(); return null; } ArrayList<ResultType> results = new ArrayList<ResultType>(); Object[] obj = null; if (start > 1) { scr.setRowNumber(start - 1); } else { scr.beforeFirst(); } for (int i = start; (end > 0 && i < end && scr.next() == true) || (end == -1 && scr.next() == true); i++) { obj = scr.get(); ResultType row = new ResultType(); row.put("experiment_id", obj[0]); row.put("description", obj[1]); row.put("speciesname", obj[2]); row.put("experimenttype", obj[3]); row.put("summary", obj[4]); row.put("pubmed_id", obj[5]); row.put("samples", obj[6]); results.add(row); } session.getTransaction().commit(); return results; }
From source file:net.sf.oreka.services.RecSegmentServiceHbn.java
License:Open Source License
public int getResults(RecSegmentFilter filter, int offset, int number, String orderBy, boolean ascending, List results) {/*from w ww .j a v a 2 s . c o m*/ firstCriterium = true; int numResults = 0; logger.log(Level.DEBUG, "Entering getResults"); //logger.log(Level.INFO, System.getProperty("java.class.path")); //RecSegment seg1 = new RecSegment(); //RecSegment seg2 = new RecSegment(); //RecTape tape1 = new RecTape(); //RecTape tape2 = new RecTape(); /* RecSegmentResult result1 = new RecSegmentResult(); RecSegmentResult result2 = new RecSegmentResult(); result1.getRecSegment().setDuration(10); result1.getRecSegment().setLocalParty("01223"); results.add(result1); result2.getRecSegment().setDuration(11); result2.getRecSegment().setLocalParty("01440"); results.add(result2); */ /* for (int i=0; i<number; i++) { RecSegmentResult result = new RecSegmentResult(); result.getRecSegment().setDuration(offset + i); result.getRecSegment().setLocalParty(orderBy); result.getRecTape().setId(ascending ? 0:1); results.add(result); } numResults = 502; */ Transaction tx = null; Session session = null; try { session = OrkWeb.hibernateManager.getSession(); StringBuffer queryString = new StringBuffer( "from OrkSegment as seg left join seg.tape as tape left join tape.service as srv "); //StringBuffer queryString = new StringBuffer("from RecSegment as seg "); //boolean firstCriterium = false; if (filter.getStartDate() != null && filter.getEndDate() != null) queryString.append(" where seg.timestamp between :startDate and :endDate "); else if (filter.getStartDate() != null) queryString.append(" where seg.timestamp > :startDate "); else if (filter.getEndDate() != null) queryString.append(" where seg.timestamp < :endDate "); if (filter.getLocalParty().length() > 0) { queryString.append(" and seg.localParty=:localParty "); } if (filter.getRemoteParty().length() > 0) { queryString.append(" and seg.remoteParty=:remoteParty "); } if (filter.getMinDuration().length() > 0) { queryString.append(" and seg.duration>:minDuration "); } if (filter.getMaxDuration().length() > 0) { queryString.append(" and seg.duration<:maxDuration "); } if (filter.getDirection() != Direction.ALL) { queryString.append(" and seg.direction=:direction "); } if (orderBy.length() == 0) { orderBy = "seg.timestamp"; } queryString.append(" order by "); queryString.append(orderBy); if (ascending) { queryString.append(" asc"); } else { queryString.append(" desc"); } Query query = session.createQuery(queryString.toString()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); if (filter.getStartDate() != null) { logger.debug("Filter start date:" + dateFormat.format(filter.getStartDate())); query.setTimestamp("startDate", filter.getStartDate()); } if (filter.getEndDate() != null) { logger.debug("Filter end date:" + dateFormat.format(filter.getEndDate())); query.setTimestamp("endDate", filter.getEndDate()); } if (filter.getLocalParty().length() > 0) { query.setString("localParty", filter.getLocalParty()); } if (filter.getRemoteParty().length() > 0) { query.setString("remoteParty", filter.getRemoteParty()); } if (filter.getMinDuration().length() > 0) { query.setString("minDuration", filter.getMinDuration()); } if (filter.getMaxDuration().length() > 0) { query.setString("maxDuration", filter.getMaxDuration()); } if (filter.getDirection() != Direction.ALL) { query.setParameter("direction", filter.getDirection().ordinal()); //query.setParameter( "direction", filter.getDirection().name() ); } // Criteria crit = session.createCriteria(RecSegment.class); // //crit.setFetchMode("RecTape",FetchMode.EAGER); // crit.setFetchMode(null, FetchMode.LAZY); ScrollableResults scrollDocs = query.scroll(); if (scrollDocs.last()) { numResults = scrollDocs.getRowNumber() + 1; logger.debug("Num res:" + numResults); } //scrollDocs.beforeFirst(); scrollDocs.setRowNumber(offset); int rowsSoFar = 0; while (scrollDocs.get() != null && rowsSoFar < number) { rowsSoFar++; OrkSegment seg = (OrkSegment) scrollDocs.get(0); //logger.log(Level.ERROR, seg.getRecTape().getUrl()); //RecTape tape = (RecTape)scrollDocs.get(1); //RecTape tape = new RecTape(); RecSegmentResult res = new RecSegmentResult(); res.setRecSegment(seg); //res.setRecTape(tape); results.add(res); scrollDocs.next(); } } catch (HibernateException he) { if (tx != null) tx.rollback(); logger.log(Level.ERROR, he.toString()); he.printStackTrace(); } catch (Exception e) { logger.error(e); e.printStackTrace(); } finally { session.close(); } return numResults; }