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

@Override
public List<CustomFieldDisplay> getCustomFieldDisplaysInWithCustomFieldType(List<String> fieldNameCollection,
        Study study, ArkFunction arkFunction, CustomFieldType customFieldType) {
    if (fieldNameCollection == null || fieldNameCollection.isEmpty()) {
        return new ArrayList<CustomFieldDisplay>();
    } else {//from w w  w .  j  av  a  2 s .c o  m
        List<String> lowerCaseNames = new ArrayList<String>();
        for (String name : fieldNameCollection) {
            lowerCaseNames.add(name.toLowerCase());
        }
        String queryString = "select cfd " + "from CustomFieldDisplay cfd " + "where customField.id in ( "
                + " SELECT id from CustomField cf " + " where cf.study =:study "
                + " and lower(cf.name) in (:names) "
                + " and cf.arkFunction =:arkFunction and cf.customFieldType=:customFieldType )";
        Query query = getSession().createQuery(queryString);
        query.setParameter("study", study);
        // query.setParameterList("names", fieldNameCollection);
        query.setParameterList("names", lowerCaseNames);
        query.setParameter("arkFunction", arkFunction);
        query.setParameter("customFieldType", customFieldType);
        return query.list();
    }
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public List<BioCollectionCustomFieldData> getBioCollectionCustomFieldDataList(
        BioCollection bioCollectionCriteria, ArkFunction arkFunction, int first, int count) {
    List<BioCollectionCustomFieldData> bioCollectionCustomFieldDataList = new ArrayList<BioCollectionCustomFieldData>();

    StringBuffer sb = new StringBuffer();
    sb.append(" FROM  CustomFieldDisplay AS cfd ");
    sb.append("LEFT JOIN cfd.bioCollectionCustomFieldData as fieldList ");
    sb.append(" with fieldList.bioCollection.id = :bioCollectionId ");
    sb.append("  WHERE cfd.customField.study.id IN (:studyId)");
    sb.append(" AND cfd.customField.arkFunction.id = :functionId");
    sb.append(" ORDER BY cfd.sequence");

    Query query = getSession().createQuery(sb.toString());
    query.setParameter("bioCollectionId", bioCollectionCriteria.getId());

    // Allow child studies to inherit parent defined custom fields
    List studyList = new ArrayList();
    studyList.add(bioCollectionCriteria.getStudy().getId());
    if (bioCollectionCriteria.getStudy().getParentStudy() != null
            && bioCollectionCriteria.getStudy().getParentStudy() != bioCollectionCriteria.getStudy()) {
        studyList.add(bioCollectionCriteria.getStudy().getParentStudy().getId());
    }//w ww  .  j ava2s.c o  m
    query.setParameterList("studyId", studyList);
    query.setParameter("functionId", arkFunction.getId());
    query.setFirstResult(first);
    query.setMaxResults(count);

    List<Object[]> listOfObjects = query.list();
    for (Object[] objects : listOfObjects) {
        CustomFieldDisplay cfd = new CustomFieldDisplay();
        BioCollectionCustomFieldData bccfd = new BioCollectionCustomFieldData();
        if (objects.length > 0 && objects.length >= 1) {

            cfd = (CustomFieldDisplay) objects[0];
            if (objects[1] != null) {
                bccfd = (BioCollectionCustomFieldData) objects[1];
            } else {
                bccfd.setCustomFieldDisplay(cfd);
            }
            bioCollectionCustomFieldDataList.add(bccfd);
        }
    }
    return bioCollectionCustomFieldDataList;
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public BioCollectionCustomFieldData getBioCollectionCustomFieldData(BioCollection bioCollectionCriteria,
        ArkFunction arkFunction, String customFieldName) {
    StringBuffer sb = new StringBuffer();
    sb.append(" FROM  CustomFieldDisplay AS cfd ");
    sb.append("LEFT JOIN cfd.bioCollectionCustomFieldData as fieldList ");
    sb.append(" WITH fieldList.bioCollection.id = :bioCollectionId ");
    sb.append("  WHERE cfd.customField.study.id IN (:studyId)");
    sb.append(" AND cfd.customField.arkFunction.id = :functionId");
    sb.append(" AND cfd.customField.name = :customFieldName");
    sb.append(" ORDER BY cfd.sequence");

    Query query = getSession().createQuery(sb.toString());
    query.setParameter("bioCollectionId", bioCollectionCriteria.getId());

    // Allow child studies to inherit parent defined custom fields
    List studyList = new ArrayList();
    studyList.add(bioCollectionCriteria.getStudy().getId());
    if (bioCollectionCriteria.getStudy().getParentStudy() != null
            && bioCollectionCriteria.getStudy().getParentStudy() != bioCollectionCriteria.getStudy()) {
        studyList.add(bioCollectionCriteria.getStudy().getParentStudy().getId());
    }//from   w w  w . j  a  v  a  2 s  .  co m
    query.setParameterList("studyId", studyList);

    query.setParameter("functionId", arkFunction.getId());
    query.setParameter("customFieldName", customFieldName);

    BioCollectionCustomFieldData bccfd = new BioCollectionCustomFieldData();
    List<Object[]> listOfObjects = query.list();
    for (Object[] objects : listOfObjects) {
        CustomFieldDisplay cfd = new CustomFieldDisplay();

        if (objects.length > 0 && objects.length >= 1) {

            cfd = (CustomFieldDisplay) objects[0];
            if (objects[1] != null) {
                bccfd = (BioCollectionCustomFieldData) objects[1];
            } else {
                bccfd.setCustomFieldDisplay(cfd);
            }
        }
    }
    return bccfd;
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public Long isCustomFieldUsed(BioCollectionCustomFieldData bioCollectionCFData) {
    Long count = new Long("0");
    CustomField customField = bioCollectionCFData.getCustomFieldDisplay().getCustomField();

    // The Study//  w  w  w  .  j a v a2  s .c  om
    try {
        Long id = bioCollectionCFData.getBioCollection().getId();
        BioCollection bioCollection = getBioCollection(id);
        //Study subjectStudy = bioCollection.getStudy();
        ArkFunction arkFunction = customField.getArkFunction();

        StringBuffer stringBuffer = new StringBuffer();

        stringBuffer.append(" SELECT COUNT(*) FROM BioCollectionCustomFieldData AS bccfd WHERE EXISTS ");
        stringBuffer.append(" ( ");
        stringBuffer.append("  SELECT cfd.id ");
        stringBuffer.append("  FROM CustomFieldDisplay AS cfd ");
        stringBuffer.append("  WHERE cfd.customField.study IN (:studyId)");
        stringBuffer.append(
                "  AND cfd.customField.arkFunction.id = :functionId AND bccfd.customFieldDisplay.id = :customFieldDisplayId");
        stringBuffer.append(" )");

        String theHQLQuery = stringBuffer.toString();

        Query query = getSession().createQuery(theHQLQuery);
        //query.setParameter("studyId", subjectStudy.getId());
        List studyList = new ArrayList();
        studyList.add(bioCollection.getStudy());
        if (bioCollection.getStudy().getParentStudy() != null
                && bioCollection.getStudy().getParentStudy() != bioCollection.getStudy()) {
            studyList.add(bioCollection.getStudy().getParentStudy());
        }
        query.setParameterList("studyId", studyList);
        query.setParameter("functionId", arkFunction.getId());
        query.setParameter("customFieldDisplayId", bioCollectionCFData.getCustomFieldDisplay().getId());
        count = (Long) query.uniqueResult();

    } catch (EntityNotFoundException e) {
        //The given BioCollection is not available, this should not happen since the person is editing custom fields for the LIMS collection
        e.printStackTrace();
    }

    return count;
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public List<String> getAllBiocollectionUIDs(Study study) {
    String queryString = "select bio.biocollectionUid " + "from BioCollection bio " + "where study =:study "
            + "order by biocollectionUid ";
    Query query = getSession().createQuery(queryString);
    query.setParameter("study", study);
    return query.list();
}

From source file:au.org.theark.lims.model.dao.BiospecimenDao.java

License:Open Source License

public List<BiospecimenCustomFieldData> getBiospecimenCustomFieldDataList(Biospecimen biospecimenCriteria,
        ArkFunction arkFunction, int first, int count) {
    List<BiospecimenCustomFieldData> biospecimenCustomFieldDataList = new ArrayList<BiospecimenCustomFieldData>();

    StringBuffer sb = new StringBuffer();
    sb.append(" FROM  CustomFieldDisplay AS cfd ");
    sb.append("LEFT JOIN cfd.biospecimenCustomFieldData as fieldList ");
    sb.append(" with fieldList.biospecimen.id = :biospecimenId ");
    sb.append("  where cfd.customField.study.id IN (:studyId)");
    sb.append(" and cfd.customField.arkFunction.id = :functionId");
    sb.append(" order by cfd.sequence");

    Query query = getSession().createQuery(sb.toString());
    query.setParameter("biospecimenId", biospecimenCriteria.getId());

    // Allow child studies to inherit parent defined custom fields
    List studyList = new ArrayList();
    studyList.add(biospecimenCriteria.getStudy().getId());
    if (biospecimenCriteria.getStudy().getParentStudy() != null
            && biospecimenCriteria.getStudy().getParentStudy() != biospecimenCriteria.getStudy()) {
        studyList.add(biospecimenCriteria.getStudy().getParentStudy().getId());
    }//from w w w.  ja  va2 s . c  o m
    query.setParameterList("studyId", studyList);
    query.setParameter("functionId", arkFunction.getId());
    query.setFirstResult(first);
    query.setMaxResults(count);

    List<Object[]> listOfObjects = query.list();
    for (Object[] objects : listOfObjects) {
        CustomFieldDisplay cfd = new CustomFieldDisplay();
        BiospecimenCustomFieldData bscfd = new BiospecimenCustomFieldData();
        if (objects.length > 0 && objects.length >= 1) {

            cfd = (CustomFieldDisplay) objects[0];
            if (objects[1] != null) {
                bscfd = (BiospecimenCustomFieldData) objects[1];
            } else {
                bscfd.setCustomFieldDisplay(cfd);
            }
            biospecimenCustomFieldDataList.add(bscfd);
        }
    }
    return biospecimenCustomFieldDataList;
}

From source file:au.org.theark.lims.model.dao.BiospecimenDao.java

License:Open Source License

public Long isCustomFieldUsed(BiospecimenCustomFieldData biospecimanCFData) {
    Long count = new Long("0");
    CustomField customField = biospecimanCFData.getCustomFieldDisplay().getCustomField();

    try {//  w w w  . ja  v  a 2s. c  om

        Long id = biospecimanCFData.getBiospecimen().getId();
        Biospecimen biospecimen = getBiospecimen(id);
        Study subjectStudy = biospecimen.getStudy();
        ArkFunction arkFunction = customField.getArkFunction();

        StringBuffer stringBuffer = new StringBuffer();

        stringBuffer.append(" SELECT COUNT(*) FROM BiospecimenCustomFieldData AS bscfd WHERE EXISTS ");
        stringBuffer.append(" ( ");
        stringBuffer.append(
                " SELECT cfd.id FROM  CustomFieldDisplay AS cfd  WHERE cfd.customField.study.id = :studyId");
        stringBuffer.append(
                " AND cfd.customField.arkFunction.id = :functionId AND bscfd.customFieldDisplay.id = :customFieldDisplayId");
        stringBuffer.append(" )");

        String theHQLQuery = stringBuffer.toString();

        Query query = getSession().createQuery(theHQLQuery);
        query.setParameter("studyId", subjectStudy.getId());
        query.setParameter("functionId", arkFunction.getId());
        query.setParameter("customFieldDisplayId", biospecimanCFData.getCustomFieldDisplay().getId());
        count = (Long) query.uniqueResult();

    } catch (EntityNotFoundException e) {
        //The given Biospecimen is not available, this should not happen since the person is editing custom fields for the LIMS biospecimen
        e.printStackTrace();
    }

    return count;
}

From source file:au.org.theark.lims.model.dao.BiospecimenDao.java

License:Open Source License

public List<String> getAllBiospecimenUIDs(Study study) {
    String queryString = "select bio.biospecimenUid " + "from Biospecimen bio " + "where study =:study "
            + "order by biospecimenUid ";
    Query query = getSession().createQuery(queryString);
    query.setParameter("study", study);
    return query.list();
}

From source file:au.org.theark.lims.model.dao.InventoryDao.java

License:Open Source License

/** TODO ASAP TEST THIS */
public List<InvCell> getCellAndBiospecimenListByBox(InvBox invBox) {

    StringBuffer sb = new StringBuffer();
    sb.append(" select cell FROM  InvCell AS cell ");
    sb.append(" LEFT JOIN fetch cell.biospecimen ");
    sb.append(" WHERE cell.invBox.id = :invBoxId ");
    sb.append(" ORDER BY cell.rowno, cell.colno ");

    Query query = getSession().createQuery(sb.toString());
    query.setParameter("invBoxId", invBox.getId());

    List<InvCell> invCellList = query.list();
    return invCellList;

    /*/*w w w .jav a  2 s .co  m*/
          List<InvCell> invCellList = new ArrayList<InvCell>();
            
          StringBuffer sb = new StringBuffer();
          sb.append(" FROM  InvCell AS cell ");
          sb.append("LEFT JOIN cell.biospecimen as biospecimenList ");
          sb.append("  WHERE cell.invBox.id = :invBoxId");
          sb.append(" ORDER BY cell.rowno, cell.colno");
            
          Query query = getSession().createQuery(sb.toString());
          query.setParameter("invBoxId", invBox.getId());
            
          List<Object[]> listOfObjects = query.list();
          for (Object[] objects : listOfObjects) {
             InvCell invCell = new InvCell();
             Biospecimen biospecimen = new Biospecimen();
            
             if (objects.length > 0 && objects.length >= 1) {
    invCell = (InvCell) objects[0];
    if (objects[1] != null) {
       biospecimen = (Biospecimen) objects[1];
       invCell.setBiospecimen(biospecimen);
    }
    invCellList.add(invCell);
             }
          }
            
          return invCellList;*/
}

From source file:au.org.theark.lims.model.dao.InventoryDao.java

License:Open Source License

public BiospecimenLocationVO getBiospecimenLocation(Biospecimen biospecimen) {
    BiospecimenLocationVO biospecimenLocationVo = new BiospecimenLocationVO();

    StringBuilder hqlString = new StringBuilder();
    hqlString.append(/*from  w w  w .ja va  2s .c  o m*/
            "SELECT site.name AS siteName, freezer.name as freezerName, rack.name AS rackName, box.name AS boxName, cell.colno AS column, cell.rowno AS row, box.colnotype.name AS colNoType, box.rownotype.name AS rowNoType \n");
    hqlString.append("FROM InvCell AS cell \n");
    hqlString.append("LEFT JOIN cell.invBox AS box \n");
    hqlString.append("LEFT JOIN box.invRack AS rack \n");
    hqlString.append("LEFT JOIN rack.invFreezer AS freezer \n");
    hqlString.append("LEFT JOIN freezer.invSite AS site \n");
    hqlString.append("WHERE cell.biospecimen = :biospecimen");

    Query q = getSession().createQuery(hqlString.toString());
    q.setParameter("biospecimen", biospecimen);
    Object[] result = (Object[]) q.uniqueResult();

    if (result != null) {
        biospecimenLocationVo.setIsAllocated(true);
        biospecimenLocationVo.setSiteName(result[0].toString());
        biospecimenLocationVo.setFreezerName(result[1].toString());
        biospecimenLocationVo.setRackName(result[2].toString());
        biospecimenLocationVo.setBoxName(result[3].toString());

        Long colno = new Long((Long) result[4]);
        Long rowno = new Long((Long) result[5]);
        biospecimenLocationVo.setColumn(colno);
        biospecimenLocationVo.setRow(rowno);

        String colNoType = result[6].toString();
        String rowNoType = result[7].toString();

        String colLabel = new String();
        if (colNoType.equalsIgnoreCase("ALPHABET")) {
            char character = (char) (colno + 64);
            colLabel = new Character(character).toString();
        } else {
            colLabel = new Integer(colno.intValue()).toString();
        }
        biospecimenLocationVo.setColLabel(colLabel);

        String rowLabel = new String();
        if (rowNoType.equalsIgnoreCase("ALPHABET")) {
            char character = (char) (rowno + 64);
            rowLabel = new Character(character).toString();
        } else {
            rowLabel = new Integer(rowno.intValue()).toString();
        }
        biospecimenLocationVo.setRowLabel(rowLabel);
    }
    return biospecimenLocationVo;
}