Example usage for org.hibernate.criterion Restrictions eq

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

Introduction

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

Prototype

public static SimpleExpression eq(String propertyName, Object value) 

Source Link

Document

Apply an "equal" constraint to the named property

Usage

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.ResourcePermissionDao.java

License:Open Source License

@Override
public void delete(ResourcePermission perm) {
    /* We need to delete any user locks of this permission. */
    int num = (Integer) this.session.createCriteria(UserLock.class)
            .add(Restrictions.eq("resourcePermission", perm)).setProjection(Projections.count("id"))
            .uniqueResult();/*from  w ww.ja  v  a  2 s . c  om*/
    if (num > 0) {
        /* Delete all user locks. */
        this.logger.debug("To delete resource permission '" + perm.getId() + "', " + num + " user locks have to"
                + " removed.");
        this.session.beginTransaction();
        int numDeleted = this.session.createQuery("delete UserLock ul where ul.resourcePermission = :perm")
                .setEntity("perm", perm).executeUpdate();

        this.logger.debug("Deleted " + numDeleted + " user locks when deleting resource permission '"
                + perm.getId() + "'.");
        this.session.getTransaction().commit();
    }

    /* Null out the sessions which use this resource permission. */
    num = (Integer) this.session
            .createCriteria(au.edu.uts.eng.remotelabs.schedserver.dataaccess.entities.Session.class)
            .add(Restrictions.eq("resourcePermission", perm)).setProjection(Projections.count("id"))
            .uniqueResult();
    if (num > 0) {
        this.logger.debug("To delete resource permission '" + perm.getId() + "', " + num + " sessions need the "
                + "resource permission nulled.");
        this.session.beginTransaction();
        int numDeleted = this.session.createQuery("update Session ses set ses.resourcePermission = null "
                + "where ses.resourcePermission = :perm").setEntity("perm", perm).executeUpdate();

        this.logger.debug("Updated " + numDeleted + " session records when deleting resource permission '"
                + perm.getId() + "'.");
        this.session.getTransaction().commit();
    }

    /* Null out the bookings which use this resource permission. */
    num = (Integer) this.session.createCriteria(Bookings.class).add(Restrictions.eq("resourcePermission", perm))
            .setProjection(Projections.count("id")).uniqueResult();
    if (num > 0) {
        this.logger.debug("To delete resource permission '" + perm.getId() + "', " + num + " bookings need to "
                + "be deleted.");
        this.session.beginTransaction();
        int numDeleted = this.session.createQuery("delete Bookings bk where bk.resourcePermission = :perm")
                .setEntity("perm", perm).executeUpdate();

        this.logger.debug("Updated " + numDeleted + " bookings records when deleting resource permission '"
                + perm.getId() + "'.");
        this.session.getTransaction().commit();
    }

    /* Finally delete the permission. */
    super.delete(perm);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigCapabilitiesDao.java

License:Open Source License

/**
 * Find the rig capabilities entity which match the specified capabilities.
 * <code>null</code> is returned if none is found.
 *  //w ww.j a v  a  2s.  c om
 * @param capabilities capabilities to find 
 * @return capabilities or null
 */
public RigCapabilities findCapabilites(String capabilities) {
    Criteria cri = this.session.createCriteria(RigCapabilities.class);
    cri.add(Restrictions.eq("capabilities", new Capabilities(capabilities).asCapabilitiesString()));
    return (RigCapabilities) cri.uniqueResult();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigDao.java

License:Open Source License

/**
 * Finds the rig with the specified name or <code>null</code> if not
 * found./*w  w  w  .  j  a  va 2 s . co  m*/
 * 
 * @param name rig name
 * @return rig or null if not found
 */
public Rig findByName(String name) {
    Criteria cri = this.session.createCriteria(Rig.class);
    cri.add(Restrictions.eq("name", name));
    return (Rig) cri.uniqueResult();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigDao.java

License:Open Source License

/**
 * Returns the list of free rigs in a specified rig type. Free rigs are 
 * denoted by the following flags://from  w w  w . j av  a 2 s  .co  m
 * <ol>
 *  <li>active - True<li>
 *  <li>online - True<li>
 *  <li>in_session - False<li>
 * <ol>
 * 
 * @param type rig type
 * @return list of free rigs
 */
@SuppressWarnings("unchecked")
public List<Rig> findFreeinType(RigType type) {
    Criteria cri = this.session.createCriteria(Rig.class);
    cri.add(Restrictions.eq("rigType", type));
    cri.add(Restrictions.eq("active", true));
    cri.add(Restrictions.eq("online", true));
    cri.add(Restrictions.eq("inSession", false));
    return cri.list();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigLogDao.java

License:Open Source License

/**
 * Finds all the stored logs for the specified period for a specific
 * rig. The logs are ordered by their time stamp with the earliest log 
 * first./* w  ww. j ava 2  s  .c  o  m*/
 * 
 * @param rig rig to find the logs for
 * @param begin beginning of a period
 * @param end end of a period
 * @return list of logs
 */
@SuppressWarnings("unchecked")
public List<RigLog> findLogs(Rig rig, Date begin, Date end) {
    Criteria cri = this.session.createCriteria(RigLog.class);
    cri.add(Restrictions.eq("rig", rig));
    cri.add(Restrictions.gt("timeStamp", begin));
    cri.add(Restrictions.lt("timeStamp", end));
    cri.addOrder(Order.asc("timeStamp"));
    return cri.list();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigLogDao.java

License:Open Source License

/**
 * Finds all the stored logs for the specified period for a specific
 * rig, filtered for a specific state. The logs are ordered by their
 * time stamp with the earliest log first.
 * /*from  w  ww  .  j a  v  a 2s .c o m*/
 * @param rig rig to find the logs for
 * @param begin beginning of a period
 * @param end end of a period
 * @return list of logs
 */
@SuppressWarnings("unchecked")
public List<RigLog> findLogsOfState(Rig rig, String state, Date begin, Date end) {
    Criteria cri = this.session.createCriteria(RigLog.class);
    cri.add(Restrictions.eq("rig", rig));
    cri.add(Restrictions.gt("timeStamp", begin));
    cri.add(Restrictions.lt("timeStamp", end));
    cri.add(Restrictions.eq("newState", state));
    cri.addOrder(Order.asc("timeStamp"));
    return cri.list();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigOfflineScheduleDao.java

License:Open Source License

/**
 * Returns true if the rig is currently in a scheduled off-line period.
 * // w  ww. ja v a2s .  c o  m
 * @param rig rig to check
 * @return true if off-line
 */
public boolean isOffline(Rig rig) {
    Date now = new Date();
    return (Integer) this.session.createCriteria(this.clazz).add(Restrictions.eq("rig", rig))
            .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.lt("startTime", now))
            .add(Restrictions.gt("endTime", now)).setProjection(Projections.rowCount()).uniqueResult() > 0;
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigOfflineScheduleDao.java

License:Open Source License

/**
 * Returns a list of offline periods for the rig.
 * //from  w ww  .  j a v  a 2 s .c o m
 * @param rig rig
 * @return list of offline periods
 */
@SuppressWarnings("unchecked")
public List<RigOfflineSchedule> getOfflinePeriods(Rig rig) {
    return this.session.createCriteria(this.clazz).add(Restrictions.eq("rig", rig))
            .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.gt("endTime", new Date())).list();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigTypeDao.java

License:Open Source License

/**
 * Returns the rig type with the specified name. If non exist, 
 * <code>null</code> is returned.
 * /*from   ww w . jav  a2  s  .  c o m*/
 * @param name rig type name
 * @return rig type or null if not found
 */
public RigType findByName(String name) {
    Criteria cri = this.session.createCriteria(this.clazz);
    cri.add(Restrictions.eq("name", name));
    return (RigType) cri.uniqueResult();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.SessionDao.java

License:Open Source License

/**
 * Gets the users active session. If the user does not have an active 
 * session <code>null</code> is returned. If the user has multiple
 * active sessions, only the lastest (ordered by request time) is 
 * returned.//  www. j  av  a2  s  . com
 * 
 * @param user user to find active session of
 * @return active session or null
 */
@SuppressWarnings("unchecked")
public Session findActiveSession(User user) {
    Criteria cri = this.session.createCriteria(Session.class);
    cri.add(Restrictions.eq("user", user));
    cri.add(Restrictions.eq("active", Boolean.TRUE));
    cri.addOrder(Order.desc("requestTime"));
    cri.setMaxResults(1);

    List<Session> sessions = cri.list();
    if (sessions.size() == 0) {
        return null;
    }
    return sessions.get(0);
}