Example usage for org.hibernate.criterion Restrictions ne

List of usage examples for org.hibernate.criterion Restrictions ne

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions ne.

Prototype

public static SimpleExpression ne(String propertyName, Object value) 

Source Link

Document

Apply a "not equal" constraint to the named property

Usage

From source file:org.generationcp.middleware.dao.GermplasmListDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<GermplasmList> getByGIDandProgramUUID(final Integer gid, final int start, final int numOfRows,
        final String programUUID) {
    try {//  w  w w .  j  a v  a2s.  c  om
        if (gid != null) {
            final Criteria criteria = this.getSession().createCriteria(GermplasmList.class, "germplasmList");
            final DetachedCriteria gidCriteria = DetachedCriteria.forClass(GermplasmListData.class, "listData");
            gidCriteria.add(Restrictions.eq("listData.gid", gid));
            gidCriteria.add(Property.forName("germplasmList.id").eqProperty("listData.list.id"));
            criteria.add(Subqueries.exists(gidCriteria.setProjection(Projections.property("listData.gid"))));
            criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED));
            this.addCriteriaForProgramUUIDInLists(programUUID, criteria);
            criteria.setFirstResult(start);
            criteria.setMaxResults(numOfRows);
            criteria.addOrder(Order.asc("name"));
            this.hideSnapshotListTypes(criteria);
            return criteria.list();
        }
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getByGIDandProgramUUID(gid=" + gid + ",programUUID="
                + programUUID + ") query from GermplasmList: " + e.getMessage();
        GermplasmListDAO.LOG.error(errorMessage);
        throw new MiddlewareQueryException(errorMessage, e);
    }
    return new ArrayList<>();
}

From source file:org.generationcp.middleware.dao.GermplasmListDAO.java

License:Open Source License

public long countByGID(final Integer gid) {
    try {/*from  w  w  w . j a  v  a 2s  .c o  m*/
        if (gid != null) {
            final Criteria criteria = this.getSession().createCriteria(GermplasmListData.class);
            criteria.createAlias("list", "l");
            criteria.add(Restrictions.eq("gid", gid));
            criteria.add(Restrictions.ne("l.status", GermplasmListDAO.STATUS_DELETED));
            criteria.setProjection(Projections.countDistinct("l.id"));
            return ((Long) criteria.uniqueResult()).longValue();
        }
    } catch (final HibernateException e) {
        final String errorMessage = "Error with countByGID(gid=" + gid + ") query from GermplasmList "
                + e.getMessage();
        GermplasmListDAO.LOG.error(errorMessage);
        throw new MiddlewareQueryException(errorMessage, e);
    }
    return 0;
}

From source file:org.generationcp.middleware.dao.GermplasmListDAO.java

License:Open Source License

public long countByGIDandProgramUUID(final Integer gid, final String programUUID) {
    try {//from   w w  w .j  a va 2s  .  c om
        if (gid != null) {
            final Criteria criteria = this.getSession().createCriteria(GermplasmList.class, "germplasmList");
            final DetachedCriteria gidCriteria = DetachedCriteria.forClass(GermplasmListData.class, "listData");
            gidCriteria.add(Restrictions.eq("listData.gid", gid));
            gidCriteria.add(Property.forName("germplasmList.id").eqProperty("listData.list.id"));
            criteria.add(Subqueries.exists(gidCriteria.setProjection(Projections.property("listData.gid"))));
            criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED));
            this.addCriteriaForProgramUUIDInLists(programUUID, criteria);
            this.hideSnapshotListTypes(criteria);
            criteria.setProjection(Projections.countDistinct("id"));
            return ((Long) criteria.uniqueResult()).longValue(); // count
        }
    } catch (final HibernateException e) {
        final String errorMessage = "Error with countByGIDandProgramUUID(gid=" + gid + ",programUUID="
                + programUUID + ") query from GermplasmList: " + e.getMessage();
        GermplasmListDAO.LOG.error(errorMessage);
        throw new MiddlewareQueryException(errorMessage, e);
    }
    return 0;
}

From source file:org.generationcp.middleware.dao.GermplasmListDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<GermplasmList> getByName(final String name, final String programUUID, final Operation operation,
        final int start, final int numOfRows) {
    try {// w w w .  ja  v a  2  s  . c o  m
        final Criteria criteria = this.getSession().createCriteria(GermplasmList.class);

        this.hideSnapshotListTypes(criteria);

        if (operation == null || operation == Operation.EQUAL) {
            criteria.add(Restrictions.eq("name", name));
        } else if (operation == Operation.LIKE) {
            criteria.add(Restrictions.like("name", name));
        }

        criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED));

        this.addCriteriaForProgramUUIDInLists(programUUID, criteria);

        criteria.setFirstResult(start);
        criteria.setMaxResults(numOfRows);
        return criteria.list();
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getByName(name=" + name + ") 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 long countByName(final String name, final Operation operation) {
    try {//from   w w  w  . j  a v a2s. c  o  m
        final Criteria criteria = this.getSession().createCriteria(GermplasmList.class);
        criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED));
        criteria.setProjection(Projections.rowCount());

        this.hideSnapshotListTypes(criteria);

        if (operation == null || operation == Operation.EQUAL) {
            criteria.add(Restrictions.eq("name", name));
        } else if (operation == Operation.LIKE) {
            criteria.add(Restrictions.like("name", name));
        }
        return ((Long) criteria.uniqueResult()).longValue();
    } catch (final HibernateException e) {
        final String errorMessage = "Error with countByName(name=" + name + ") 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> getByStatus(final Integer status, final int start, final int numOfRows) {
    try {// w w  w . j a  v a 2s  . c o  m
        if (status != null) {
            final Criteria criteria = this.getSession().createCriteria(GermplasmList.class);
            criteria.add(Restrictions.eq(GermplasmListDAO.STATUS, status));
            criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED));

            this.hideSnapshotListTypes(criteria);

            criteria.setFirstResult(start);
            criteria.setMaxResults(numOfRows);
            return criteria.list();
        }
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getByStatus(status=" + status + ") query from GermplasmList: "
                + e.getMessage();
        GermplasmListDAO.LOG.error(errorMessage);
        throw new MiddlewareQueryException(errorMessage, e);
    }
    return new ArrayList<>();
}

