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.MarkerDAO.java

License:Open Source License

public List<AllelicValueElement> getAllelicValuesFromLocal(final List<Integer> gids) {

    final List<AllelicValueElement> allelicValues = new ArrayList<>();

    if (gids == null || gids.isEmpty()) {
        return allelicValues;
    }//from   w w w  .j av a2 s.  c  o  m

    try {

        // retrieve allelic values from allele_values
        SQLQuery query = this.getSession().createSQLQuery(AlleleValuesDAO.GET_ALLELIC_VALUES_BY_GID_LOCAL);
        query.setParameterList("gidList", gids);
        List results = query.list();
        allelicValues.addAll(this.getAllelicValueElementsFromListLocal(results));

        // retrieve allelic values from char_values
        query = this.getSession().createSQLQuery(CharValuesDAO.GET_ALLELIC_VALUES_BY_GID_LOCAL);
        query.setParameterList("gidList", gids);
        results = query.list();
        allelicValues.addAll(this.getAllelicValueElementsFromListLocal(results));

        // retrieve allelic values from mapping_pop_values
        query = this.getSession().createSQLQuery(MappingPopValuesDAO.GET_ALLELIC_VALUES_BY_GID_LOCAL);
        query.setParameterList("gidList", gids);
        results = query.list();
        allelicValues.addAll(this.getAllelicValueElementsFromListLocal(results));

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

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

License:Open Source License

/**
 * Get list of marker names by marker ids.
 *
 * @param ids the ids// w  w  w.  ja v a2s. com
 * @return the names by ids
 * @ the MiddlewareQueryException
 */
public List<MarkerIdMarkerNameElement> getNamesByIds(final List<Integer> ids) {

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

    try {
        final SQLQuery query = this.getSession().createSQLQuery(MarkerDAO.GET_NAMES_BY_IDS);
        query.setParameterList("markerIdList", ids);

        final List<MarkerIdMarkerNameElement> dataValues = new ArrayList<>();
        final List<Object> results = query.list();

        for (final Object o : results) {
            final Object[] result = (Object[]) o;
            if (result != null) {
                final Integer id = (Integer) result[0];
                final String name = (String) result[1];
                final MarkerIdMarkerNameElement elem = new MarkerIdMarkerNameElement(id, name);
                dataValues.add(elem);
            }
        }

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

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

License:Open Source License

public Map<Integer, String> getNamesByIdsMap(final List<Integer> ids) {
    final Map<Integer, String> dataValues = new HashMap<>();
    if (ids == null || ids.isEmpty()) {
        return dataValues;
    }// ww  w  . j  a  va  2  s. c  om

    try {
        final SQLQuery query = this.getSession().createSQLQuery(MarkerDAO.GET_NAMES_BY_IDS);
        query.setParameterList("markerIdList", ids);

        final List<Object> results = query.list();

        for (final Object o : results) {
            final Object[] result = (Object[]) o;
            if (result != null) {
                final Integer id = (Integer) result[0];
                final String name = (String) result[1];
                dataValues.put(id, name);
            }
        }

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

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

License:Open Source License

public List<Marker> getMarkersByIds(final List<Integer> markerIds, final int start, final int numOfRows) {
    if (markerIds == null || markerIds.isEmpty()) {
        return new ArrayList<>();
    }/*  www.j  av  a 2  s.  co  m*/

    try {
        final SQLQuery query = this.getSession().createSQLQuery(MarkerDAO.GET_MARKERS_BY_IDS);
        query.setParameterList("markerIdList", markerIds);
        query.setFirstResult(start);
        query.setMaxResults(numOfRows);
        final List results = query.list();

        final List<Marker> dataValues = new ArrayList<>();
        for (final Object o : results) {
            final Object[] result = (Object[]) o;
            if (result != null) {
                dataValues.add(this.convertToMarker(result));
            }
        }
        return dataValues;
    } catch (final HibernateException e) {
        LOG.error(e.getMessage(), e);
        throw new MiddlewareQueryException("Error with getMarkersByIds() query from Marker: " + e.getMessage(),
                e);
    }
}

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

License:Open Source License

public long countMarkersByIds(final List<Integer> markerIds) {
    if (markerIds == null || markerIds.isEmpty()) {
        return 0;
    }/*from   w  w  w. ja v  a2  s  .co m*/
    try {
        final SQLQuery query = this.getSession().createSQLQuery(MarkerDAO.COUNT_MARKERS_BY_IDS);
        query.setParameterList("markerIdList", markerIds);
        final BigInteger result = (BigInteger) query.uniqueResult();
        if (result != null) {
            return result.longValue();
        } else {
            return 0L;
        }
    } catch (final HibernateException e) {
        LOG.error(e.getMessage(), e);
        throw new MiddlewareQueryException(
                "Error with countMarkersByIds() query from Marker: " + e.getMessage(), e);
    }
}

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

License:Open Source License

public List<String> getMarkerNamesByIds(final List<Integer> markerIds) {
    if (markerIds == null || markerIds.isEmpty()) {
        return new ArrayList<>();
    }//from   w w w .j a v  a  2s . c  o  m

    try {
        final StringBuilder sql = new StringBuilder()
                .append("SELECT CONCAT(marker_name, '') FROM gdms_marker WHERE marker_id IN (:markerIds) ");

        final SQLQuery query = this.getSession().createSQLQuery(sql.toString());
        query.setParameterList("markerIds", markerIds);
        return query.list();
    } catch (final HibernateException e) {
        LOG.error(e.getMessage(), e);
        throw new MiddlewareQueryException(
                "Error with getMarkerNamesByIds() query from Marker: " + e.getMessage(), e);
    }
}

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

License:Open Source License

@SuppressWarnings("rawtypes")
public List<MarkerInfo> getByMarkerIds(List<Integer> markerList) throws MiddlewareQueryException {
    if (markerList == null || markerList.isEmpty()) {
        return new ArrayList<MarkerInfo>();
    }//from  w w w. j  av a 2 s  . co m

    try {
        SQLQuery query = this.getSession().createSQLQuery(MarkerInfoDAO.GET_BY_MARKER_ID);
        query.setParameterList("markerList", markerList);

        List results = query.list();

        ArrayList<MarkerInfo> toReturn = new ArrayList<MarkerInfo>();
        for (Object o : results) {
            Object[] result = (Object[]) o;
            if (result != null) {
                toReturn.add(this.convertFromObject(result));
            }
        }
        return toReturn;

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

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Integer> getMarkersBySampleIdAndDatasetIds(final Integer sampleId, final List<Integer> datasetIds,
        final int start, final int numOfRows) throws MiddlewareQueryException {
    List<Integer> markerIds = new ArrayList<Integer>();

    try {//from  w  w  w .j  a v  a 2s . com
        if (sampleId != null && datasetIds != null) {
            SQLQuery query = this.getSession()
                    .createSQLQuery(MarkerMetadataSetDAO.GET_MARKERS_BY_SAMPLEID_AND_DATASETS);
            query.setParameterList("datasetids", datasetIds);
            query.setParameter("sampleId", sampleId);
            query.setFirstResult(start);
            query.setMaxResults(numOfRows);

            markerIds = query.list();
        } else {
            return new ArrayList<Integer>();
        }
    } catch (HibernateException e) {
        this.logAndThrowException("Error with getMarkersBySampleIdAndDatasetIds(sampleID=" + sampleId
                + ", datasetIds=" + datasetIds + ") query from MarkerMetadataSet: " + e.getMessage(), e);
    }
    return markerIds;
}

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

License:Open Source License

public long countMarkersBySampleIdAndDatasetIds(final Integer sampleId, final List<Integer> datasetIds)
        throws MiddlewareQueryException {
    long count = 0;
    try {/*from  w w w  .  ja  v  a2 s . c om*/
        if (sampleId != null) {
            SQLQuery query = this.getSession()
                    .createSQLQuery(MarkerMetadataSetDAO.COUNT_MARKERS_BY_SAMPLEID_AND_DATASETS);
            query.setParameterList("datasetids", datasetIds);
            query.setParameter("sampleId", sampleId);
            BigInteger result = (BigInteger) query.uniqueResult();
            if (result != null) {
                count = result.longValue();
            }
        }
    } catch (HibernateException e) {
        this.logAndThrowException("Error with countMarkersBySampleIdAndDatasetIds(sampleId=" + sampleId
                + ", datasetIds=" + datasetIds + ") query from MarkerMetadataSet: " + e.getMessage(), e);
    }
    return count;
}

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

License:Open Source License

public long countByDatasetIds(final List<Integer> datasetIds) throws MiddlewareQueryException {
    long count = 0;
    try {/* w  w w. j a v a2  s  . c  om*/
        if (datasetIds != null && !datasetIds.isEmpty()) {
            SQLQuery query = this.getSession().createSQLQuery(MarkerMetadataSetDAO.COUNT_MARKER_BY_DATASET_IDS);
            query.setParameterList("datasetIds", datasetIds);
            BigInteger result = (BigInteger) query.uniqueResult();
            if (result != null) {
                count = result.longValue();
            }
        }

    } catch (HibernateException e) {
        this.logAndThrowException("Error with countByDatasetIds=" + datasetIds
                + ") query from MarkerMetadataSet: " + e.getMessage(), e);
    }
    return count;
}