List of usage examples for org.hibernate SQLQuery uniqueResult
R uniqueResult();
From source file:org.generationcp.middleware.dao.dms.GeolocationPropertyDao.java
License:Open Source License
@SuppressWarnings("unchecked") public String getValueOfTrialInstance(final int datasetId, final int typeId, final String trialInstance) { try {//w ww . j a v a 2 s. co m final StringBuilder sql = new StringBuilder().append("SELECT gp.value FROM nd_geolocationprop gp ") .append(" INNER JOIN nd_geolocation g ON g.nd_geolocation_id = gp.nd_geolocation_id ") .append(" AND g.description = ").append(trialInstance) .append(" INNER JOIN nd_experiment e ON e.nd_geolocation_id = g.nd_geolocation_id ") .append(" WHERE gp.type_id = ").append(typeId).append(" AND e.project_id = ") .append(datasetId); final SQLQuery query = this.getSession().createSQLQuery(sql.toString()); return (String) query.uniqueResult(); } catch (final HibernateException e) { throw new MiddlewareQueryException("Error at getValueOfTrialInstance=" + datasetId + " query on GeolocationPropertyDao: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.dms.PhenotypeDao.java
License:Open Source License
public long countObservationForTraits(final List<Integer> traitIds, final List<Integer> environmentIds) { try {/*w ww .ja v a 2 s . c o m*/ final SQLQuery query = this.getSession().createSQLQuery(PhenotypeDao.COUNT_OBSERVATIONS); query.setParameterList(TRAIT_IDS, traitIds); query.setParameterList("environmentIds", environmentIds); return ((BigInteger) query.uniqueResult()).longValue(); } catch (final HibernateException e) { throw new MiddlewareQueryException( "Error at countObservationForTraits() query on PhenotypeDao: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.dms.PhenotypeDao.java
License:Open Source License
public long countPhenotypes(final PhenotypeSearchRequestDTO requestDTO) { final StringBuilder queryString = new StringBuilder(PhenotypeQuery.PHENOTYPE_SEARCH); addPhenotypeSearchFilter(requestDTO, queryString); final SQLQuery query = this.getSession().createSQLQuery("SELECT COUNT(1) FROM (" + queryString + ") T"); addPhenotypeSearchQueryParams(requestDTO, query); return ((BigInteger) query.uniqueResult()).longValue(); }
From source file:org.generationcp.middleware.dao.dms.PhenotypeDao.java
License:Open Source License
public Boolean hasOutOfSync(final Integer projectId) { final SQLQuery query = this.getSession().createSQLQuery(HAS_OUT_OF_SYNC); query.setParameter(PROJECT_ID, projectId); final BigInteger result = (BigInteger) query.uniqueResult(); return result.intValue() > 0; }
From source file:org.generationcp.middleware.dao.dms.StockDao.java
License:Open Source License
public long countStudiesByGid(final int gid) { try {/*from w w w. ja v a 2 s . c om*/ final SQLQuery query = this.getSession() .createSQLQuery("select count(distinct p.study_id) " + "FROM stock s " + "LEFT JOIN nd_experiment e on e.stock_id = s.stock_id " + "LEFT JOIN project p ON e.project_id= p.project_id " + "WHERE s.dbxref_id = " + gid + " AND p.deleted = 0"); return ((BigInteger) query.uniqueResult()).longValue(); } catch (final HibernateException e) { throw new MiddlewareQueryException( "Error in countStudiesByGid=" + gid + StockDao.IN_STOCK_DAO + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.gdms.AccMetadataSetDAO.java
License:Open Source License
public long countNIdsByMarkerIdsAndDatasetIdsAndNotGIds(List<Integer> datasetIds, List<Integer> markerIds, List<Integer> gIds) throws MiddlewareQueryException { try {//from www . ja v a 2 s . c o m if (datasetIds != null && !datasetIds.isEmpty()) { StringBuilder queryString = new StringBuilder( AccMetadataSetDAO.COUNT_NIDS_BY_DATASET_IDS_AND_MARKER_IDS_AND_NOT_GIDS_SELECT); queryString.append(AccMetadataSetDAO.GET_NIDS_BY_DATASET_IDS_AND_MARKER_IDS_AND_NOT_GIDS_FROM); if (markerIds != null && !markerIds.isEmpty()) { queryString.append(AccMetadataSetDAO.GET_NIDS_BY_DATASET_IDS_FILTER_BY_MARKER_IDS); } if (gIds != null && !gIds.isEmpty()) { queryString.append(AccMetadataSetDAO.GET_NIDS_BY_DATASET_IDS_FILTER_NOT_BY_GIDS); } queryString.append(AccMetadataSetDAO.GET_NIDS_BY_DATASET_IDS_ORDER); SQLQuery query; query = this.getSession().createSQLQuery(queryString.toString()); query.setParameterList("represnos", datasetIds); if (markerIds != null && !markerIds.isEmpty()) { query.setParameterList("markerids", markerIds); } if (gIds != null && !gIds.isEmpty()) { query.setParameterList("gids", gIds); } return ((BigInteger) query.uniqueResult()).intValue(); } } catch (HibernateException e) { throw new MiddlewareQueryException("Error with countNIDsByDatasetIdsAndMarkerIdsAndNotGIDs(datasetIds=" + datasetIds + ", markerIds=" + markerIds + ", gIds=" + gIds + ") query from AccMetadataSet: " + e.getMessage(), e); } return 0; }
From source file:org.generationcp.middleware.dao.gdms.AccMetadataSetDAO.java
License:Open Source License
public long countAccMetadataSetsByGids(List<Integer> gids) throws MiddlewareQueryException { long count = 0; try {/* w w w. java 2 s. co m*/ if (gids != null && !gids.isEmpty()) { SQLQuery query = this.getSession().createSQLQuery(AccMetadataSetDAO.COUNT_ACC_METADATASETS_BY_GIDS); query.setParameterList("gids", gids); BigInteger result = (BigInteger) query.uniqueResult(); if (result != null) { count = result.longValue(); } } } catch (HibernateException e) { throw new MiddlewareQueryException("Error with countAccMetadataSetByGids(gids=" + gids + ") query from AccMetadataSet: " + e.getMessage(), e); } return count; }
From source file:org.generationcp.middleware.dao.gdms.AccMetadataSetDAO.java
License:Open Source License
public long countSampleIdsByDatasetIds(List<Integer> datasetIds) throws MiddlewareQueryException { long count = 0; try {//from www.j a va2 s .co m if (datasetIds != null && !datasetIds.isEmpty()) { SQLQuery query = this.getSession() .createSQLQuery(AccMetadataSetDAO.COUNT_SAMPLE_IDS_BY_DATASET_IDS); query.setParameterList("datasetIds", datasetIds); BigInteger result = (BigInteger) query.uniqueResult(); if (result != null) { count = result.longValue(); } } } catch (HibernateException e) { throw new MiddlewareQueryException( "Error with countSampleIdsByDatasetIds=" + datasetIds + ") query from AccMetadataSet", e); } return count; }
From source file:org.generationcp.middleware.dao.gdms.AlleleValuesDAO.java
License:Open Source License
public long countAlleleValuesByGids(List<Integer> gids) throws MiddlewareQueryException { try {/* www .j a va 2 s . c o m*/ if (gids != null && !gids.isEmpty()) { SQLQuery query = this.getSession().createSQLQuery(AlleleValuesDAO.COUNT_ALLELE_VALUES_BY_GIDS); query.setParameterList("gids", gids); BigInteger result = (BigInteger) query.uniqueResult(); if (result != null) { return result.longValue(); } } } catch (HibernateException e) { this.logAndThrowException("Error with countAlleleValuesByGids(gids=" + gids + ") query from AlleleValues: " + e.getMessage(), e); } return 0; }
From source file:org.generationcp.middleware.dao.gdms.AlleleValuesDAO.java
License:Open Source License
public long countIntAlleleValuesForPolymorphicMarkersRetrieval(List<Integer> gids) throws MiddlewareQueryException { try {//from w w w . j ava2 s .com if (gids != null && !gids.isEmpty()) { SQLQuery query = this.getSession().createSQLQuery( AlleleValuesDAO.COUNT_INT_ALLELE_VALUES_FOR_POLYMORPHIC_MARKERS_RETRIEVAL_BY_GIDS); query.setParameterList("gids", gids); BigInteger result = (BigInteger) query.uniqueResult(); if (result != null) { return result.longValue(); } return 0; } } catch (HibernateException e) { this.logAndThrowException("Error with countCharAlleleValuesForPolymorphicMarkersRetrieval(gids=" + gids + ") query from AlleleValues: " + e.getMessage(), e); } return 0; }