List of usage examples for org.hibernate Criteria list
public List list() throws HibernateException;
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.ConfigDao.java
License:Open Source License
/** * Returns the configuration values with the specified configuration key. * /*from ww w . j ava 2 s .c om*/ * @param key configuration key * @return list of matching configuration values */ @SuppressWarnings("unchecked") public List<Config> getConfig(String key) { Criteria crit = this.session.createCriteria(this.clazz); crit.add(Restrictions.eq("key", key)); return crit.list(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RequestCapabilitiesDao.java
License:Open Source License
/** * Adds a new request capabilities string. Adding a request rig capabilities string * involves creating the request capabilities record and computing all * the matches to the currently stored request capabilities. * <br />//from ww w .jav a 2 s. c o m * A match is defined as having each request capability token present * as a token of the rig capabilities string. That is, all matching * request capabilities strings are subsets of the rig capabililities * string. * <p /> * To denote tokens in a capabilities string, the comma (',') symbol * is used. * * @param capabilities rig capabilities string * @return rig capabilities persistent object */ @SuppressWarnings("unchecked") public RequestCapabilities addCapabilities(String capabilities) { Capabilities requestCaps = new Capabilities(capabilities); GenericDao<MatchingCapabilities> matchCapsDao = new GenericDao<MatchingCapabilities>(this.session, MatchingCapabilities.class); List<String> capsList = requestCaps.asCapabilitiesList(); /* Store the rig capabilities. */ RequestCapabilities reqCaps = this.persist(new RequestCapabilities(requestCaps.asCapabilitiesString())); /* Iterate through all the rig capabilities and store matches. */ Criteria cri = this.session.createCriteria(RigCapabilities.class); List<RigCapabilities> rigCapsList = cri.list(); Capabilities caps = new Capabilities(); for (RigCapabilities rigCaps : rigCapsList) { caps.setCapabilitiesString(rigCaps.getCapabilities()); if (caps.asCapabilitiesList().containsAll(capsList)) { /* Rig - Request capabilities match. */ MatchingCapabilities match = new MatchingCapabilities(); match.setId(new MatchingCapabilitiesId(rigCaps.getId(), reqCaps.getId())); match.setRequestCapabilities(reqCaps); match.setRigCapabilities(rigCaps); matchCapsDao.persist(match); } } this.session.refresh(reqCaps); return reqCaps; }
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 a v a2s .c o 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./* ww w . j a v a 2 s . co 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. * /* ww w . j a va 2s . c om*/ * @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.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.// ww w . ja va 2 s . c o m * * @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); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.SessionDao.java
License:Open Source License
/** * Returns all the currently active sessions. If no active sessions are * found, an empty list is returned./* w ww . j a va2 s. c o m*/ * * @return active sessions */ @SuppressWarnings("unchecked") public List<Session> findAllActiveSessions() { Criteria cri = this.session.createCriteria(Session.class); cri.add(Restrictions.eq("active", Boolean.TRUE)); return cri.list(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.SlaveableRigsDao.java
License:Open Source License
/** * Returns info for an active session on the specified rig * //from www. j a v a2s . c o m * @param user user to find active session of * @return active session or null */ @SuppressWarnings("unchecked") public SlaveableRigs getInfo(Rig rig) { Criteria cri = this.session.createCriteria(SlaveableRigs.class); cri.add(Restrictions.eq("rig", rig)); cri.addOrder(Order.desc("id")); cri.setMaxResults(1); List<SlaveableRigs> sessions = cri.list(); if (sessions.size() == 0) { return null; } return sessions.get(0); }
From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.SlaveableRigsDao.java
License:Open Source License
/** * Finishes the collaborative session//ww w. ja v a 2s . c o m * * @param user user to find active session of * @return active session or null */ @SuppressWarnings("unchecked") public void finishCol(Rig rig) { Criteria cri = this.session.createCriteria(SlaveableRigs.class); cri.add(Restrictions.eq("rig", rig)); cri.addOrder(Order.desc("id")); List<SlaveableRigs> sessions = cri.list(); for (SlaveableRigs s : sessions) { this.delete(s); } }
From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.pages.KeysPage.java
License:Open Source License
/** * Returns the list of keys for a user class. If the parameter 'historical' * is part of the request parameters and has a value of 'true', non-usable * keys are returned otherwise usable keys are returned. Usable keys are * those that are 'active', have remaining uses and have not elapsed * their expiry time. /*from ww w . ja v a2 s. c om*/ * * @param request request * @return list of permission keys * @throws JSONException */ @SuppressWarnings("unchecked") public JSONArray getList(HttpServletRequest request) throws JSONException { JSONArray arr = new JSONArray(); String className = request.getParameter("name"); if (className == null) { this.logger.warn("Unable to provide access key list because the user class name was not provided."); return arr; } Criteria qu = this.db.createCriteria(UserClassKey.class).add(Restrictions.eq("userTargeted", Boolean.FALSE)) .addOrder(Order.asc("id")); if ("true".equals(request.getAttribute("historical"))) { qu.add(Restrictions.disjunction().add(Restrictions.eq("active", Boolean.FALSE)) .add(Restrictions.eq("remaining", 0))) .add(Restrictions.or(Restrictions.isNull("expiry"), Restrictions.lt("expiry", new Date()))); } else { qu.add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.gt("remaining", 0)) .add(Restrictions.or(Restrictions.isNull("expiry"), Restrictions.gt("expiry", new Date()))); } qu = qu.createCriteria("userClass").add(Restrictions.eq("name", className)); for (UserClassKey key : (List<UserClassKey>) qu.list()) { JSONObject keyObj = new JSONObject(); keyObj.put("key", key.getRedeemKey()); keyObj.put("active", key.isActive()); keyObj.put("remaining", key.getRemaining()); arr.put(keyObj); } return arr; }