Example usage for org.hibernate.criterion Restrictions or

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

Introduction

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

Prototype

public static LogicalExpression or(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the disjuction of two expressions

Usage

From source file:com.zapangtrainer.model.dao.ClientDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Long getPass() {
    Long val = null;

    session = getSessionFactory().getCurrentSession();

    Criteria criteria = session.createCriteria(Reply.class, "reply");
    criteria.setReadOnly(true);// w  w w  .ja  va 2s.c  o  m
    criteria.add(Restrictions.like("reply.type", "rating"));
    criteria.add(Restrictions.ne("reply.answer", "0"));
    criteria.add(Restrictions.or(Restrictions.like("reply.answer", "2", MatchMode.START),
            Restrictions.like("reply.answer", "3", MatchMode.START)));
    criteria.setProjection(Projections.rowCount());
    val = (Long) criteria.uniqueResult();

    return val;
}

From source file:com.zapangtrainer.model.dao.ClientDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Long getDet() {
    Long val = null;

    session = getSessionFactory().getCurrentSession();

    Criteria criteria = session.createCriteria(Reply.class, "reply");
    criteria.setReadOnly(true);/*  w  w  w.j a va2 s. c  o  m*/
    criteria.add(Restrictions.like("reply.type", "rating"));
    criteria.add(Restrictions.ne("reply.answer", "0"));
    criteria.add(Restrictions.or(Restrictions.like("reply.answer", "0", MatchMode.START),
            Restrictions.like("reply.answer", "1", MatchMode.START)));
    criteria.setProjection(Projections.rowCount());
    val = (Long) criteria.uniqueResult();

    return val;
}

From source file:corner.orm.tapestry.component.DefaultSelectFilter.java

License:Apache License

/**
 * ???//ww w.j  a  v  a 2 s.  c o m
 * @param searchParam
 * @return
 */
public List listAllMatchedValue(final String... searchParam) {
    return this.entityService.executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(queryClass);
            criteria.add(Restrictions.or(Restrictions.like(labelField, searchParam[0]),
                    Restrictions.like(cnlabelField, searchParam[0])));
            criteria.setFirstResult(nFirst);
            criteria.setMaxResults(nPageSize);
            return criteria.list();
        }
    });
}

From source file:cpcc.core.services.jobs.JobRepositoryImpl.java

License:Open Source License

/**
 * {@inheritDoc}/*from ww w  .jav  a 2 s. com*/
 */
@SuppressWarnings("unchecked")
@Override
public void removeOldJobs() {
    List<Job> oldJobs = (List<Job>) session.createCriteria(Job.class)
            .add(Restrictions.or(Restrictions.le("end", new Date(System.currentTimeMillis() - maxJobAge)),
                    Restrictions.and(Restrictions.le("end", new Date(System.currentTimeMillis() - 30000)),
                            Restrictions.in("status",
                                    new JobStatus[] { JobStatus.OK, JobStatus.FAILED, JobStatus.NO_FACTORY }))))
            .list();

    for (Job job : oldJobs) {
        logger.debug("Removing old job " + job.getId() + " " + job.getQueued() + " " + job.getQueueName() + " "
                + job.getParameters());

        session.delete(job);
    }
}

From source file:cz.jirutka.rsql.hibernate.RSQL2CriteriaConverterImplTest.java

License:Open Source License

/**
 * Finally test whole DetachedCriteria creation.
 *//*w w w .  ja v a  2  s.  c  o m*/
@Test
public void testInnerConvertDetached2() {
    instance.pushCriterionBuilder(new MockCriterionBuilder());

    DetachedCriteria expResult = DetachedCriteria.forClass(Course.class, RSQL2CriteriaConverter.ROOT_ALIAS)
            .add(Restrictions.and(Restrictions.eq("foo", "flynn"),
                    Restrictions.or(Restrictions.eq("bar", 42), Restrictions.eq("baz", 42.2))));

    Expression expression = new LogicalExpression(new ComparisonExpression("foo", Comparison.EQUAL, "flynn"),
            Logical.AND, new LogicalExpression(new ComparisonExpression("bar", Comparison.EQUAL, "42"),
                    Logical.OR, new ComparisonExpression("baz", Comparison.EQUAL, "42.2")));

    DetachedCriteria result = DetachedCriteria.forClass(Course.class);
    inner.convert(expression, result);

    assertEquals(expResult.toString(), result.toString());
}

