Example usage for org.hibernate SQLQuery setFirstResult

List of usage examples for org.hibernate SQLQuery setFirstResult

Introduction

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

Prototype

@Override
    Query<R> setFirstResult(int startPosition);

Source Link

Usage

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

License:Open Source License

public List<QtlDetailElement> getQtlDetailsByQtlTraits(List<Integer> qtlTraits, int start, int numOfRows)
        throws MiddlewareQueryException {
    List<QtlDetailElement> toReturn = new ArrayList<QtlDetailElement>();

    try {//from ww w . java2 s . c o  m
        SQLQuery query = this.getSession().createSQLQuery(QtlDAO.GET_QTL_DETAILS_BY_TRAITS);
        query.setParameterList("qtlTraitIds", qtlTraits);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);

        toReturn = this.getQtlAndQtlDetails(query);
    } catch (HibernateException e) {
        this.logAndThrowException("Error with getQtlDetailsByQtlTraits(qtlTraits=" + qtlTraits
                + ") query from gdms_qtl_details: " + e.getMessage(), e);
    }
    return toReturn;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public Set<Integer> getMapIDsByQTLName(String qtlName, int start, int numOfRows)
        throws MiddlewareQueryException {
    try {/*  w  w  w  .j av  a 2  s .c om*/

        SQLQuery query;

        query = this.getSession().createSQLQuery(QtlDAO.GET_MAP_IDS_BY_QTL_NAME);
        query.setParameter("qtl_name", qtlName);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);
        Set<Integer> mapIDSet = new TreeSet<Integer>(query.list());

        return mapIDSet;

    } catch (HibernateException e) {
        this.logAndThrowException("Error with getMapIDsByQTLName(qtlName=" + qtlName + ", start=" + start
                + ", numOfRows=" + numOfRows + ") query from QTL: " + e.getMessage(), e);
    }
    return new TreeSet<Integer>();
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Integer> getQtlByTrait(Integer traitId, int start, int numOfRows) throws MiddlewareQueryException {
    try {/*from w  w  w. jav  a2s.c  om*/
        if (traitId != null) {
            SQLQuery query = this.getSession().createSQLQuery(QtlDAO.GET_QTL_BY_TRAIT);
            query.setParameter("qtlTrait", traitId);
            query.setFirstResult(start);
            query.setMaxResults(numOfRows);
            return query.list();
        }
    } catch (HibernateException e) {
        this.logAndThrowException("Error with getQtlByTrait(traitId=" + traitId
                + ") query from gdms_qtl_details: " + e.getMessage(), e);
    }
    return new ArrayList<Integer>();
}

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

License:Open Source License

public List<Integer> getMarkerIdsByQtl(String qtlName, String chromosome, float min, float max, int start,
        int numOfRows) throws MiddlewareQueryException {
    try {//w  w  w.  j a va2s. c om
        SQLQuery query = this.getSession().createSQLQuery(QtlDetailsDAO.GET_MARKER_IDS_BY_QTL);
        query.setParameter("qtlName", qtlName);
        query.setParameter("chromosome", chromosome);
        query.setParameter("min", min);
        query.setParameter("max", max);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);
        return query.list();

    } catch (HibernateException e) {
        this.logAndThrowException("Error with getMarkerIDsByQtl() query from QtlDetails: " + e.getMessage(), e);
    }
    return new ArrayList<Integer>();
}

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

License:Open Source License

public List<Integer> getMapIdsByQtlName(String qtlName, int start, int numOfRows)
        throws MiddlewareQueryException {
    try {// w  w w .  j  av a  2  s  . co m
        SQLQuery query = this.getSession().createSQLQuery(QtlDetailsDAO.GET_MAP_IDS_BY_QTL);
        query.setParameter("qtlName", qtlName);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);
        return query.list();

    } catch (HibernateException e) {
        this.logAndThrowException("Error with getMapIdsByQtlName() query from QtlDetails: " + e.getMessage(),
                e);
    }
    return new ArrayList<Integer>();
}

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

License:Open Source License

public List<Integer> getQtlTraitsByDatasetId(Integer datasetId, int start, int numOfRows)
        throws MiddlewareQueryException {
    try {/* w w w.  j a v  a 2  s .c  o m*/
        if (datasetId != null) {
            SQLQuery query = this.getSession().createSQLQuery(QtlDetailsDAO.GET_QTL_TRAITS_BY_DATASET_ID);
            query.setParameter("datasetId", datasetId);
            query.setFirstResult(start);
            query.setMaxResults(numOfRows);
            return query.list();
        }
    } catch (HibernateException e) {
        this.logAndThrowException(
                "Error with getQtlTraitsByDatasetId() query from QtlDetails: " + e.getMessage(), e);
    }
    return new ArrayList<Integer>();
}

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

License:Open Source License

