Example usage for org.hibernate ScrollableResults next

List of usage examples for org.hibernate ScrollableResults next

Introduction

In this page you can find the example usage for org.hibernate ScrollableResults next.

Prototype

boolean next();

Source Link

Document

Advance to the next result.

Usage

From source file:edu.utah.further.core.data.hibernate.page.ScrollableResultsPager.java

License:Apache License

/**
 * @param iterable//from ww w  .ja  va 2 s  .c om
 * @param pagingStrategy
 */
protected ScrollableResultsPager(final ScrollableResults iterable, final PagingStrategy pagingStrategy) {
    super(pagingStrategy);
    ValidationUtil.validateNotNull("iterable", iterable);
    this.iterable = iterable;
    // Point to the first result set row
    this.hasNext = iterable.next();
}

From source file:edu.utah.further.core.data.util.HibernateUtil.java

License:Apache License

/**
 * @param <T>/*from w w w. j a v  a 2s  . com*/
 * @param results
 * @return
 */
public static <T> List<T> asList(final ScrollableResults results) {
    final List<T> resultList = CollectionUtil.newList();
    while (results.next()) {
        resultList.add((T) results.get(0));
    }
    return resultList;
}

From source file:edu.utah.further.ds.impl.executor.db.hibernate.criteria.HibernateCriteriaScrollableResultsExecutor.java

License:Apache License

/**
 * @param request//from   w ww .j  ava  2 s.  c o m
 * @return
 * @see edu.utah.further.core.chain.AbstractRequestHandler#process(edu.utah.further.core.api.chain.ChainRequest)
 */
@Override
public boolean process(final ChainRequest request) {
    final QueryExecutionRequest executionRequest = new QueryExecutionRequest(request);
    final GenericCriteria criteria = executionRequest.getResult();
    final ScrollableResults results = getResultListFromHibernate(criteria);
    executionRequest.setResult(results);
    executionRequest.setStatus("Executed query @ " + TimeService.getDate());
    // Hibernate's ScrollableResults interface has no hasNext() or peek(), so go one
    // row forward (if exists) and then back all the way so that we don't miss the
    // first row in subsequent processors
    final boolean hasNext = results.next();
    if (hasNext) {
        results.previous();
    }
    return hasNext;
}

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 {//  w  w  w  .  j a  va 2 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 ww  .ja  v  a2 s. c  o 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 {// www . j av  a  2 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 = 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.  ja va 2s.  c  om*/

        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 {//  w w  w .j a v a2s. c o  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 a  v a 2s  .  co m*/

        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 ww.  ja  va 2 s.  c  o  m

    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;
}