List of usage examples for org.hibernate.criterion Restrictions ne
public static SimpleExpression ne(String propertyName, Object value)
From source file:org.generationcp.middleware.dao.GermplasmListDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<GermplasmList> getByProjectIdAndType(final int projectId, final GermplasmListType type) { final List<GermplasmList> list = new ArrayList<>(); try {// w w w. ja v a 2s . c om final Criteria criteria = this.getSession().createCriteria(GermplasmList.class); criteria.add(Restrictions.eq("projectId", projectId)); criteria.add(Restrictions.eq("type", type.name())); criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED)); return criteria.list(); } catch (final HibernateException e) { final String errorMessage = "Error with getByProjectId(projectId=" + projectId + ") query from GermplasmList: " + e.getMessage(); GermplasmListDAO.LOG.error(errorMessage); throw new MiddlewareQueryException(errorMessage, e); } }
From source file:org.generationcp.middleware.dao.GermplasmListDAO.java
License:Open Source License
public boolean hasAdvancedOrCrossesList(final int projectId) { try {//from www. j a v a 2 s .c o m final Criteria criteria = this.getSession().createCriteria(GermplasmList.class); criteria.add(Restrictions.eq("projectId", projectId)); criteria.add(Restrictions.in("type", Arrays.asList(GermplasmListType.ADVANCED.name(), GermplasmListType.IMP_CROSS.name(), GermplasmListType.CRT_CROSS.name()))); criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED)); return ((Number) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue() > 0; } catch (final HibernateException e) { final String errorMessage = "Error with hasAdvancedOrCrossesList(projectId=" + projectId + ") query from GermplasmList: " + e.getMessage(); GermplasmListDAO.LOG.error(errorMessage); throw new MiddlewareQueryException(errorMessage, e); } }
From source file:org.generationcp.middleware.dao.GermplasmListDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<GermplasmList> getListsByProgramUUID(final String programUUID) { final Criteria criteria = this.getSession().createCriteria(GermplasmList.class); criteria.add(Restrictions.eq(GermplasmListDAO.PROGRAM_UUID, programUUID)); criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED)); this.hideSnapshotListTypes(criteria); return criteria.list(); }
From source file:org.generationcp.middleware.dao.GermplasmListDAO.java
License:Open Source License
/** * @param listIds/*from ww w. ja va 2 s . c o m*/ * a group of ids for which we want to retrieve germplasm list * @return the resultant germplasm list */ public List<GermplasmList> getAllGermplasmListsById(final List<Integer> listIds) { final Criteria criteria = this.getSession().createCriteria(GermplasmList.class); criteria.add(Restrictions.in("id", listIds)); criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED)); criteria.add(Restrictions.eq("type", GermplasmListType.LST.toString())); return criteria.list(); }
From source file:org.generationcp.middleware.dao.GermplasmListDataDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<GermplasmListData> getByListId(final Integer id) { // Make sure parameters are not null. Preconditions.checkNotNull(id, "List id passed in cannot be null."); final Criteria criteria = this.getSession().createCriteria(GermplasmListData.class); criteria.createAlias(GermplasmListDataDAO.GERMPLASM_LIST_NAME_TABLE, GermplasmListDataDAO.GERMPLASM_LIST_NAME_TABLE_ALIAS); criteria.createAlias(GermplasmListDataDAO.GERMPLASM_TABLE, GermplasmListDataDAO.GERMPLASM_TABLE_ALIAS); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_LIST_NAME_ID_COLUMN, id)); criteria.add(Restrictions.ne(GermplasmListDataDAO.GERMPLASM_LIST_DATA_TABLE_STATUS_COLUMN, GermplasmListDataDAO.STATUS_DELETED)); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_DELETED_COLUMN, Boolean.FALSE)); criteria.addOrder(Order.asc(GermplasmListDataDAO.GERMPLASM_LIST_DATA_ENTRY_ID_COLUMN)); final List<GermplasmListData> germplasmListDataList = criteria.list(); for (final GermplasmListData germplasmListData : germplasmListDataList) { final Germplasm germplasm = germplasmListData.getGermplasm(); if (germplasm != null) { germplasmListData.setGroupId(germplasm.getMgid()); }/*from w ww. j av a 2 s .c o m*/ } return germplasmListDataList; }
From source file:org.generationcp.middleware.dao.GermplasmListDataDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<GermplasmListData> getByIds(final List<Integer> entryIds) { // Make sure parameters are not null. Preconditions.checkNotNull(entryIds, "List entry id's passed in cannot be null."); final Criteria criteria = this.getSession().createCriteria(GermplasmListData.class); criteria.createAlias(GermplasmListDataDAO.GERMPLASM_TABLE, GermplasmListDataDAO.GERMPLASM_TABLE_ALIAS); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_DELETED_COLUMN, Boolean.FALSE)); criteria.add(Restrictions.in(GermplasmListDataDAO.GERMPLASM_LIST_DATA_ID_COLUMN, entryIds)); criteria.add(Restrictions.ne(GermplasmListDataDAO.GERMPLASM_LIST_DATA_TABLE_STATUS_COLUMN, GermplasmListDataDAO.STATUS_DELETED)); criteria.addOrder(Order.asc(GermplasmListDataDAO.GERMPLASM_LIST_DATA_ENTRY_ID_COLUMN)); return criteria.list(); }
From source file:org.generationcp.middleware.dao.GermplasmListDataDAO.java
License:Open Source License
public GermplasmListData getByListIdAndEntryId(final Integer listId, final Integer entryId) { // Make sure parameters are not null. Preconditions.checkNotNull(listId, "List id passed in cannot be null."); Preconditions.checkNotNull(entryId, "List entry id's passed in cannot be null."); final Criteria criteria = this.getSession().createCriteria(GermplasmListData.class); criteria.createAlias(GermplasmListDataDAO.GERMPLASM_LIST_NAME_TABLE, GermplasmListDataDAO.GERMPLASM_LIST_NAME_TABLE_ALIAS); criteria.createAlias(GermplasmListDataDAO.GERMPLASM_TABLE, GermplasmListDataDAO.GERMPLASM_TABLE_ALIAS); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_DELETED_COLUMN, Boolean.FALSE)); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_LIST_NAME_ID_COLUMN, listId)); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_LIST_DATA_ENTRY_ID_COLUMN, entryId)); criteria.add(Restrictions.ne(GermplasmListDataDAO.GERMPLASM_LIST_DATA_TABLE_STATUS_COLUMN, GermplasmListDataDAO.STATUS_DELETED)); criteria.addOrder(Order.asc(GermplasmListDataDAO.GERMPLASM_LIST_DATA_ENTRY_ID_COLUMN)); return (GermplasmListData) criteria.uniqueResult(); }
From source file:org.generationcp.middleware.dao.GermplasmListDataDAO.java
License:Open Source License
public GermplasmListData getByListIdAndLrecId(final Integer listId, final Integer lrecId) { // Make sure parameters are not null. Preconditions.checkNotNull(listId, "List id passed cannot be null."); Preconditions.checkNotNull(lrecId, "List record id's passed in cannot be null."); final Criteria criteria = this.getSession().createCriteria(GermplasmListData.class); criteria.createAlias(GermplasmListDataDAO.GERMPLASM_LIST_NAME_TABLE, GermplasmListDataDAO.GERMPLASM_LIST_NAME_TABLE_ALIAS); criteria.createAlias(GermplasmListDataDAO.GERMPLASM_TABLE, GermplasmListDataDAO.GERMPLASM_TABLE_ALIAS); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_DELETED_COLUMN, Boolean.FALSE)); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_LIST_NAME_ID_COLUMN, listId)); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_LIST_DATA_ID_COLUMN, lrecId)); criteria.add(Restrictions.ne(GermplasmListDataDAO.GERMPLASM_LIST_DATA_TABLE_STATUS_COLUMN, GermplasmListDataDAO.STATUS_DELETED)); criteria.addOrder(Order.asc(GermplasmListDataDAO.GERMPLASM_LIST_DATA_ID_COLUMN)); return (GermplasmListData) criteria.uniqueResult(); }
From source file:org.generationcp.middleware.dao.GermplasmListDataDAO.java
License:Open Source License
public GermplasmListData getByListIdAndGid(final Integer listId, final Integer gid) { // Make sure parameters are not null. Preconditions.checkNotNull(listId, "List id passed cannot be null."); Preconditions.checkNotNull(gid, "Gid passed in cannot be null."); final Criteria criteria = this.getSession().createCriteria(GermplasmListData.class); criteria.createAlias(GermplasmListDataDAO.GERMPLASM_LIST_NAME_TABLE, GermplasmListDataDAO.GERMPLASM_LIST_NAME_TABLE_ALIAS); criteria.createAlias(GermplasmListDataDAO.GERMPLASM_TABLE, GermplasmListDataDAO.GERMPLASM_TABLE_ALIAS); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_LIST_NAME_ID_COLUMN, listId)); criteria.add(Restrictions.eq(GermplasmListDataDAO.GERMPLASM_LIST_DATA_GID_COLUMN, gid)); criteria.add(Restrictions.ne(GermplasmListDataDAO.GERMPLASM_LIST_DATA_TABLE_STATUS_COLUMN, GermplasmListDataDAO.STATUS_DELETED)); List result = criteria.list(); return (result != null && result.size() > 0 ? (GermplasmListData) result.get(0) : null); }
From source file:org.generationcp.middleware.dao.ims.LotDAO.java
License:Open Source License
public Double getAvailableLotBalance(Integer lotId) throws MiddlewareQueryException { try {// w w w.ja v a 2 s .c om if (lotId != null) { Lot lot = this.getById(lotId, false); Criteria criteria = this.getSession().createCriteria(Transaction.class); criteria.setProjection(Projections.sum("quantity")); criteria.add(Restrictions.eq("lot", lot)); // get all non-cancelled transactions criteria.add(Restrictions.ne("status", 9)); return (Double) criteria.uniqueResult(); } } catch (HibernateException e) { this.logAndThrowException( "Error with getAvailableLotBalance(lotId=" + lotId + QUERY_FROM_LOT + e.getMessage(), e); } return 0d; }