public List<QtlDataElement> getQtlDataByQtlTraits(List<Integer> qtlTraits, int start, int numOfRows)
        throws MiddlewareQueryException {
    List<QtlDataElement> toReturn = new ArrayList<QtlDataElement>();

    try {//from  w  w w  .  j a  va 2s .  com
        if (qtlTraits != null && !qtlTraits.isEmpty()) {
            SQLQuery query = this.getSession().createSQLQuery(QtlDetailsDAO.GET_QTL_DATA_BY_QTL_TRAITS);
            query.setParameterList("qtlTraits", qtlTraits);
            query.setFirstResult(start);
            query.setMaxResults(numOfRows);

            @SuppressWarnings("rawtypes")
            List results = query.list();

            for (Object o : results) {
                Object[] result = (Object[]) o;
                if (result != null) {
                    // Get the fields for QtlDataElement
                    String qtlName = (String) result[0];
                    String linkageGroup = (String) result[1];
                    Float position = (Float) result[2];
                    Float minPosition = (Float) result[3];
                    Float maxPosition = (Float) result[4];
                    Integer traitId = (Integer) result[5];
                    String experiment = (String) result[6];
                    String leftFlankingMarker = (String) result[7];
                    String rightFlankingMarker = (String) result[8];
                    Float effect = (Float) result[9];
                    Float scoreValue = (Float) result[10];
                    Float rSquare = (Float) result[11];

                    QtlDataElement qtlData = new QtlDataElement(qtlName, linkageGroup, position, minPosition,
                            maxPosition, traitId, experiment, leftFlankingMarker, rightFlankingMarker, effect,
                            scoreValue, rSquare);
                    toReturn.add(qtlData);
                }
            }
        }
    } catch (HibernateException e) {
        this.logAndThrowException("Error with getQtlDataByQtlTraits() query from QtlDetails: " + e.getMessage(),
                e);
    }
    return toReturn;
}

From source file:org.generationcp.middleware.dao.GermplasmDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Germplasm> getByNamePermutations(final String name, final Operation operation, final int start,
        final int numOfRows) {

    // Converting supplied value to combination of names that can exists in names
    final List<String> names = GermplasmDataManagerUtil.createNamePermutations(name);

    if (names == null || names.isEmpty()) {
        return new ArrayList<>();
    }//ww  w .  ja  v  a  2s  .c  om

    try {

        final String originalName = names.get(0);
        final String standardizedName = names.get(1);
        final String noSpaceName = names.get(2);

        // Search using = by default
        SQLQuery query = this.getSession().createSQLQuery(Germplasm.GET_BY_NAME_ALL_MODES_USING_EQUAL);
        if (operation == Operation.LIKE) {
            query = this.getSession().createSQLQuery(Germplasm.GET_BY_NAME_ALL_MODES_USING_LIKE);
        }

        // Set the parameters
        query.setParameter("name", originalName);
        query.setParameter("noSpaceName", noSpaceName);
        query.setParameter("standardizedName", standardizedName);

        query.addEntity("g", Germplasm.class);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);

        return query.list();
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getByName(names=" + names + GermplasmDAO.QUERY_FROM_GERMPLASM
                + e.getMessage();
        GermplasmDAO.LOG.error(errorMessage, e);
        throw new MiddlewareQueryException(errorMessage, e);
    }
}

From source file:org.generationcp.middleware.dao.GermplasmDAO.java

License:Open Source License

public List<Germplasm> getManagementNeighbors(final Integer gid, final int start, final int numOfRows) {
    final List<Germplasm> toreturn = new ArrayList<>();
    try {/*from ww w  .j a v  a  2s. co m*/
        if (gid != null) {
            final SQLQuery query = this.getSession().createSQLQuery(Germplasm.GET_MANAGEMENT_NEIGHBORS);
            query.addEntity("g", Germplasm.class);
            query.addEntity("n", Name.class);
            query.setParameter("gid", gid);

            query.setFirstResult(start);
            query.setMaxResults(numOfRows);

            for (final Object resultObject : query.list()) {
                final Object[] result = (Object[]) resultObject;
                final Germplasm germplasm = (Germplasm) result[0];
                final Name prefName = (Name) result[1];
                germplasm.setPreferredName(prefName);
                toreturn.add(germplasm);
            }
        }

    } catch (final HibernateException e) {
        final String errorMessage = "Error with getManagementNeighbors(gid=" + gid
                + GermplasmDAO.QUERY_FROM_GERMPLASM + e.getMessage();
        GermplasmDAO.LOG.error(errorMessage, e);
        throw new MiddlewareQueryException(errorMessage, e);
    }
    return toreturn;
}

From source file:org.generationcp.middleware.dao.GermplasmDAO.java

License:Open Source License

public List<Germplasm> getGroupRelatives(final Integer gid, final int start, final int numRows) {
    final List<Germplasm> toreturn = new ArrayList<>();
    try {/*from ww  w .  j av  a 2 s  . co  m*/
        if (gid != null) {
            final SQLQuery query = this.getSession().createSQLQuery(Germplasm.GET_GROUP_RELATIVES);
            query.addEntity("g", Germplasm.class);
            query.addEntity("n", Name.class);
            query.setParameter("gid", gid);

            query.setFirstResult(start);
            query.setMaxResults(numRows);

            for (final Object resultObject : query.list()) {
                final Object[] result = (Object[]) resultObject;
                final Germplasm germplasm = (Germplasm) result[0];
                final Name prefName = (Name) result[1];
                germplasm.setPreferredName(prefName);
                toreturn.add(germplasm);
            }
        }
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getGroupRelatives(gid=" + gid
                + GermplasmDAO.QUERY_FROM_GERMPLASM + e.getMessage();
        GermplasmDAO.LOG.error(errorMessage, e);
        throw new MiddlewareQueryException(errorMessage, e);
    }
    return toreturn;
}