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:org.generationcp.middleware.dao.gdms.DatasetDAO.java

License:Open Source License

public List<Integer> getDatasetIdsForMapping(final int start, final int numOfRows) {
    try {// w w  w.  j  av a 2 s  . com
        SQLQuery query = this.getSession().createSQLQuery(DatasetDAO.GET_DATASET_ID_BY_MAPPING_AND_NOT_QTL);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);
        return query.list();
    } catch (HibernateException e) {
        final String errorMessage = "Error with getDatasetIdsForMapping() query from Dataset: "
                + e.getMessage();
        DatasetDAO.LOG.error(errorMessage, e);
        throw new MiddlewareQueryException(errorMessage, e);

    }
}

From source file:org.generationcp.middleware.dao.gdms.DatasetDAO.java

License:Open Source License

public List<String> getDatasetNamesByQtlId(final Integer qtlId, final int start, final int numOfRows) {
    try {/* w  w  w  .j  a  va  2  s.c o m*/
        if (qtlId != null) {
            SQLQuery query = this.getSession().createSQLQuery(DatasetDAO.GET_DATASET_NAMES_BY_QTL_ID);
            query.setParameter("qtlId", qtlId);
            query.setFirstResult(start);
            query.setMaxResults(numOfRows);
            return query.list();
        }
        return new ArrayList<>();
    } catch (HibernateException e) {
        final String errorMessage = "Error with getDatasetNamesByQtlId() query from Dataset: " + e.getMessage();
        DatasetDAO.LOG.error(errorMessage, e);
        throw new MiddlewareQueryException(errorMessage, e);

    }
}

From source file:org.generationcp.middleware.dao.gdms.MapDAO.java

License:Open Source License

@SuppressWarnings("rawtypes")
public List<MapDetailElement> getMapDetailsByName(final String nameLike, final int start, final int numOfRows) {

    final SQLQuery query = this.getSession().createSQLQuery(MapDAO.GET_MAP_DETAILS_BY_NAME);
    query.setString("nameLike", nameLike.toLowerCase());
    query.setFirstResult(start);//from w  w w.  j a  va 2  s .  c  om
    query.setMaxResults(numOfRows);

    final List<MapDetailElement> maps = new ArrayList<MapDetailElement>();

    try {

        final List results = query.list();

        for (final Object o : results) {
            final Object[] result = (Object[]) o;
            if (result != null) {
                final int markerCount = ((BigInteger) result[0]).intValue();
                final Double maxStartPosition = (Double) result[1];
                final String linkageGroup = (String) result[2];
                final String mapName = (String) result[3];
                final String mapType = (String) result[4];
                final String mapDesc = (String) result[5];
                final String mapUnit = (String) result[6];

                final MapDetailElement map = new MapDetailElement(markerCount, maxStartPosition, linkageGroup,
                        mapName, mapType, mapDesc, mapUnit);
                maps.add(map);
            }
        }

        return maps;

    } catch (final HibernateException e) {
        MapDAO.LOG.error(e.getMessage(), e);
        throw new MiddlewareQueryException("Error with getMapDetailsByName() query from Map: " + e.getMessage(),
                e);
    }
}

From source file:org.generationcp.middleware.dao.gdms.MapDAO.java

License:Open Source License

@SuppressWarnings("rawtypes")
public List<MapDetailElement> getAllMapDetails(final int start, final int numOfRows) {
    final List<MapDetailElement> values = new ArrayList<MapDetailElement>();

    try {/*from   ww  w. j  av  a2  s.  c o m*/
        final SQLQuery query = this.getSession().createSQLQuery(MapDAO.GET_MAP_DETAILS);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);
        final List results = query.list();

        for (final Object o : results) {
            final Object[] result = (Object[]) o;
            if (result != null) {
                final BigInteger markerCount = (BigInteger) result[0];
                final Double max = (Double) result[1];
                final String linkageGroup = (String) result[2];
                final String mapName2 = (String) result[3];
                final String mapType = (String) result[4];
                final String mapDesc = (String) result[5];
                final String mapUnit = (String) result[6];

                final MapDetailElement element = new MapDetailElement(markerCount.intValue(), max, linkageGroup,
                        mapName2, mapType, mapDesc, mapUnit);
                values.add(element);
            }
        }

        return values;
    } catch (final HibernateException e) {
        MapDAO.LOG.error(e.getMessage(), e);
        throw new MiddlewareQueryException("Error with getAllMapDetails() query: " + e.getMessage(), e);
    }
}