From source file:org.generationcp.middleware.dao.GermplasmListDAO.java

License:Open Source License

public long countByStatus(final Integer status) {
    try {/*from  w  w w.ja  va  2 s  .c  o  m*/
        if (status != null) {
            final Criteria criteria = this.getSession().createCriteria(GermplasmList.class);
            criteria.add(Restrictions.eq(GermplasmListDAO.STATUS, status));
            criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED));

            this.hideSnapshotListTypes(criteria);

            criteria.setProjection(Projections.rowCount());
            return ((Long) criteria.uniqueResult()).longValue();
        }
    } catch (final HibernateException e) {
        final String errorMessage = "Error with countByStatus(status=" + status + ") query from GermplasmList: "
                + e.getMessage();
        GermplasmListDAO.LOG.error(errorMessage);
        throw new MiddlewareQueryException(errorMessage, e);
    }
    return 0;
}

From source file:org.generationcp.middleware.dao.GermplasmListDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<GermplasmList> getAllTopLevelLists(final String programUUID) {
    try {// ww  w .  j a  va2  s .  co  m
        final Criterion topFolder = Restrictions.eq("parent.id", 0);
        final Criterion nullFolder = Restrictions.isNull("parent");
        final Criteria criteria = this.getSession().createCriteria(GermplasmList.class);
        criteria.add(Restrictions.or(topFolder, nullFolder));
        criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED));

        if (programUUID == null) {
            final Criterion nullProgramUUID = Restrictions.isNull(GermplasmListDAO.PROGRAM_UUID);
            criteria.add(nullProgramUUID);
        } else {
            final Criterion sameProgramUUID = Restrictions.eq(GermplasmListDAO.PROGRAM_UUID, programUUID);
            criteria.add(sameProgramUUID);
        }

        this.hideSnapshotListTypes(criteria);

        criteria.addOrder(Order.asc("name"));
        return criteria.list();
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getAllTopLevelLists() 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

/**
 * Gets the germplasm list children.//from w  ww . j av a 2 s . c  o m
 *
 * @param parentId
 *            the parent id
 * @param programUUID
 *            the program UUID
 * @param start
 *            the start
 * @param numOfRows
 *            the num of rows
 * @return the germplasm list children
 */
@SuppressWarnings("unchecked")
public List<GermplasmList> getByParentFolderId(final Integer parentId, final String programUUID) {
    try {
        if (parentId != null) {
            final Criteria criteria = this.getSession().createCriteria(GermplasmList.class);
            criteria.add(Restrictions.eq("parent.id", parentId));
            criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED));

            this.addCriteriaForProgramUUIDInLists(programUUID, criteria);

            this.hideSnapshotListTypes(criteria);

            criteria.addOrder(Order.asc("name"));
            return criteria.list();
        }
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getByParentFolderId(parentId=" + parentId
                + ") query from GermplasmList: " + e.getMessage();
        GermplasmListDAO.LOG.error(errorMessage);
        throw new MiddlewareQueryException(errorMessage, e);
    }
    return new ArrayList<>();
}

From source file:org.generationcp.middleware.dao.GermplasmListDAO.java

License:Open Source License

@Nullable
public GermplasmList getLastCreatedByUserID(final Integer userID, final String programUUID) {
    try {//ww  w  . j  ava 2  s . c  o m
        if (userID != null) {
            final Criteria criteria = this.getSession().createCriteria(GermplasmList.class);
            criteria.add(Restrictions.eq("userId", userID));
            criteria.add(Restrictions.ne(GermplasmListDAO.STATUS, GermplasmListDAO.STATUS_DELETED));

            this.addCriteriaForProgramUUIDInLists(programUUID, criteria);

            this.hideSnapshotListTypes(criteria);

            criteria.addOrder(Order.desc("id"));

            final List result = criteria.list();
            if (!result.isEmpty()) {
                return (GermplasmList) result.get(0);
            } else {
                return null;
            }
        }
    } catch (final HibernateException e) {
        final String errorMessage = "Error with getByUserID(userID=" + userID + ") query from GermplasmList: "
                + e.getMessage();
        GermplasmListDAO.LOG.error(errorMessage);
        throw new MiddlewareQueryException(errorMessage, e);
    }
    return null;
}