From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java

License:Apache License

@Override
public Criterion visit(OrNode node) {
    List<Node> children = node.getChildren();
    assert children.size() >= 2;
    Criterion previous = children.get(0).accept(this);
    for (int i = 1; i < children.size(); ++i) {
        previous = Restrictions.or(previous, children.get(i).accept(this));
    }//w w w  . j a  v a  2  s  .  c  o  m
    return previous;
}

From source file:cz.zcu.kiv.eegdatabase.data.dao.SimpleReservationDao.java

License:Apache License

public int createChecked(Reservation newInstance) throws DaoException {

    if (newInstance.getStartTime().getTime() >= newInstance.getEndTime().getTime()) {
        throw new DaoException("Time of start cannot be lower than or equal to time of end!");
    }/*  w w w .  ja  va 2  s . c  o m*/
    Criteria overlapCriteria = getSession().createCriteria(Reservation.class);
    //start overlap
    LogicalExpression startOverlap = Restrictions.and(
            Restrictions.and(Restrictions.ge("startTime", newInstance.getStartTime()),
                    Restrictions.ge("endTime", newInstance.getEndTime())),
            Restrictions.le("startTime", newInstance.getEndTime()));
    //end overlap
    LogicalExpression endOverlap = Restrictions.and(
            Restrictions.and(Restrictions.le("startTime", newInstance.getStartTime()),
                    Restrictions.le("endTime", newInstance.getEndTime())),
            Restrictions.ge("endTime", newInstance.getStartTime()));
    //include overlap
    LogicalExpression inOverlap = Restrictions.and(Restrictions.le("startTime", newInstance.getStartTime()),
            Restrictions.ge("endTime", newInstance.getEndTime()));

    //complete overlap
    LogicalExpression completeOverlap = Restrictions.and(
            Restrictions.ge("startTime", newInstance.getStartTime()),
            Restrictions.le("endTime", newInstance.getEndTime()));

    overlapCriteria.add(Restrictions.or(Restrictions.or(inOverlap, completeOverlap),
            Restrictions.or(startOverlap, endOverlap)));

    //if some overlap was found, it is an error
    if (overlapCriteria.list().size() > 0) {
        throw new DaoException(
                "Reservation could not be created due to existing records within the time range.");
    }

    return super.create(newInstance);
}

From source file:dao.JobSearchDAO.java

/**
 * get search condition//from  ww  w  .  j  a v  a  2 s  .  c om
 *
 * @param keyword
 * @param location
 * @param cName
 *
 */
public List<Job> searchByCondition(String keyword, String location, String cName) {
    Criteria c = session.createCriteria(Job.class);
    //
    if (keyword != null) {
        c.add(Restrictions.or(Restrictions.like("title", "%" + keyword + "%"),
                Restrictions.like("description", "%" + keyword + "%")));
    }
    if (cName != null) {
        c.add(Restrictions.like("cname", "%" + cName + "%"));
    }
    if (location != null) {
        c.add(Restrictions.like("location", "%" + location + "%"));
    }
    List<Job> jobList = new ArrayList<Job>();
    jobList = (List<Job>) c.list();
    return jobList;
}

From source file:dao.parent.Dao.java

protected Criterion nullOrFalse(String fieldName) {
    return Restrictions.or(Restrictions.isNull(fieldName), Restrictions.eq(fieldName, false));
}

From source file:de.arago.rike.commons.util.MilestoneHelper.java

License:Open Source License

public static List<Milestone> listNotExpired() {
    DataHelperRike<Milestone> helper = new DataHelperRike<Milestone>(Milestone.class);

    return helper.list(helper.filter()
            .add(Restrictions.or(Restrictions.gt("dueDate", new Date()), Restrictions.isNull("dueDate")))
            .addOrder(Order.asc("dueDate")).addOrder(Order.asc("title")));
}