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

License:Open Source License

public InvCell getInvCell(InvBox invBox, long rowno, long colno) {
    InvCell invCell = null; //new InvCell();
    Criteria criteria = getSession().createCriteria(InvCell.class);

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

    criteria.add(Restrictions.eq("rowno", rowno));
    criteria.add(Restrictions.eq("colno", colno));

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

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

License:Open Source License

public Biospecimen getBiospecimenByInvCell(InvCell invCell) {
    Biospecimen biospecimen = null;/*from   ww w  .  j ava2s.com*/
    Criteria criteria = getSession().createCriteria(InvCell.class);
    criteria.add(Restrictions.eq("id", invCell.getId()));
    List<InvCell> list = criteria.list();
    if (!list.isEmpty()) {
        biospecimen = (Biospecimen) list.get(0).getBiospecimen();
    }
    return biospecimen;
}

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

License:Open Source License

public InvBox getInvBox(Long id) {
    InvBox invBox = new InvBox();
    Criteria criteria = getSession().createCriteria(InvBox.class);

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

    List<InvBox> list = criteria.list();
    if (!list.isEmpty()) {
        invBox = (InvBox) list.get(0);
    }

    if (invBox == null) {
        log.error("InvBox with ID " + id + " is no longer in the database");
    }
    return invBox;
}

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

License:Open Source License

public InvFreezer getInvFreezer(Long id) {
    InvFreezer invFreezer = new InvFreezer();
    Criteria criteria = getSession().createCriteria(InvFreezer.class);

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

    List<InvFreezer> list = criteria.list();
    if (!list.isEmpty()) {
        invFreezer = (InvFreezer) list.get(0);
    }

    if (invFreezer == null) {
        log.error("InvFreezer with ID " + id + " is no longer in the database");
    }
    return invFreezer;
}

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

License:Open Source License

public InvRack getInvRack(Long id) {
    InvRack invRack = new InvRack();
    Criteria criteria = getSession().createCriteria(InvRack.class);

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

    List<InvRack> list = criteria.list();
    if (!list.isEmpty()) {
        invRack = (InvRack) list.get(0);
    }

    if (invRack == null) {
        log.error("InvRack with ID " + id + " is no longer in the database");
    }
    return invRack;
}

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

License:Open Source License

public InvCell getInvCellByBiospecimen(Biospecimen biospecimen) {
    InvCell invCell = new InvCell();
    Criteria criteria = getSession().createCriteria(InvCell.class);

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

    List<InvCell> list = criteria.list();
    if (!list.isEmpty()) {
        invCell = (InvCell) list.get(0);
    }

    if (invCell == null) {
        log.error("InvCell with biospecimen " + biospecimen.getId() + " is no longer in the database");
    }
    return invCell;
}

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

License:Open Source License

public InvCell getInvCell(Long id) {
    InvCell invCell = new InvCell();
    Criteria criteria = getSession().createCriteria(InvCell.class);

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

    List<InvCell> list = criteria.list();
    if (!list.isEmpty()) {
        invCell = (InvCell) list.get(0);
    }

    if (invCell == null) {
        log.error("InvRack with ID " + id + " is no longer in the database");
    }
    return invCell;
}

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

License:Open Source License

public List<InvBox> searchInvBox(InvBox invBox) throws ArkSystemException {
    Criteria criteria = getSession().createCriteria(InvBox.class);

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

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

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

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)/*from   ww w .  jav  a2 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;
}