Example usage for org.hibernate Criteria uniqueResult

List of usage examples for org.hibernate Criteria uniqueResult

Introduction

In this page you can find the example usage for org.hibernate Criteria uniqueResult.

Prototype

public Object uniqueResult() throws HibernateException;

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

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

License:Open Source License

public Unit getUnitByName(String name) {
    Criteria criteria = getSession().createCriteria(Unit.class);
    criteria.add(Restrictions.eq("name", name));
    return (Unit) criteria.uniqueResult();
}

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

License:Open Source License

public Biospecimen getBiospecimenByUid(String biospecimenUid, final Study study) {
    Criteria criteria = getSession().createCriteria(Biospecimen.class);
    criteria.add(Restrictions.eq("biospecimenUid", biospecimenUid));
    if (study != null) {
        criteria.add(Restrictions.eq("study", study));
    }//from w ww. j  av  a  2s  .  c om
    return (Biospecimen) criteria.uniqueResult();
}

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

License:Open Source License

/**
 * TODO this should use a real fkey// w  w w. j  a va  2s. c  o m
 * @param studyNameKy
 * @return
 */
public Integer getUidAndIncrement(String studyNameKy, int numToInsert) {
    Criteria criteria = getSession().createCriteria(BiospecimenUidSequence.class);
    criteria.add(Restrictions.eq("studyNameId", studyNameKy));
    BiospecimenUidSequence seqData = (BiospecimenUidSequence) criteria.uniqueResult();
    if (seqData == null) {
        log.warn("sequence does not exist...creating");
        BiospecimenUidSequence seq = new BiospecimenUidSequence();
        seq.setInsertLock(false);
        seq.setStudyNameId(studyNameKy);
        seq.setUidSequence(numToInsert);
        getSession().persist(seq);
        getSession().flush();
        return new Integer(0);
    } else {
        //log.warn("so we hav a seq");
        int currentSeqNumber = seqData.getUidSequence();
        seqData.setUidSequence((currentSeqNumber + numToInsert));
        getSession().update(seqData);
        getSession().flush();
        return currentSeqNumber;//TODO ...perhaps this should be handled transactionally in one class, and probably with generators...although this isnt really even a key
    }
}

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

License:Open Source License

public BioTransaction getBioTransaction(Long id) throws EntityNotFoundException, ArkSystemException {
    Criteria criteria = getSession().createCriteria(BioTransaction.class);
    criteria.add(Restrictions.eq("id", id));

    BioTransaction bioTransaction = (BioTransaction) criteria.uniqueResult();
    if (bioTransaction.getId() == null) {
        throw new EntityNotFoundException("The entity with id" + id.toString() + " cannot be found.");
    }/*from w ww  .  j a va  2 s  .c o  m*/

    return bioTransaction;
}

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

License:Open Source License

public long getBioTransactionCount(BioTransaction bioTransaction) {
    // Handle for biospecimen not in context
    if (bioTransaction.getBiospecimen() == null) {
        return 0L;
    }// ww  w. j  a v a 2s. com
    Criteria criteria = buildBioTransactionCriteria(bioTransaction);
    criteria.setProjection(Projections.rowCount());

    return (Long) criteria.uniqueResult();
}

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

License:Open Source License

public BioTransactionStatus getBioTransactionStatusByName(String statusName) {
    Criteria criteria = getSession().createCriteria(BioTransactionStatus.class);
    criteria.add(Restrictions.eq("name", statusName));
    BioTransactionStatus result = (BioTransactionStatus) criteria.uniqueResult();
    return result;
}

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

License:Open Source License

public boolean boxesExist() {
    Criteria criteria = getSession().createCriteria(InvBox.class);
    criteria.setProjection(Projections.count("id"));
    Long count = (Long) criteria.uniqueResult();
    return count > 0L;
}

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

License:Open Source License

public boolean hasAllocatedCells(InvBox invBox) {
    Criteria criteria = getSession().createCriteria(InvCell.class);
    criteria.add(Restrictions.eq("invBox", invBox));
    criteria.add(Restrictions.isNotNull("biospecimen"));
    criteria.setProjection(Projections.count("id"));
    Long count = (Long) criteria.uniqueResult();
    return count > 0L;
}

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

License:Open Source License

public InvCell getInvCellByLocationNames(String siteName, String freezerName, String rackName, String boxName,
        String row, String column) throws ArkSystemException {
    InvCell invCell = new InvCell();
    if ((siteName == null || freezerName == null || rackName == null || boxName == null || row == null
            || column == null)// ww w.  j a v  a 2 s . c  o  m
            || (siteName.isEmpty() || freezerName.isEmpty() || rackName.isEmpty() || boxName.isEmpty()
                    || row.isEmpty() || column.isEmpty())) {
        return invCell;
    }
    Long rowno;
    Long colno;

    if (StringUtils.isNumeric(row)) {
        rowno = new Long(row);
    } else {
        row = row.toUpperCase();
        char c = (char) row.charAt(0);
        rowno = (long) ((char) row.charAt(0) - 64);
    }

    if (StringUtils.isNumeric(column)) {
        colno = new Long(column);
    } else {
        column = column.toUpperCase();
        char c = (char) column.charAt(0);
        colno = (long) ((char) column.charAt(0) - 64);
    }

    Criteria criteria = getSession().createCriteria(InvCell.class);
    criteria.createAlias("invBox", "box", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("box.invRack", "rack", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("rack.invFreezer", "freezer", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("freezer.invSite", "site", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("biospecimen", "b", JoinType.LEFT_OUTER_JOIN);
    criteria.add(Restrictions.eq("site.name", siteName));
    criteria.add(Restrictions.eq("freezer.name", freezerName));
    criteria.add(Restrictions.eq("rack.name", rackName));
    criteria.add(Restrictions.eq("box.name", boxName));
    criteria.add(Restrictions.eq("rowno", rowno));
    criteria.add(Restrictions.eq("colno", colno));

    invCell = (InvCell) criteria.uniqueResult();
    return invCell;
}

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

License:Open Source License

/**
 * Get invSite by name//  ww  w  . j  a v  a 2 s.  c om
 * @param siteName
 * @return
 */
public InvSite getInvSiteByname(String siteName) {
    Criteria criteria = getSession().createCriteria(InvSite.class);
    if (siteName != null && !siteName.isEmpty()) {
        criteria.add(Restrictions.eq("name", siteName));
    }
    return (InvSite) criteria.uniqueResult();
}