List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:org.infoglue.calendar.controllers.ResourceController.java
License:Open Source License
/** * This method returns a list of Events based on a number of parameters within a transaction * @return List//from w w w .jav a 2 s. c om * @throws Exception */ public List getEventList(Calendar calendar, java.util.Calendar startDate, java.util.Calendar endDate, Session session) throws Exception { Query q = session.createQuery( "from Event as event inner join fetch event.owningCalendar as calendar where event.owningCalendar = ? AND event.startDateTime >= ? AND event.endDateTime <= ? order by event.startDateTime"); q.setEntity(0, calendar); q.setCalendar(1, startDate); q.setCalendar(2, endDate); List list = q.list(); Iterator iterator = list.iterator(); while (iterator.hasNext()) { Object o = iterator.next(); Event event = (Event) o; } return list; }
From source file:org.jasig.ssp.dao.MapStatusReportDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<MapStatusReportPerson> getOffPlanPlansForOwner(Person owner) { String getAllActivePlanIdQuery = "select new org.jasig.ssp.transferobject.reports.MapStatusReportPerson(plan.id, plan.person.id, plan.person.schoolId, plan.programCode,plan.catalogYearCode,plan.person.firstName,plan.person.lastName,plan.person.coach.id,plan.owner.id) " + "from org.jasig.ssp.model.Plan plan , MapStatusReport msr " + "where msr.plan = plan and msr.planStatus = :planStatus and plan.owner = :owner"; Query query = createHqlQuery(getAllActivePlanIdQuery); List<MapStatusReportPerson> result = query.setEntity("owner", owner) .setString("planStatus", PlanStatus.OFF.name()).list(); return result; }
From source file:org.jasig.ssp.dao.MapStatusReportDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<MapStatusReportPerson> getOffPlanPlansForWatcher(Person watcher) { String getAllActivePlanIdQueryForWatcher = "select distinct new org.jasig.ssp.transferobject.reports.MapStatusReportPerson(plan.id, plan.person.id, plan.person.schoolId, plan.programCode,plan.catalogYearCode,plan.person.firstName,plan.person.lastName,plan.person.coach.id,plan.owner.id,ws.person.id) " + "from org.jasig.ssp.model.Plan plan , MapStatusReport msr , org.jasig.ssp.model.WatchStudent ws " + "where msr.plan = plan and msr.planStatus = :planStatus and msr.plan.person = ws.student and ws.person = :watcher"; Query query = createHqlQuery(getAllActivePlanIdQueryForWatcher); List<MapStatusReportPerson> result = query.setEntity("watcher", watcher) .setString("planStatus", PlanStatus.OFF.name()).list(); return result; }
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); }// ww w . ja va2s .com 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.db.GraphSession.java
License:Open Source License
public void deleteProcessInstance(ProcessInstance processInstance, boolean includeTasks, boolean includeJobs) { if (processInstance == null) throw new JbpmException("processInstance is null in JbpmSession.deleteProcessInstance()"); try {// ww w . j av a 2 s. c om // find the tokens Query query = session.getNamedQuery("GraphSession.findTokensForProcessInstance"); query.setEntity("processInstance", processInstance); List tokens = query.list(); // deleteSubProcesses Iterator iter = tokens.iterator(); while (iter.hasNext()) { Token token = (Token) iter.next(); deleteSubProcesses(token); } // jobs if (includeJobs) { query = session.getNamedQuery("GraphSession.deleteJobsForProcessInstance"); query.setEntity("processInstance", processInstance); query.executeUpdate(); } // tasks if (includeTasks) { query = session.getNamedQuery("GraphSession.findTaskInstanceIdsForProcessInstance"); query.setEntity("processInstance", processInstance); List taskInstanceIds = query.list(); query = session.getNamedQuery("GraphSession.deleteTaskInstancesById"); query.setParameterList("taskInstanceIds", taskInstanceIds); } // delete the logs for all the process instance's tokens query = session.getNamedQuery("GraphSession.selectLogsForTokens"); query.setParameterList("tokens", tokens); List logs = query.list(); iter = logs.iterator(); while (iter.hasNext()) { session.delete(iter.next()); } // then delete the process instance session.delete(processInstance); } catch (Exception e) { log.error(e); jbpmSession.handleException(); throw new JbpmException("couldn't delete process instance '" + processInstance.getId() + "'", e); } }
From source file:org.jbpm.db.GraphSession.java
License:Open Source License
void deleteSubProcesses(Token token) { Query query = session.getNamedQuery("GraphSession.findSubProcessInstances"); query.setEntity("processInstance", token.getProcessInstance()); List processInstances = query.list(); if (processInstances == null || processInstances.isEmpty()) { return;//from ww w . j a va 2 s .c o m } Iterator iter = processInstances.iterator(); while (iter.hasNext()) { ProcessInstance subProcessInstance = (ProcessInstance) iter.next(); subProcessInstance.setSuperProcessToken(null); token.setSubProcessInstance(null); deleteProcessInstance(subProcessInstance); } if (token.getChildren() != null) { iter = token.getChildren().values().iterator(); while (iter.hasNext()) { Token child = (Token) iter.next(); deleteSubProcesses(child); } } }
From source file:org.jbpm.db.GraphSession.java
License:Open Source License
public List findActiveNodesByProcessInstance(ProcessInstance processInstance) { List results = null;/* w w w. j a v a2 s . c o m*/ try { Query query = session.getNamedQuery("GraphSession.findActiveNodesByProcessInstance"); query.setEntity("processInstance", processInstance); results = query.list(); } catch (Exception e) { log.error(e); jbpmSession.handleException(); throw new JbpmException("couldn't active nodes for process instance '" + processInstance + "'", e); } return results; }
From source file:org.jbpm.db.GraphSession.java
License:Open Source License
public ProcessInstance getProcessInstance(ProcessDefinition processDefinition, String key) { ProcessInstance processInstance = null; try {//www . j a va 2 s. c om Query query = session.getNamedQuery("GraphSession.findProcessInstanceByKey"); query.setEntity("processDefinition", processDefinition); query.setString("key", key); processInstance = (ProcessInstance) query.uniqueResult(); } catch (Exception e) { log.error(e); jbpmSession.handleException(); throw new JbpmException("couldn't get process instance with key '" + key + "'", e); } return processInstance; }
From source file:org.jbpm.db.GraphSession.java
License:Open Source License
public ProcessInstance loadProcessInstance(ProcessDefinition processDefinition, String key) { ProcessInstance processInstance = null; try {/*from w w w . ja v a2s. c o m*/ Query query = session.getNamedQuery("GraphSession.findProcessInstanceByKey"); query.setEntity("processDefinition", processDefinition); query.setString("key", key); processInstance = (ProcessInstance) query.uniqueResult(); if (processInstance == null) { throw new JbpmException("no process instance was found with key " + key); } } catch (Exception e) { log.error(e); jbpmSession.handleException(); throw new JbpmException("couldn't load process instance with key '" + key + "'", e); } return processInstance; }
From source file:org.jbpm.db.LoggingSession.java
License:Open Source License
/** * collects the logs for a given token, ordered by creation time. *///from www . ja v a2 s. c om public List findLogsByToken(long tokenId) { List result = null; try { Token token = (Token) session.load(Token.class, new Long(tokenId)); Query query = session.getNamedQuery("LoggingSession.findLogsByToken"); query.setEntity("token", token); result = query.list(); } catch (Exception e) { log.error(e); jbpmSession.handleException(); throw new JbpmException("couldn't get logs for token '" + tokenId + "'", e); } return result; }