From source file:org.generationcp.middleware.dao.gdms.MappingPopDAO.java

License:Open Source License

@SuppressWarnings("rawtypes")
public List<ParentElement> getAllParentsFromMappingPopulation(int start, int numOfRows)
        throws MiddlewareQueryException {

    SQLQuery query = this.getSession().createSQLQuery(MappingPopDAO.GET_ALL_PARENTS_FROM_MAPPING_POPULATION);
    query.setFirstResult(start);//from w w w .  ja  v  a 2 s  .com
    query.setMaxResults(numOfRows);

    List<ParentElement> dataValues = new ArrayList<ParentElement>();
    try {
        List results = query.list();

        for (Object o : results) {
            Object[] result = (Object[]) o;
            if (result != null) {
                int parentAGId = (Integer) result[0];
                int parentBGId = (Integer) result[1];
                String mappingPopType = null;
                ParentElement parentElement = new ParentElement(parentAGId, parentBGId, mappingPopType);
                dataValues.add(parentElement);
            }
        }
        return dataValues;
    } catch (HibernateException e) {
        this.logAndThrowException(
                "Error with getAllParentsFromMappingPopulation() query from MappingPop: " + e.getMessage(), e);
    }
    return dataValues;
}

From source file:org.generationcp.middleware.dao.gdms.MappingPopValuesDAO.java

License:Open Source License

/**
 * Gets the allelic values based on the given dataset id. The result is limited by the start and numOfRows parameters.
 * /* w  w  w .ja  v  a2s. c o m*/
 * @param datasetId the dataset id
 * @param start the start of the rows to retrieve
 * @param numOfRows the number of rows to retrieve
 * @return the Allelic Values (germplasm id, data value, and marker id) for the given dataset id
 * @throws MiddlewareQueryException the MiddlewareQueryException
 */
@SuppressWarnings("rawtypes")
public List<AllelicValueWithMarkerIdElement> getAllelicValuesByDatasetId(Integer datasetId, int start,
        int numOfRows) throws MiddlewareQueryException {
    List<AllelicValueWithMarkerIdElement> toReturn = new ArrayList<AllelicValueWithMarkerIdElement>();

    try {
        if (datasetId != null) {
            SQLQuery query = this.getSession()
                    .createSQLQuery(MappingPopValuesDAO.GET_ALLELIC_VALUES_BY_DATASET_ID);
            query.setParameter("datasetId", datasetId);
            query.setFirstResult(start);
            query.setMaxResults(numOfRows);
            List results = query.list();

            for (Object o : results) {
                Object[] result = (Object[]) o;
                if (result != null) {
                    Integer gid = (Integer) result[0];
                    Integer markerId = (Integer) result[1];
                    String data = (String) result[2];
                    Integer markerSampleId = (Integer) result[3];
                    Integer accSampleId = (Integer) result[4];
                    AllelicValueWithMarkerIdElement allelicValueElement = new AllelicValueWithMarkerIdElement(
                            gid, data, markerId, markerSampleId, accSampleId);
                    toReturn.add(allelicValueElement);
                }
            }
            return toReturn;
        }
    } catch (HibernateException e) {
        this.logAndThrowException("Error with getAllelicValuesByDatasetId(datasetId=" + datasetId
                + ") query from MappingPopValues: " + e.getMessage(), e);
    }
    return toReturn;

}

