Example usage for org.hibernate.criterion Restrictions isNotNull

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

Introduction

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

Prototype

public static Criterion isNotNull(String propertyName) 

Source Link

Document

Apply an "is not null" constraint to the named property

Usage

From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.AchievementIconDAOImpl.java

License:Open Source License

@Override
protected Criteria createCriteria(SearchFilter<AchievementIcon> filter) {
    Criteria criteria = getSession().createCriteria(AchievementIcon.class);

    if (filter instanceof AchievementIconFilter) {
        AchievementIconFilter cf = (AchievementIconFilter) filter;

        if (cf.getUnclaimed() != null) {
            if (cf.getUnclaimed()) {
                criteria.add(Restrictions.isNull("achievement"));
                criteria.add(Restrictions.isNull("proposal"));
            } else {
                Disjunction d = Restrictions.disjunction();
                d.add(Restrictions.isNotNull("achievement"));
                d.add(Restrictions.isNotNull("proposal"));
                criteria.add(d);//from w ww  . ja v  a  2 s  .c om
            }
        }
        if (cf.getCreatorOnly() != null) {
            criteria.add(Restrictions.eq("creatorOnly", cf.getCreatorOnly()));
        } else if (cf.isCreatorOnlyAsNull()) {
            criteria.add(Restrictions.isNull("creatorOnly"));
        }
        if (cf.getApproved() != null) {
            criteria.add(Restrictions.eq("approved", cf.getApproved()));
        } else if (cf.isApprovedAsNull()) {
            criteria.add(Restrictions.isNull("approved"));
        }
        if (cf.getCreator() != null) {
            criteria.add(Restrictions.eq("creator", cf.getCreator()));
        }
    }

    return criteria;
}

From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.ProfileDAOImpl.java

License:Open Source License

/**
 * @see com.tysanclan.site.projectewok.entities.dao.ProfileDAO#getSkypeUsers()
 *//*from  w  w  w  .jav a 2  s. c  o  m*/
@SuppressWarnings("unchecked")
@Override
@Transactional(propagation = Propagation.REQUIRED)
public List<User> getSkypeUsers() {
    Criteria criteria = getSession().createCriteria(User.class);

    criteria.createAlias("profile", "profile");
    criteria.add(Restrictions.isNotNull("profile.instantMessengerAddress"));
    criteria.add(Restrictions.in("rank", new Rank[] { Rank.CHANCELLOR, Rank.SENATOR, Rank.TRUTHSAYER,
            Rank.REVERED_MEMBER, Rank.SENIOR_MEMBER, Rank.FULL_MEMBER, Rank.JUNIOR_MEMBER, Rank.TRIAL }));
    criteria.addOrder(Order.asc("username"));

    return criteria.list();
}

From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.TruthsayerNominationDAOImpl.java

License:Open Source License

@Override
protected Criteria createCriteria(SearchFilter<TruthsayerNomination> filter) {
    Criteria criteria = getSession().createCriteria(TruthsayerNomination.class);

    if (filter instanceof TruthsayerNominationFilter) {
        TruthsayerNominationFilter cf = (TruthsayerNominationFilter) filter;

        if (cf.getNominee() != null) {
            criteria.add(Restrictions.eq("user", cf.getNominee()));
        }//from  w w  w  .  j  a v a 2 s.  c o  m
        if (cf.getStartBefore() != null) {
            criteria.add(Restrictions.lt("voteStart", cf.getStartBefore()));
        } else if (cf.isStartNotSet()) {
            criteria.add(Restrictions.isNull("voteStart"));
        } else if (cf.isStartSet()) {
            criteria.add(Restrictions.isNotNull("voteStart"));
        }
    }

    return criteria;
}

