List of usage examples for org.hibernate Query setDate
@Deprecated @SuppressWarnings("unchecked") default Query<R> setDate(String name, Date val)
From source file:org.glite.security.voms.admin.persistence.dao.VOMSUserDAO.java
License:Apache License
@SuppressWarnings("unchecked") public List<VOMSUser> findExpiredUsers() { Date now = new Date(); String queryString = "from VOMSUser u where u.endTime is not null and u.endTime < :now"; Query q = HibernateFactory.getSession().createQuery(queryString); q.setDate("now", now); return q.list(); }
From source file:org.headsupdev.agile.storage.HibernateStorage.java
License:Open Source License
public List<Event> getEvents(Date start) { Session session = getHibernateSession(); Query q = session.createQuery("from StoredEvent e where time >= :start order by time desc"); q.setDate("start", start); q.setReadOnly(true);//w w w.j a v a 2 s .co m return (List<Event>) q.list(); }
From source file:org.headsupdev.agile.storage.HibernateStorage.java
License:Open Source License
public List<Event> getEvents(Date start, Date end) { Session session = getHibernateSession(); Query q = session.createQuery("from StoredEvent e where time >= :start and time < :end order by time desc"); q.setDate("start", start); q.setDate("end", end); q.setReadOnly(true);/* w ww .ja v a 2s . c om*/ return (List<Event>) q.list(); }
From source file:org.iti.agrimarket.model.dao.UserOfferProductFixedDAO.java
@Override public List<UserOfferProductFixed> findUserOfferProductByDate(Date date, Date maxDate, String criteria) { return (List<UserOfferProductFixed>) getHibernateTemplate().execute(new HibernateCallback() { @Override/* ww w. j a va 2 s .c o m*/ public Object doInHibernate(Session session) throws HibernateException { try { Logger logger = LogManager.getLogger(UserOfferProductFixed.class); logger.debug(criteria); Query newCriteria = session .createQuery("from UserOfferProductFixed userOffer where date(userOffer.startDate) " + criteria + " :date " + (criteria.equals("between") ? " and :maxDate " : "")) .setDate("date", date); if (criteria.equals("between")) { newCriteria = newCriteria.setDate("maxDate", maxDate); } System.out.println(newCriteria.toString()); List<UserOfferProductFixed> results = newCriteria.list(); return results; } catch (Exception ex) { ex.printStackTrace(); return null; } } }); }
From source file:org.jasig.portlets.FeedbackPortlet.dao.hibernate.HibernateFeedbackStore.java
License:Apache License
@Override public long getFeedbackTotal(FeedbackQueryParameters params) { String role = params.getString(params.USER_ROLE); String feedbacktype = params.getString(params.FEEDBACK_TYPE); boolean comments = params.getBoolean(params.COMMENTS_ONLY_DISPLAYED); Date startDate = params.getDate(params.START_DISPLAY_DATE); Date endDate = params.getEndDate(params.END_DISPLAY_DATE); try {//from w w w.j a va 2 s . com final Session session = this.getSession(false); String sql = "select count(item.id) from FeedbackItem item"; if (role != null && !role.isEmpty()) { sql = sql.concat(!sql.contains(" where ") ? " where " : " and "); sql = sql.concat("userrole = :userrole"); } if (feedbacktype != null && !feedbacktype.isEmpty()) { sql = sql.concat(!sql.contains(" where ") ? " where " : " and "); sql = sql.concat("feedbacktype = :feedbacktype"); } if (comments != false) { sql = sql.concat(!sql.contains(" where ") ? " where " : " and "); sql = sql.concat("LENGTH(feedback) > 0"); } if (startDate != null && endDate != null) { sql = sql.concat(!sql.contains(" where ") ? " where " : " and "); sql = sql.concat("submissiontime BETWEEN :startDate AND :endDate"); } Query query = session.createQuery(sql); if (role != null && !role.isEmpty()) { query.setString("userrole", role); } if (feedbacktype != null && !feedbacktype.isEmpty()) { query.setString("feedbacktype", feedbacktype); } if (startDate != null && endDate != null) { query.setDate("startDate", startDate); query.setDate("endDate", endDate); } return (Long) query.uniqueResult(); } catch (HibernateException ex) { throw convertHibernateAccessException(ex); } }
From source file:org.jasig.ssp.dao.external.TermDao.java
License:Apache License
private void buildProgramSearchParamList(String tag, String programCode, Query hqlQuery) { hqlQuery.setDate("now", DateTimeUtils.midnight()); if (!StringUtils.isEmpty(programCode)) { hqlQuery.setString("programCode", programCode); }// ww w . ja v a2s . c om if (!StringUtils.isEmpty(tag)) { hqlQuery.setString("tag", tag); } }
From source file:org.jasig.ssp.dao.PersonSearchDao.java
License:Apache License
private void addBindParams(PersonSearchRequest personSearchRequest, Query query, Term currentTerm) { if (hasStudentId(personSearchRequest)) { final String wildcardedStudentIdOrNameTerm = new StringBuilder("%") .append(personSearchRequest.getSchoolId().toUpperCase()).append("%").toString(); query.setString("studentIdOrName", wildcardedStudentIdOrNameTerm); }/*from w ww . j a v a 2 s . c om*/ if (hasPlanExists(personSearchRequest)) { if (PersonSearchRequest.PLAN_EXISTS_ACTIVE.equals(personSearchRequest.getPlanExists())) { query.setInteger("planObjectStatus", ObjectStatus.ACTIVE.ordinal()); } else if (PersonSearchRequest.PLAN_EXISTS_INACTIVE.equals(personSearchRequest.getPlanExists())) { query.setInteger("planObjectStatus", ObjectStatus.INACTIVE.ordinal()); } else if (PersonSearchRequest.PLAN_EXISTS_NONE.equals(personSearchRequest.getPlanExists())) { // this is handled structurally (exists test) } else { query.setParameter("planObjectStatus", null); } } if (hasPlanStatus(personSearchRequest)) { PlanStatus param = null; if (PersonSearchRequest.PLAN_STATUS_ON_PLAN.equals(personSearchRequest.getPlanStatus())) { param = PlanStatus.ON; } if (PersonSearchRequest.PLAN_STATUS_OFF_PLAN.equals(personSearchRequest.getPlanStatus())) { param = PlanStatus.OFF; } if (PersonSearchRequest.PLAN_STATUS_ON_TRACK_SEQUENCE.equals(personSearchRequest.getPlanStatus())) { param = PlanStatus.ON_TRACK_SEQUENCE; } if (PersonSearchRequest.PLAN_STATUS_ON_TRACK_SUBSTITUTION.equals(personSearchRequest.getPlanStatus())) { param = PlanStatus.ON_TRACK_SUBSTITUTION; } query.setString("planStatus", param == null ? null : param.name()); } if (hasGpaCriteria(personSearchRequest)) { if (personSearchRequest.getGpaEarnedMin() != null) { query.setBigDecimal("gpaEarnedMin", personSearchRequest.getGpaEarnedMin()); } if (personSearchRequest.getGpaEarnedMax() != null) { query.setBigDecimal("gpaEarnedMax", personSearchRequest.getGpaEarnedMax()); } } if (hasCoach(personSearchRequest) || hasMyCaseload(personSearchRequest)) { Person me = null; Person coach = null; if (hasMyCaseload(personSearchRequest)) { me = securityService.currentlyAuthenticatedUser().getPerson(); } if (hasCoach(personSearchRequest)) { coach = personSearchRequest.getCoach(); } UUID queryPersonId = null; Person compareTo = null; if (me != null) { queryPersonId = me.getId(); compareTo = coach; } else if (coach != null) { queryPersonId = coach.getId(); compareTo = me; } // If me and coach aren't the same, the query is non-sensical, so set the 'queryPerson' to null which // will effectively force the query to return no results. if (queryPersonId != null && compareTo != null) { queryPersonId = queryPersonId.equals(compareTo.getId()) ? queryPersonId : null; } query.setParameter("coachId", queryPersonId); } if (hasAnyWatchCriteria(personSearchRequest)) { Person me = null; Person watcher = null; if (hasMyWatchList(personSearchRequest)) { me = securityService.currentlyAuthenticatedUser().getPerson(); } if (hasWatcher(personSearchRequest)) { watcher = personSearchRequest.getWatcher(); } UUID queryPersonId = null; Person compareTo = null; if (me != null) { queryPersonId = me.getId(); compareTo = watcher; } else if (watcher != null) { queryPersonId = watcher.getId(); compareTo = me; } // If me and watcher aren't the same, the query is non-sensical, so set the 'queryPerson' to null which // will effectively force the query to return no results. if (queryPersonId != null && compareTo != null) { queryPersonId = queryPersonId.equals(compareTo.getId()) ? queryPersonId : null; } query.setParameter("watcherId", queryPersonId); } if (hasDeclaredMajor(personSearchRequest)) { query.setString("programCode", personSearchRequest.getDeclaredMajor()); } if (hasHoursEarnedCriteria(personSearchRequest)) { if (personSearchRequest.getHoursEarnedMin() != null) { query.setBigDecimal("hoursEarnedMin", personSearchRequest.getHoursEarnedMin()); } if (personSearchRequest.getHoursEarnedMax() != null) { query.setBigDecimal("hoursEarnedMax", personSearchRequest.getHoursEarnedMax()); } } if (hasProgramStatus(personSearchRequest)) { query.setEntity("programStatus", personSearchRequest.getProgramStatus()); } if (hasSpecialServiceGroup(personSearchRequest)) { query.setEntity("specialServiceGroup", personSearchRequest.getSpecialServiceGroup()); } if (hasFinancialAidStatus(personSearchRequest)) { query.setString("sapStatusCode", personSearchRequest.getSapStatusCode()); } if (hasCurrentlyRegistered(personSearchRequest)) { query.setString("currentTerm", currentTerm.getCode()); } if (hasMyPlans(personSearchRequest)) { query.setEntity("owner", securityService.currentlyAuthenticatedUser().getPerson()); } if (hasBirthDate(personSearchRequest)) { query.setDate("birthDate", personSearchRequest.getBirthDate()); } query.setInteger("activeObjectStatus", ObjectStatus.ACTIVE.ordinal()); }
From source file:org.jbpm.test.load.async.JobExecutorTestCase.java
License:Open Source License
public boolean areJobsAvailable() { return commandService.execute(new Command<Boolean>() { private static final long serialVersionUID = 1L; public Boolean execute(Environment environment) { Session session = environment.get(Session.class); Query query = session.createQuery(jobsAvailableQueryText); query.setDate("now", new Date()); Long jobs = (Long) query.uniqueResult(); if (jobs.longValue() > 0) { log.debug("found " + jobs + " more jobs to process"); return true; }/* ww w. j av a 2s .co m*/ log.debug("no more jobs to process"); return false; } }); }
From source file:org.jrecruiter.dao.jpa.JobCountPerDayDaoJpa.java
/** {@inheritDoc} */ public JobCountPerDay getByDate(Date day) { Session session = (Session) entityManager.getDelegate(); Query query = session .createQuery("select jcpd from JobCountPerDay jcpd " + " where jcpd.jobDate = :jobDate "); query.setDate("jobDate", day); return (JobCountPerDay) query.uniqueResult(); }
From source file:org.jrecruiter.dao.jpa.JobCountPerDayDaoJpa.java
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public List<JobCountPerDay> getJobCountPerDayAndPeriod(Date fromDate, Date toDate) { Session session = (Session) entityManager.getDelegate(); Query query = session.createQuery("select jcpd from JobCountPerDay jcpd " + " where jcpd.jobDate >= :fromDate and jcpd.jobDate <= :toDate " + " order by jobDate asc"); query.setDate("fromDate", fromDate); query.setDate("toDate", toDate); List<JobCountPerDay> jobCountPerDayList = query.list(); return jobCountPerDayList; }