From source file:org.generationcp.middleware.dao.gdms.MappingPopValuesDAO.java

License:Open Source License

/**
 * Gets the gids by marker id.//from ww  w.j  a va  2s  .  co  m
 *
 * @param markerId the marker id
 * @param start the start
 * @param numOfRows the num of rows
 * @return the gI ds by marker id
 * @throws MiddlewareQueryException the MiddlewareQueryException
 */
@SuppressWarnings("unchecked")
public List<Integer> getGIDsByMarkerId(Integer markerId, int start, int numOfRows)
        throws MiddlewareQueryException {

    try {
        if (markerId != null) {
            SQLQuery query = this.getSession().createSQLQuery(MappingPopValuesDAO.GET_GIDS_BY_MARKER_ID);
            query.setParameter("markerId", markerId);
            query.setFirstResult(start);
            query.setMaxResults(numOfRows);
            return query.list();
        }
    } catch (HibernateException e) {
        this.logAndThrowException("Error with getGIDsByMarkerId(markerId=" + markerId
                + ") query from MappingPopValues: " + e.getMessage(), e);
    }
    return new ArrayList<Integer>();
}

From source file:org.generationcp.middleware.dao.gdms.MarkerDAO.java

License:Open Source License

/**
 * Gets the ids by names.// w  w w .  j a v a2 s  .c  o m
 *
 * @param names     the names
 * @param start     the start
 * @param numOfRows the num of rows
 * @return the ids by names
 * @ the MiddlewareQueryException
 */
public List<Integer> getIdsByNames(final List<String> names, final int start, final int numOfRows) {

    if (names == null || names.isEmpty()) {
        return new ArrayList<>();
    }

    try {
        final SQLQuery query = this.getSession().createSQLQuery(MarkerDAO.GET_IDS_BY_NAMES);
        query.setParameterList("markerNameList", names);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);
        return query.list();
    } catch (final HibernateException e) {
        LOG.error(e.getMessage(), e);
        throw new MiddlewareQueryException(
                "Error with getIdsByNames(names=" + names + ") query from Marker: " + e.getMessage(), e);
    }
}

From source file:org.generationcp.middleware.dao.gdms.MarkerDAO.java

License:Open Source License

/**
 * Get all marker types./*w ww. j  a  va 2  s . c om*/
 *
 * @param start     the start
 * @param numOfRows the num of rows
 * @return the all marker types
 * @ the MiddlewareQueryException
 */
public List<String> getAllMarkerTypes(final int start, final int numOfRows) {
    try {
        final SQLQuery query = this.getSession().createSQLQuery(MarkerDAO.GET_ALL_MARKER_TYPES);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);

        final List<String> markerTypes = query.list();

        return markerTypes;

    } catch (final HibernateException e) {
        LOG.error(e.getMessage(), e);
        throw new MiddlewareQueryException(
                "Error with getAllMarkerTypes() query from Marker: " + e.getMessage(), e);
    }
}

From source file:org.generationcp.middleware.dao.gdms.MarkerDAO.java

License:Open Source License

/**
 * Gets the all marker names by marker type.
 *
 * @param markerType the marker type//w  w  w  .  j av  a 2 s . co  m
 * @param start      the start
 * @param numOfRows  the num of rows
 * @return the all marker names by marker type
 * @ the MiddlewareQueryException
 */
public List<String> getMarkerNamesByMarkerType(final String markerType, final int start, final int numOfRows) {

    try {
        final SQLQuery query = this.getSession().createSQLQuery(MarkerDAO.GET_NAMES_BY_TYPE);
        query.setParameter("markerType", markerType);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);

        final List<String> markerNames = query.list();

        return markerNames;
    } catch (final HibernateException e) {
        LOG.error(e.getMessage(), e);
        throw new MiddlewareQueryException("Error with getMarkerNamesByMarkerType(markerType=" + markerType
                + ") query from Marker: " + e.getMessage(), e);
    }
}