From source file:com.ut.tekir.stock.yeni.PurchaseShipmentBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(TekirShipmentNote.class);

    crit.createAlias("contact", "contact");

    crit.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("serial"), "serial").add(Projections.property("reference"), "reference")
            .add(Projections.property("code"), "code").add(Projections.property("date"), "date")
            .add(Projections.property("info"), "info").add(Projections.property("info1"), "info1")
            .add(Projections.property("info2"), "info2").add(Projections.property("warehouse"), "warehouse")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("contact.company"), "company")
            .add(Projections.property("contact.person"), "person")
            .add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("workBunch"), "workBunch"))
            .setResultTransformer(Transformers.aliasToBean(ShipmentFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }//from w  w  w  . jav a 2  s .  c  o  m

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("this.reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("this.date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("this.date", filterModel.getEndDate()));
    }

    if (filterModel.getWarehouse() != null) {
        crit.add(Restrictions.eq("this.warehouse", filterModel.getWarehouse()));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.fullname", filterModel.getContactName(), MatchMode.ANYWHERE));
    }

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (filterModel.getInvoiced() != null) {
        if (filterModel.getInvoiced().equals(Boolean.TRUE)) {
            crit.add(Restrictions.isNotNull("this.invoice"));
        } else {
            crit.add(Restrictions.isNull("this.invoice"));
        }
    }

    if (filterModel.getWorkBunch() != null) {
        crit.add(Restrictions.eq("this.workBunch", filterModel.getWorkBunch()));
    }

    crit.add(Restrictions.eq("this.tradeAction", TradeAction.Purchase));
    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.ut.tekir.stock.yeni.SaleShipmentBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(TekirShipmentNote.class);

    crit.createAlias("contact", "contact");

    crit.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("serial"), "serial").add(Projections.property("reference"), "reference")
            .add(Projections.property("code"), "code").add(Projections.property("date"), "date")
            .add(Projections.property("info1"), "info1").add(Projections.property("info2"), "info2")
            .add(Projections.property("warehouse"), "warehouse")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("contact.company"), "company")
            .add(Projections.property("contact.person"), "person")
            .add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("workBunch"), "workBunch"))
            .setResultTransformer(Transformers.aliasToBean(ShipmentFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }/*from w  ww.j  a v  a  2  s  . com*/

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("this.reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("this.date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("this.date", filterModel.getEndDate()));
    }

    if (filterModel.getWarehouse() != null) {
        crit.add(Restrictions.eq("this.warehouse", filterModel.getWarehouse()));
    }

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.fullname", filterModel.getContactName(), MatchMode.ANYWHERE));
    }

    if (filterModel.getInvoiced() != null) {
        if (filterModel.getInvoiced().equals(Boolean.TRUE)) {
            crit.add(Restrictions.isNotNull("this.invoice"));
        } else {
            crit.add(Restrictions.isNull("this.invoice"));
        }
    }

    if (filterModel.getWorkBunch() != null) {
        crit.add(Restrictions.eq("this.workBunch", filterModel.getWorkBunch()));
    }

    crit.add(Restrictions.eq("this.tradeAction", TradeAction.Sale));
    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.viettel.vsaadmin.database.DAOHibernate.DepartmentDAOHE.java

License:Open Source License

/**
 *
 * @return/* w w  w.j  av a2  s .c  o  m*/
 */
public List<Department> getParentDeptForTree(Boolean isCheckStatus) {
    Criterion[] criterion = new Criterion[3];
    criterion[0] = Restrictions.isNull("parentId");
    if (isCheckStatus) {
        criterion[1] = Restrictions.eq("status", 1L);
    } else {
        criterion[1] = Restrictions.isNotNull("deptId");
    }
    criterion[2] = Restrictions
            .sqlRestriction(" 1 = 1 order by nlssort(lower({alias}.DEPT_NAME),'nls_sort = Vietnamese') ");
    return this.findByCriteria(0, -1, criterion);
}

From source file:com.viettel.vsaadmin.database.DAOHibernate.DepartmentDAOHE.java

License:Open Source License

/**
 *
 * @return/*from   w w w.ja  va  2  s .c  om*/
 */
