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:net.frontlinesms.plugins.reminders.data.repository.hibernate.HibernateReminderDao.java

License:Open Source License

/** @see ReminderDao#getPendingReminders() */
public Collection<Reminder> getPendingReminders() {
    DetachedCriteria criteria = super.getCriterion();
    Criterion notSent = Restrictions.ne(Field.STATUS.getFieldName(), Reminder.Status.SENT);
    Criterion isNull = Restrictions.isNull(Field.STATUS.getFieldName());
    criteria.add(Restrictions.or(notSent, isNull));
    return super.getList(criteria);
}

From source file:net.jforum.core.hibernate.ForumDAO.java

License:Open Source License

/**
 * Selects all topics associated to a specific forum.
 *
 * @param forum The forum to select the topics
 * @return <code>List</code> with all topics found. Each entry is a <code>net.jforum.Topic</code> object
  * @param startFrom int/*from   ww w .j a  v a  2  s .  c o m*/
  * @param count int
 */
@SuppressWarnings("unchecked")
public List<Topic> getTopics(Forum forum, int startFrom, int count) {
    boolean includeMoved = this.config == null || !this.config.getBoolean(ConfigKeys.QUERY_IGNORE_TOPIC_MOVED);

    Criteria criteria = this.session().createCriteria(Topic.class).createAlias("firstPost", "fp")
            .createAlias("lastPost", "lp");

    if (includeMoved) {
        criteria.add(
                Restrictions.or(Restrictions.eq("forum", forum), Restrictions.eq("movedId", forum.getId())));
    } else {
        criteria.add(Restrictions.eq("forum", forum));
    }

    return criteria.add(Restrictions.eq("pendingModeration", false)).addOrder(Order.desc("type"))
            .addOrder(Order.desc("lastPost")).setFirstResult(startFrom).setMaxResults(count)
            .setCacheable(startFrom == 0) // FIXME cache other pages? should find a good solution. Also, check the eviction rules if changing this
            .setCacheRegion("forumDAO.getTopics#" + forum.getId()) // Related to the fixme above
            .setComment("forumDAO.getTopics").list();
}

From source file:net.jforum.core.hibernate.UserDAO.java

License:Open Source License

/**
 * @see net.jforum.repository.UserRepository#isUsernameAvailable(java.lang.String, java.lang.String)
 *//*w  w w .j a  v  a 2 s  . c o  m*/
public boolean isUsernameAvailable(String username, String email) {
    return (Integer) this.session().createCriteria(User.class).setProjection(Projections.rowCount())
            .add(Restrictions.or(Restrictions.eq("username", username).ignoreCase(),
                    Restrictions.eq("email", email).ignoreCase()))
            .uniqueResult() == 0;
}

From source file:net.jforum.repository.ForumDao.java

License:Open Source License

/**
 * Selects all topics associated to a specific forum.
 *
 * @param forum     The forum to select the topics
 * @param startFrom int//w  ww  . j  a  v a  2 s  . c  o  m
 * @param count     int
 * @return <code>List</code> with all topics found. Each entry is a <code>net.jforum.Topic</code> object
 */
@SuppressWarnings("unchecked")
public List<Topic> getTopics(Forum forum, int startFrom, int count) {
    boolean includeMoved = this.config == null || !this.config.getBoolean(ConfigKeys.QUERY_IGNORE_TOPIC_MOVED);

    Criteria criteria = session.createCriteria(Topic.class).createAlias("firstPost", "fp")
            .createAlias("lastPost", "lp");

    if (includeMoved) {
        criteria.add(
                Restrictions.or(Restrictions.eq("forum", forum), Restrictions.eq("movedId", forum.getId())));
    } else {
        criteria.add(Restrictions.eq("forum", forum));
    }

    return criteria.add(Restrictions.eq("pendingModeration", false)).addOrder(Order.desc("type"))
            .addOrder(Order.desc("lastPost")).setFirstResult(startFrom).setMaxResults(count)
            .setCacheable(startFrom == 0) // FIXME cache other pages? should find a good solution. Also, check the eviction rules if changing this
            .setCacheRegion("forumDAO.getTopics#" + forum.getId()) // Related to the fixme above
            .setComment("forumDAO.getTopics").list();
}

From source file:net.jforum.repository.UserDao.java

License:Open Source License

/**
 * Checks if the given username is available for registering
 *
 * @param username the username to check
 * @param email    the email of the given username.
 * @return true if the username is available, of false if either
 *         the username or the email address is already taken
 *///  www  . jav  a 2s.  com
public boolean isUsernameAvailable(String username, String email) {
    return (Integer) session.createCriteria(User.class).setProjection(Projections.rowCount())
            .add(Restrictions.or(Restrictions.eq("username", username).ignoreCase(),
                    Restrictions.eq("email", email).ignoreCase()))
            .uniqueResult() == 0;
}