Example usage for org.hibernate SQLQuery setParameterList

List of usage examples for org.hibernate SQLQuery setParameterList

Introduction

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

Prototype

@Override
    NativeQuery<T> setParameterList(String name, Object[] values);

Source Link

Usage

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

License:Open Source License

@SuppressWarnings("rawtypes")
public List<MarkerMetadataSet> getByMarkerIds(final List<Integer> markerIds) throws MiddlewareQueryException {
    List<MarkerMetadataSet> toReturn = new ArrayList<MarkerMetadataSet>();
    try {/*from   www  .  j  a v a 2s  . c om*/
        if (markerIds != null && !markerIds.isEmpty()) {
            SQLQuery query = this.getSession().createSQLQuery(MarkerMetadataSetDAO.GET_BY_MARKER_IDS);
            query.setParameterList("markerIdList", markerIds);

            List results = query.list();
            for (final Object o : results) {
                Object[] result = (Object[]) o;
                if (result != null) {
                    Integer markerMetadatasetId = (Integer) result[0];
                    Integer datasetId = (Integer) result[1];
                    Integer markerId2 = (Integer) result[2];
                    Integer markerSampleId = (Integer) result[3];

                    Dataset dataset = new Dataset();
                    dataset.setDatasetId(datasetId);

                    MarkerMetadataSet dataElement = new MarkerMetadataSet(markerMetadatasetId, dataset,
                            markerId2, markerSampleId);
                    toReturn.add(dataElement);
                }
            }
        }
    } catch (HibernateException e) {
        this.logAndThrowException("Error with getByMarkerIds(markerIds=" + markerIds
                + ") query from MarkerMetadataSet: " + e.getMessage(), e);
    }
    return toReturn;

}

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

License:Open Source License

public List<Object> getMarkersOnMapByMarkerIdsAndMapId(List<Integer> markerIds, Integer mapID) {

    List<Object> result = new ArrayList<>();

    String strQuerry = "SELECT distinct gdms_markers_onmap.marker_id, gdms_map.map_name, gdms_markers_onmap.start_position, gdms_markers_onmap.linkage_group, gdms_map.map_unit FROM "
            + "gdms_map join gdms_markers_onmap on gdms_map.map_id=gdms_markers_onmap.map_id where gdms_markers_onmap.marker_id in (:markerIds) "
            + "and gdms_map.map_id=(:mapID) "
            + "order BY gdms_map.map_name, gdms_markers_onmap.linkage_group, gdms_markers_onmap.start_position asc";

    SQLQuery query = this.getSession().createSQLQuery(strQuerry);
    query.setParameterList("markerIds", markerIds);
    query.setParameter("mapID", mapID);

    query.addScalar("marker_id", Hibernate.INTEGER);
    query.addScalar("map_name", Hibernate.STRING);
    query.addScalar("start_position", Hibernate.DOUBLE);
    query.addScalar("linkage_group", Hibernate.STRING);
    query.addScalar("map_unit", Hibernate.STRING);
    result = query.list();//from   ww  w .  j  a va  2s  .  c  o  m

    return result;

}

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

