Example usage for org.hibernate Criteria add

List of usage examples for org.hibernate Criteria add

Introduction

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

Prototype

public Criteria add(Criterion criterion);

Source Link

Document

Add a Criterion restriction to constrain the results to be retrieved.

Usage

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

License:Open Source License

public List<Biospecimen> getRootBiospecimensForBiocollection(BioCollection bc) {
    Criteria criteria = getSession().createCriteria(Biospecimen.class);
    criteria.add(Restrictions.eq("bioCollection", bc));
    criteria.add(Restrictions.isNull("parent"));
    //criteria.setFetchMode("invBlah", FetchMode.JOIN);
    List<Biospecimen> list = criteria.list();
    return list;// w w  w  .  j  a  v a2s . co m
}

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

License:Open Source License

/**
 * TODO this should use a real fkey/*from   w w  w  . j  av a  2 s.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 .  co m

    return bioTransaction;
}

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

License:Open Source License

private Criteria buildBioTransactionCriteria(BioTransaction bioTransaction) {
    Criteria criteria = getSession().createCriteria(BioTransaction.class);
    // All transactions must operate on a given biospecimen
    criteria.add(Restrictions.eq("biospecimen", bioTransaction.getBiospecimen()));

    return criteria;
}

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

License:Open Source License

public List<BioTransactionStatus> getBioTransactionStatusChoices() {
    Criteria criteria = getSession().createCriteria(BioTransactionStatus.class);
    // remove Initial Quantity status choice because this is reserved
    criteria.add(
            Restrictions.ne("name", au.org.theark.lims.web.Constants.BIOTRANSACTION_STATUS_INITIAL_QUANTITY));
    return criteria.list();
}

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

License:Open Source License

public List<BioTransaction> getAllBiotransactionForBiospecimen(Biospecimen biospecimen) {
    Criteria criteria = getSession().createCriteria(BioTransaction.class);
    criteria.add(Restrictions.eq("biospecimen", biospecimen));
    List<BioTransaction> result = (List<BioTransaction>) criteria.list();
    return result;
}

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

License:Open Source License

public List<InvSite> searchInvSite(InvSite invSite) throws ArkSystemException {
    Criteria criteria = getSession().createCriteria(InvSite.class);

    if (invSite.getId() != null) {
        criteria.add(Restrictions.eq("id", invSite.getId()));
    }//from w  w  w.  j  a  v a 2s  .co m

    if (invSite.getName() != null) {
        criteria.add(Restrictions.eq("name", invSite.getName()));
    }

    if (invSite.getContact() != null) {
        criteria.add(Restrictions.eq("contact", invSite.getContact()));
    }

    if (invSite.getAddress() != null) {
        criteria.add(Restrictions.eq("address", invSite.getAddress()));
    }

    if (invSite.getPhone() != null) {
        criteria.add(Restrictions.eq("phone", invSite.getPhone()));
    }

    List<InvSite> list = criteria.list();
    return list;
}

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

License:Open Source License

public List<InvSite> searchInvSite(InvSite invSite, List<Study> studyList) throws ArkSystemException {
    List<InvSite> invSiteList = new ArrayList<InvSite>(0);

    if (studyList == null || studyList.isEmpty()) {
        return invSiteList;
    }// www. j  a  va  2 s. co m

    Criteria criteria = getSession().createCriteria(StudyInvSite.class);

    /*
     * if (invSite.getId() != null) { criteria.add(Restrictions.eq("id", invSite.getId())); }
     * 
     * if (invSite.getName() != null) { criteria.add(Restrictions.eq("name", invSite.getName())); }
     * 
     * if (invSite.getContact() != null) { criteria.add(Restrictions.eq("contact", invSite.getContact())); }
     * 
     * if (invSite.getAddress() != null) { criteria.add(Restrictions.eq("address", invSite.getAddress())); }
     * 
     * if (invSite.getPhone() != null) { criteria.add(Restrictions.eq("phone", invSite.getPhone())); }
     */
    /*if you have an empty grouping, hibernate will do this sort of this;
     * select
            this_.INV_SITE_ID as y0_ 
        from
            lims.study_inv_site this_ 
        where
            this_.STUDY_ID in (
            
            ) 
        group by
            this_.INV_SITE_ID
            ...therefore always null check before checking if something is in a group of nothing
             */
    criteria.add(Restrictions.in("study", studyList));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("invSite"), "invSite");
    criteria.setProjection(projectionList);

    // List<StudyInvSite> list = criteria.list();
    invSiteList = criteria.list();
    /*
     * for(StudyInvSite studyInvSite : list){ invSiteList.add(studyInvSite.getInvSite()); }
     */
    return invSiteList;
}

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

License:Open Source License

public InvSite getInvSite(Long id) {
    InvSite invSite = new InvSite();
    Criteria criteria = getSession().createCriteria(InvSite.class);

    if (id != null) {
        criteria.add(Restrictions.eq("id", id));
    }//from   w w w . j  av a  2  s  .  c o m

    List<InvSite> list = criteria.list();
    if (!list.isEmpty()) {
        invSite = (InvSite) list.get(0);
    }
    return invSite;
}