public List<Department> getDeptListByParentId(Long parentId, Boolean isCheckStatus) {

    Criterion[] criterion = new Criterion[3];
    criterion[0] = Restrictions.eq("parentId", parentId);
    if (isCheckStatus) {
        criterion[1] = Restrictions.eq("status", 1L);
    } else {
        criterion[1] = Restrictions.isNotNull("deptId");
    }
    //            criterion[1] = Restrictions.ne(idField, entityId);
    //criteria.addOrder(Order.asc("name"));
    criterion[2] = Restrictions
            .sqlRestriction(" 1 = 1 order by nlssort(lower({alias}.DEPT_NAME),'nls_sort = Vietnamese') ");
    return this.findByCriteria(0, -1, criterion);
}

From source file:com.vmware.appfactory.feed.dao.FeedDaoImpl.java

License:Open Source License

@Override
public long countFailed() {
    Criterion criterion = Restrictions.and(Restrictions.isNotNull("_failure._summary"),
            Restrictions.ne("_failure._summary", Feed.SCANNING));
    return countByCriterion(criterion);
}

From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java

License:Open Source License

public Criterion getCriterion() throws Exception {
    if (condition.equals(EQ)) {
        if (value == null || value.toString().trim().length() == 0) {
            return Restrictions.isNull(fullKey);
        } else {//  ww  w  .jav a2  s  . c o  m
            return Restrictions.eq(fullKey, value);
        }
    }

    if (condition.equals(NE)) {
        if (value == null || value.toString().trim().length() == 0) {
            return Restrictions.isNotNull(fullKey);
        } else {
            return Restrictions.ne(fullKey, value);
        }
    }

    if (condition.equals(GT)) {
        assertNonNullity(value);
        return Restrictions.gt(fullKey, value);
    }

    if (condition.equals(GE)) {
        assertNonNullity(value);
        return Restrictions.ge(fullKey, value);
    }

    if (condition.equals(LT)) {
        assertNonNullity(value);
        return Restrictions.lt(fullKey, value);
    }

    if (condition.equals(LE)) {
        assertNonNullity(value);
        return Restrictions.le(fullKey, value);
    }

    if (condition.equals(IN_A_RANGE)) {
        assertNonNullity(value);
        assertNonNullity(diff);
        return getPercentRange();
    }

    if (condition.equals(ENDS_WITH)) {
        return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()));
    }

    if (condition.equals(STARTS_WITH)) {
        return Restrictions.like(fullKey, StringUtils.trim(value.toString()) + "%");
    }

    if (condition.equals(CONTAINS)) {
        return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%');
    }

    if (condition.equals(NOT_CONTAIN)) {
        return Restrictions.not(Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%'));
    }

    LOGGER.error(
            "Undefined User Criteria [key:{0}, value:{1}, condition:{3}] couldn't be transformed to search criterion",
            fullKey, value, condition);

    throw new RuntimeException("Undefined User Criteria: " + name);
}

From source file:com.xpn.xwiki.store.XWikiHibernateVersioningStore.java

License:Open Source License

/**
 * {@inheritDoc}//from   w w  w  .j  a v  a2 s.  c  o m
 */
protected List<XWikiRCSNodeInfo> loadAllRCSNodeInfo(XWikiContext context, final long id, boolean bTransaction)
        throws XWikiException {
    return executeRead(context, bTransaction, new HibernateCallback<List<XWikiRCSNodeInfo>>() {
        @SuppressWarnings("unchecked")
        public List<XWikiRCSNodeInfo> doInHibernate(Session session) throws HibernateException {
            try {
                return session.createCriteria(XWikiRCSNodeInfo.class)
                        .add(Restrictions.eq("id.docId", Long.valueOf(id))).add(Restrictions.isNotNull("diff"))
                        .list();
            } catch (IllegalArgumentException ex) {
                // This happens when the database has wrong values...
                LOG.warn("Invalid history for document " + id);
                return Collections.emptyList();
            }
        }
    });
}