Example usage for org.hibernate Query setParameter

List of usage examples for org.hibernate Query setParameter

Introduction

In this page you can find the example usage for org.hibernate Query setParameter.

Prototype

@SuppressWarnings("unchecked")
Query<R> setParameter(int position, Object val);

Source Link

Document

Bind a positional query parameter using its inferred Type.

Usage

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

@Deprecated
public List<CustomFieldDisplay> getSelectedPhenoCustomFieldDisplaysForSearch(Search search) {
    String queryString = "select cfds.customFieldDisplay " + " from CustomFieldDisplaySearch cfds "
            + " where cfds.search=:search "
            + " and cfds.customFieldDisplay.customField.arkFunction=:arkFunction ";// +
    // " order by cfds.customFieldDisplay.customFieldGroup.name ";
    Query query = getSession().createQuery(queryString);
    query.setParameter("search", search);
    query.setParameter("arkFunction", getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_PHENO_COLLECTION));

    return query.list();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public List<PhenoDataSetFieldDisplay> getSelectedPhenoDataSetFieldDisplaysForSearch(Search search) {
    String queryString = "select pdfds.phenoDataSetFieldDisplay "
            + " from PhenoDataSetFieldDisplaySearch pdfds " + "where pdfds.search=:search "
            + " and pdfds.phenoDataSetFieldDisplay.phenoDataSetField.arkFunction=:arkFunction";
    Query query = getSession().createQuery(queryString);
    query.setParameter("search", search);
    query.setParameter("arkFunction", getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_DATA_DICTIONARY));
    return query.list();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public List<CustomFieldDisplay> getSelectedSubjectCustomFieldDisplaysForSearch(Search search) {
    String queryString = "select cfds.customFieldDisplay " + " from CustomFieldDisplaySearch cfds "
            + " where cfds.search=:search "
            + " and cfds.customFieldDisplay.customField.arkFunction=:arkFunction";
    Query query = getSession().createQuery(queryString);
    query.setParameter("search", search);
    query.setParameter("arkFunction", getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD));
    return query.list();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public List<CustomFieldDisplay> getSelectedBiospecimenCustomFieldDisplaysForSearch(Search search) {
    String queryString = "select cfds.customFieldDisplay " + " from CustomFieldDisplaySearch cfds "
            + " where cfds.search=:search "
            + " and cfds.customFieldDisplay.customField.arkFunction=:arkFunction";
    Query query = getSession().createQuery(queryString);
    query.setParameter("search", search);
    query.setParameter("arkFunction", getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_BIOSPECIMEN));
    return query.list();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public List<CustomFieldDisplay> getAllSelectedCustomFieldDisplaysForSearch(Search search) {
    String queryString = "select cfds.customFieldDisplay " + " from CustomFieldDisplaySearch cfds "
            + " where cfds.search=:search ";
    Query query = getSession().createQuery(queryString);
    query.setParameter("search", search);
    return query.list();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public List<CustomFieldDisplay> getSelectedBiocollectionCustomFieldDisplaysForSearch(Search search) {
    String queryString = "select cfds.customFieldDisplay " + " from CustomFieldDisplaySearch cfds "
            + " where cfds.search=:search "
            + " and cfds.customFieldDisplay.customField.arkFunction=:arkFunction";
    Query query = getSession().createQuery(queryString);
    query.setParameter("search", search);
    //query.setParameter("arkFunction", getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_LIMS_COLLECTION));
    query.setParameter("arkFunction", getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD));
    return query.list();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

private Collection<String> getBiospecimenUIDsNotMatchingTheseBiospecimenIdsOrSubjectIds(Study study,
        Collection<String> biospecimenUIDs, List<Long> biospecimenIds, List<Long> biocollectionIds,
        List<Long> subjectIds) {

    Query query = null;
    //if there is nothing to start with get out of here.
    if (biospecimenUIDs.isEmpty()) {
        return new ArrayList<String>();
    }//from  ww  w. j a v a  2s.  co m

    //if there is nothing to reduce the list by...return original list.
    if (biospecimenIds.isEmpty() || subjectIds.isEmpty() || biocollectionIds.isEmpty()) {
        return biospecimenUIDs;
    } else {
        String queryString = " select distinct biospecimen.biospecimenUid " + " from Biospecimen biospecimen "
                + " where " + " ( "
                + (biospecimenIds.isEmpty() ? "" : " biospecimen.id not in (:biospecidList) or ")
                + (biocollectionIds.isEmpty() ? ""
                        : " biospecimen.bioCollection.id not in (:biocollectionIds) or ")
                + (subjectIds.isEmpty() ? "" : " biospecimen.linkSubjectStudy.id not in (:subjectIdList)  ")
                + " ) " + " and biospecimen.biospecimenUid in (:uidList) " + " and biospecimen.study =:study ";
        query = getSession().createQuery(queryString);
        if (!biospecimenIds.isEmpty())
            query.setParameterList("biospecidList", biospecimenIds);
        if (!biocollectionIds.isEmpty())
            query.setParameterList("biocollectionIds", biocollectionIds);
        if (!subjectIds.isEmpty())
            query.setParameterList("subjectIdList", subjectIds);
        query.setParameter("study", study);
        query.setParameterList("uidList", biospecimenUIDs);
        return query.list();
    }
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

private Collection<String> getBioCollectionUIDsNotMatchingTheseBioCollectionIdsOrSubjectIds(Study study,
        Collection<String> bioCollectionUIDs, List<Long> bioCollectionIds, List<Long> subjectIds,
        List<Long> biospecimenIds, List<QueryFilter> biospecimenFilters) {

    Query query = null;
    //      Query query2 = null;
    //if there is nothing to start with get out of here.
    if (bioCollectionUIDs.isEmpty()) {
        return new ArrayList<String>();
    }//from  w  w w .j  a  va 2s .com

    //if there is nothing to reduce the list by...return original list.
    if ((bioCollectionIds.isEmpty() && subjectIds.isEmpty())) {
        return bioCollectionUIDs;
    } else {
        List<Long> subjectIdsNew = new ArrayList<Long>();
        //add a dummy value=0 to get rid of ".QuerySyntaxException: unexpected end of subtree" due to empty list.
        subjectIds.add(new Long(0));
        String queryString = " select distinct bioCollection.biocollectionUid "
                + " from BioCollection bioCollection " + " where (" + " bioCollection.id not in (:idList) or "
                + " bioCollection.linkSubjectStudy.id not in (:subjectIdList) ) and "
                + " bioCollection.biocollectionUid in (:uidList) " + " and bioCollection.study =:study ";
        query = getSession().createQuery(queryString);
        if (!bioCollectionIds.isEmpty())
            query.setParameterList("idList", bioCollectionIds);
        if (!subjectIds.isEmpty())
            query.setParameterList("subjectIdList", subjectIds);
        else {
            query.setParameterList("subjectIdList", subjectIdsNew);
        }
        query.setParameter("study", study);
        query.setParameterList("uidList", bioCollectionUIDs);
        log.info("Query String: " + query.getQueryString());
        List<String> collectionsToDelete = query.list();

        if (biospecimenIds.isEmpty()) {
            //if all biospecimens WERE filtered, then all biocollections deleted
            if (!biospecimenFilters.isEmpty()) {
                return bioCollectionUIDs;
            } else {
                //there were no biospec filters...continue as usual
                return collectionsToDelete;
            }
        } else {
            if (!bioCollectionUIDs.isEmpty() && !subjectIds.isEmpty()) {

                if (!biospecimenFilters.isEmpty()) {
                    List<String> biocollectionsCorrespondingOurFilteredBiospecimens = getBiocollectionUIDsForTheseBiospecimens(
                            biospecimenIds, collectionsToDelete, study);
                    for (String biocollectionUid : bioCollectionUIDs) {
                        if (!biocollectionsCorrespondingOurFilteredBiospecimens.contains(biocollectionUid)) {
                            collectionsToDelete.add(biocollectionUid);
                        }
                    }
                }
            }
        }
        return collectionsToDelete;
    }

}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

/**
 * /*from w  ww . j a  va2 s  . c  o  m*/
 * @param biospecimenIds 
 * @param collectionsToExclude DO NOT RETURN ANY OF THESE
 * @return
 */
private List<String> getBiocollectionUIDsForTheseBiospecimens(List<Long> biospecimenIds,
        List<String> collectionsToExclude, Study study) {
    if (biospecimenIds == null) {
        return new ArrayList<String>();
    } else {
        Query query2 = null;
        String queryString2 = "Select distinct biospecimen.bioCollection.biocollectionUid  "
                + " from  Biospecimen biospecimen " + " where " + " biospecimen.id in (:biospecimenIds)  "
                + "  and biospecimen.study =:study  ";
        query2 = getSession().createQuery(queryString2);
        query2.setParameterList("biospecimenIds", biospecimenIds);
        query2.setParameter("study", study);

        return query2.list();
    }

}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

@Override
public List<FamilyCustomFieldData> getfamilyCustomFieldDataFor(Study study,
        Collection customFieldDisplaysThatWeNeed, List familyUidsToBeIncluded) {
    if (customFieldDisplaysThatWeNeed == null || customFieldDisplaysThatWeNeed.isEmpty()
            || familyUidsToBeIncluded == null || familyUidsToBeIncluded.isEmpty()) {
        return new ArrayList<FamilyCustomFieldData>();
    } else {/*from  w  ww  .ja v a  2 s .  c o m*/
        String queryString = "select fcfd from FamilyCustomFieldData fcfd where fcfd.familyUid in (:familyUidsToBeIncluded) "
                + " and fcfd.customFieldDisplay in (:customFieldDisplaysThatWeNeed) and fcfd.study=:study";
        Query query = getSession().createQuery(queryString);
        query.setParameterList("familyUidsToBeIncluded", familyUidsToBeIncluded);
        query.setParameterList("customFieldDisplaysThatWeNeed", customFieldDisplaysThatWeNeed);
        query.setParameter("study", study);
        return query.list();

    }
}