License:Open Source License

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

    try {/*ww w  .  j  a  va  2  s  . co m*/
        if (qtlIDs != null && !qtlIDs.isEmpty()) {
            SQLQuery query = this.getSession().createSQLQuery(QtlDAO.GET_QTL_AND_QTL_DETAILS_BY_QTL_IDS);
            query.setParameterList("qtl_id_list", qtlIDs);
            query.setFirstResult(start);
            query.setMaxResults(numOfRows);

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

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.  j a  va2s . 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.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 ww  w  .j  a v a2 s .  c  o  m
        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.gdms.QtlDetailsDAO.java

License:Open Source License

public long countQtlDataByQtlTraits(List<Integer> qtlTraits) throws MiddlewareQueryException {
    try {/*w w w .j  ava2 s  .  c o m*/
        if (qtlTraits != null && !qtlTraits.isEmpty()) {
            SQLQuery query = this.getSession().createSQLQuery(QtlDetailsDAO.COUNT_QTL_DATA_BY_QTL_TRAITS);
            query.setParameterList("qtlTraits", qtlTraits);
            BigInteger result = (BigInteger) query.uniqueResult();
            if (result != null) {
                return result.longValue();
            }
        }
    } catch (HibernateException e) {
        this.logAndThrowException(
                "Error with countQtlDataByQtlTraits() query from QtlDetails: " + e.getMessage(), e);
    }
    return 0;
}

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

License:Open Source License

public List<Germplasm> getProgenitorsByGIDWithPrefName(final Integer gid) {
    Preconditions.checkNotNull(gid);/*from   w w w . ja va 2s  . co  m*/
    try {
        final List<Germplasm> progenitors = new ArrayList<>();

        final SQLQuery query = this.getSession()
                .createSQLQuery(Germplasm.GET_PROGENITORS_BY_GIDS_WITH_PREF_NAME);
        query.addScalar("gid");
        query.addEntity("g", Germplasm.class);
        query.addEntity("n", Name.class);
        query.addScalar("malePedigree");
        query.setParameterList("gidList", Lists.newArrayList(gid));
        final List<Object[]> results = query.list();
        for (final Object[] result : results) {
            final Germplasm germplasm = (Germplasm) result[1];
            final Name prefName = (Name) result[2];
            germplasm.setPreferredName(prefName);
            progenitors.add(germplasm);
        }

        return progenitors;
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getProgenitorsByGIDWithPrefName(gid=" + gid
                + 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 Map<Integer, List<GermplasmParent>> getParentsFromProgenitorsForGIDsMap(final List<Integer> gids) {
    Preconditions.checkNotNull(gids);/*from ww  w  .  jav  a  2 s.c  om*/
    Preconditions.checkArgument(!gids.isEmpty());

    final Map<Integer, List<GermplasmParent>> map = new HashMap<>();
    try {
        final SQLQuery query = this.getSession()
                .createSQLQuery(Germplasm.GET_PROGENITORS_BY_GIDS_WITH_PREF_NAME);
        query.addScalar("gid");
        query.addEntity("g", Germplasm.class);
        query.addEntity("n", Name.class);
        query.addScalar("malePedigree");
        query.setParameterList("gidList", gids);
        final List<Object[]> results = query.list();

        List<GermplasmParent> progenitors = new ArrayList<>();
        Integer lastGid = 0;
        for (final Object[] result : results) {
            final Integer crossGid = (Integer) result[0];
            if (lastGid == 0) {
                lastGid = crossGid;
            }
            if (!crossGid.equals(lastGid)) {
                map.put(lastGid, progenitors);
                lastGid = crossGid;
                progenitors = new ArrayList<>();
            }
            final Germplasm germplasm = (Germplasm) result[1];
            final Name prefName = (Name) result[2];
            final String pedigree = (String) result[3];
            germplasm.setPreferredName(prefName);
            progenitors.add(new GermplasmParent(germplasm.getGid(), prefName.getNval(), pedigree));
        }
        // Set last cross GID to map
        map.put(lastGid, progenitors);

        return map;
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getProgenitorsForGIDsMap(gids=" + gids
                + 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

@SuppressWarnings("unchecked")
public List<Germplasm> getByGIDList(final List<Integer> gids) {

    if (gids.isEmpty()) {
        return new ArrayList<>();
    }//from  w w w .  jav a  2 s  . c  om

    try {
        final StringBuilder queryString = new StringBuilder();
        queryString.append("SELECT {g.*} FROM germplsm g WHERE ");
        queryString.append("g.gid IN( :gids ) ");

        final SQLQuery query = this.getSession().createSQLQuery(queryString.toString());
        query.setParameterList("gids", gids);
        query.addEntity("g", Germplasm.class);

        return query.list();

    } catch (final HibernateException e) {
        final String message = "Error with getByGIDList(gids=" + gids.toString()
                + GermplasmDAO.QUERY_FROM_GERMPLASM + e.getMessage();
        GermplasmDAO.LOG.error(message, e);
        throw new MiddlewareQueryException(message, e);
    }
}

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

License:Open Source License

public Map<Integer, Integer> getGermplasmDatesByGids(final List<Integer> gids) {
    final Map<Integer, Integer> resultMap = new HashMap<>();
    final SQLQuery query = this.getSession().createSQLQuery(Germplasm.GET_GERMPLASM_DATES_BY_GIDS);
    query.setParameterList("gids", gids);
    @SuppressWarnings("rawtypes")
    final List results = query.list();
    for (final Object result : results) {
        final Object[] resultArray = (Object[]) result;
        final Integer gid = (Integer) resultArray[0];
        final Integer gdate = (Integer) resultArray[1];
        resultMap.put(gid, gdate);//from   w w  w  . j  a  v  a2  s.com
    }
    return resultMap;
}