Example usage for org.hibernate SQLQuery setMaxResults

List of usage examples for org.hibernate SQLQuery setMaxResults

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setMaxResults.

Prototype

@Override
    Query<R> setMaxResults(int maxResult);

Source Link

Usage

From source file:ubic.gemma.persistence.service.expression.designElement.CompositeSequenceDaoImpl.java

License:Apache License

@Override
public Collection<Object[]> getRawSummary(Collection<CompositeSequence> compositeSequences) {
    if (compositeSequences == null || compositeSequences.size() == 0)
        return null;

    StringBuilder buf = new StringBuilder();

    for (Iterator<CompositeSequence> it = compositeSequences.iterator(); it.hasNext();) {
        CompositeSequence compositeSequence = it.next();
        if (compositeSequence == null || compositeSequence.getId() == null) {
            throw new IllegalArgumentException();
        }/*  ww w.j  a v  a2 s .co  m*/
        long id = compositeSequence.getId();
        buf.append(id);
        if (it.hasNext())
            buf.append(",");
    }

    // This uses the 'full' query, assuming that this list isn't too big.
    String nativeQueryString = CompositeSequenceDaoImpl.nativeBaseSummaryQueryString + " WHERE cs.ID IN ("
            + buf.toString() + ")";
    org.hibernate.SQLQuery queryObject = this.getSessionFactory().getCurrentSession()
            .createSQLQuery(nativeQueryString);
    queryObject.addScalar("deID").addScalar("deName").addScalar("bsName").addScalar("bsdbacc")
            .addScalar("ssrid").addScalar("gpId").addScalar("gpName").addScalar("gpNcbi").addScalar("geneid")
            .addScalar("gId").addScalar("gSymbol").addScalar("gNcbi").addScalar("adShortName")
            .addScalar("adId");

    queryObject.addScalar("chrom").addScalar("tgst").addScalar("tgend").addScalar("tgstarts").addScalar("bsId");

    queryObject.addScalar("deDesc", StandardBasicTypes.TEXT); // must do this for CLOB or Hibernate is unhappy
    queryObject.addScalar("adName");
    queryObject.setMaxResults(CompositeSequenceDaoImpl.MAX_CS_RECORDS);
    //noinspection unchecked
    return queryObject.list();
}

From source file:ubic.gemma.persistence.service.expression.designElement.CompositeSequenceDaoImpl.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from w  w w  .  j  a  v a 2s  . com
public Collection<Object[]> getRawSummary(ArrayDesign arrayDesign, Integer numResults) {
    if (arrayDesign == null || arrayDesign.getId() == null) {
        throw new IllegalArgumentException();
    }

    if (numResults <= 0) {
        // get all probes. Uses a light-weight version of this query that omits as much as possible.
        final String queryString = CompositeSequenceDaoImpl.nativeBaseSummaryShorterQueryString
                + " where ad.id = " + arrayDesign.getId();
        try {
            org.hibernate.SQLQuery queryObject = this.getSessionFactory().getCurrentSession()
                    .createSQLQuery(queryString);
            queryObject.addScalar("deID").addScalar("deName").addScalar("bsName").addScalar("bsdbacc")
                    .addScalar("ssrid").addScalar("gId").addScalar("gSymbol");
            queryObject.setMaxResults(CompositeSequenceDaoImpl.MAX_CS_RECORDS);
            return queryObject.list();
        } catch (org.hibernate.HibernateException ex) {
            throw SessionFactoryUtils.convertHibernateAccessException(ex);
        }

    }
    // just a chunk but get the full set of results.
    //language=HQL
    final String queryString = "select cs from CompositeSequence as cs inner join cs.arrayDesign as ar where ar = :ar";
    this.getHibernateTemplate().setMaxResults(numResults);
    List<?> cs = this.getHibernateTemplate().findByNamedParam(queryString, "ar", arrayDesign);
    this.getHibernateTemplate().setMaxResults(0);
    return this.getRawSummary((Collection<CompositeSequence>) cs);

}