List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Time Sheets in state by member// w ww . j av a 2 s . c o m * * @param teammember * @param status * @return */ @SuppressWarnings("unchecked") public List<Timesheet> hoursInState(Teammember teammember, String status) { String q = "SELECT ts FROM Timesheet ts " + "JOIN ts.employee e " + "JOIN e.teammembers tem " + "WHERE " + "ts.projectactivity = :projectactivity " + "AND ts.status = :status " + "AND tem = :teammember " + "AND ((ts.initDate between :since and :until) " + "OR (ts.endDate between :since and :until) " + "OR (:since between ts.initDate and ts.endDate) " + "OR (:until between ts.initDate and ts.endDate)) "; Query query = getSession().createQuery(q); query.setEntity("teammember", teammember); query.setEntity("projectactivity", teammember.getProjectactivity()); query.setDate("since", DateUtil.getFirstWeekDay(teammember.getDateIn())); query.setDate("until", DateUtil.getFirstWeekDay(teammember.getDateOut())); query.setString("status", status); return query.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Returns employee with all level (app) hours. * //from w ww .j a v a 2 s. c o m * @param initDate * @param endDate * @param user * @return */ @SuppressWarnings("unchecked") public List<ApprovalWrap> findTimesheetsAllApp(Date initDate, Date endDate, Employee user) { String activity = "(SELECT coalesce(SUM(" + "coalesce(tse.hoursDay1, 0D) + " + "coalesce(tse.hoursDay2, 0D) + " + "coalesce(tse.hoursDay3, 0D) + " + "coalesce(tse.hoursDay4, 0D) + " + "coalesce(tse.hoursDay5, 0D) + " + "coalesce(tse.hoursDay6, 0D) + " + "coalesce(tse.hoursDay7, 0D)), 0D) " + "FROM Timesheet tse " + "JOIN tse.projectactivity paSub " + "JOIN paSub.project pSub " + "WHERE tse.employee = e " + "AND tse.projectactivity is not null " + "AND tse.initDate = :initDate " + "AND tse.endDate= :endDate " + "AND ((pSub.status != :statusClosed AND pSub.status != :statusArchived) " + "OR ((pSub.status = :statusClosed OR pSub.status = :statusArchived) AND tse.status != :app0))) "; String operation = "(SELECT coalesce(SUM(" + "coalesce(tseo.hoursDay1, 0D) + " + "coalesce(tseo.hoursDay2, 0D) + " + "coalesce(tseo.hoursDay3, 0D) + " + "coalesce(tseo.hoursDay4, 0D) + " + "coalesce(tseo.hoursDay5, 0D) + " + "coalesce(tseo.hoursDay6, 0D) + " + "coalesce(tseo.hoursDay7, 0D)), 0D) " + "FROM Timesheet tseo " + "WHERE tseo.employee = e " + "AND tseo.operation is not null " + "AND tseo.initDate = :initDate " + "AND tseo.endDate = :endDate) "; String suggestReject = "(SELECT count(tss.suggestReject) " + " FROM Timesheet tss " + " WHERE tss.initDate = :initDate " + " AND tss.suggestReject IS TRUE " + " AND tss.employee = e) "; String q = "SELECT NEW es.sm2.openppm.core.model.wrap.ApprovalWrap( " + "e.idEmployee, " + "c.fullName," + "rp.name," + "coalesce(s.name,'')," + getHours(Constants.TIMESTATUS_APP0) + ", " + getHours(Constants.TIMESTATUS_APP1) + ", " + getHours(Constants.TIMESTATUS_APP2) + ", " + getHours(Constants.TIMESTATUS_APP3) + ", " + activity + ", " + operation + ", " + suggestReject + " ) " + "FROM Employee e " + "JOIN e.timesheets ts " + "JOIN e.contact c " + "JOIN e.resourcepool rp " + "LEFT JOIN e.seller s " + "WHERE ts.initDate = :initDate " + "AND ts.endDate = :endDate " + "AND e.performingorg = :performingOrg " + "GROUP BY e.idEmployee ,c.fullName "; Query query = getSession().createQuery(q); query.setString(Constants.TIMESTATUS_APP0, Constants.TIMESTATUS_APP0); query.setString(Constants.TIMESTATUS_APP1, Constants.TIMESTATUS_APP1); query.setString(Constants.TIMESTATUS_APP2, Constants.TIMESTATUS_APP2); query.setString(Constants.TIMESTATUS_APP3, Constants.TIMESTATUS_APP3); // Add filters. query.setDate("initDate", initDate); query.setDate("endDate", endDate); query.setEntity("performingOrg", user.getPerformingorg()); query.setString("statusClosed", Constants.STATUS_CLOSED); query.setString("statusArchived", Constants.STATUS_ARCHIVED); return query.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Find teemsheets for an employee/*from w ww. j a va2 s . c o m*/ * * @param initWeek * @param endWeek * @param employee * @return */ @SuppressWarnings("unchecked") public List<TimesheetWrap> findTimesheetsForEmployee(Date initWeek, Date endWeek, Employee employee) { String q = "SELECT DISTINCT NEW es.sm2.openppm.core.model.wrap.TimesheetWrap( " + "ts, " + "p.status," + "case when pa is null then 0 else pa.idActivity end, " + "case when pa is null then '' else pa.activityName end, " + "case when o is null then '' else o.operationName end, " + "case when p is null then 0 else p.idProject end, " + "case when p is null then '' else p.projectName end, " + "case when p is null then '' else p.chartLabel end, " + "case when p is null then '' else p.status end, " + "case when pm is null then 0 else pm.idEmployee end, " + "case when c is null then '' else c.fullName end) " + "FROM Timesheet ts " + "LEFT JOIN ts.employee e " + "LEFT JOIN ts.projectactivity pa " + "LEFT JOIN pa.project p " + "LEFT JOIN p.employeeByProjectManager pm " + "LEFT JOIN pm.contact c " + "LEFT JOIN ts.operation o " + "WHERE ts.employee = :employee " + "AND ts.initDate = :initWeek " + "AND ts.endDate = :endWeek " + "AND (((p.status = :statusClosed OR p.status = :statusArchived) AND ts.status = :app3) " + "OR (p.status != :statusClosed AND p.status != :statusArchived) " + "OR ts.operation is not null)"; Query query = getSession().createQuery(q); query.setDate("initWeek", initWeek); query.setDate("endWeek", endWeek); query.setEntity("employee", employee); query.setString("statusClosed", Constants.STATUS_CLOSED); query.setString("statusArchived", Constants.STATUS_ARCHIVED); query.setString("app3", Constants.TIMESTATUS_APP3); return query.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Returns employee with all level (app) hours. * /*from ww w .ja v a 2s .co m*/ * @param initDate * @param endDate * @param user * @return */ @SuppressWarnings("unchecked") public List<ApprovalWrap> findTimesheetsAllAppByProject(Date initDate, Date endDate, Employee user) { String suggestReject = "(SELECT count(tss.suggestReject) " + "FROM Timesheet tss " + "LEFT JOIN tss.projectactivity pjas " + "LEFT JOIN pjas.project prs " + "WHERE tss.initDate = :initDate " + "AND tss.suggestReject IS TRUE " + "AND tss.employee = e " + "AND prs = p) "; String q = "SELECT NEW es.sm2.openppm.core.model.wrap.ApprovalWrap( " + "e.idEmployee, " + "c.fullName, " + "p.idProject, " + "p.projectName, " + getHoursByProject(Constants.TIMESTATUS_APP0) + ", " + getHoursByProject(Constants.TIMESTATUS_APP1) + ", " + getHoursByProject(Constants.TIMESTATUS_APP2) + ", " + getHoursByProject(Constants.TIMESTATUS_APP3) + ", " + suggestReject + " ) " + "FROM Employee e " + "JOIN e.timesheets ts " + "JOIN e.contact c " + "JOIN ts.projectactivity pa " + "JOIN pa.project p " + "WHERE ts.initDate = :initDate " + "AND ts.endDate = :endDate " + "AND p.employeeByProjectManager = :pm " + "GROUP BY e.idEmployee , c.fullName, p.idProject, p.projectName "; Query query = getSession().createQuery(q); query.setString(Constants.TIMESTATUS_APP0, Constants.TIMESTATUS_APP0); query.setString(Constants.TIMESTATUS_APP1, Constants.TIMESTATUS_APP1); query.setString(Constants.TIMESTATUS_APP2, Constants.TIMESTATUS_APP2); query.setString(Constants.TIMESTATUS_APP3, Constants.TIMESTATUS_APP3); // Add filters. query.setDate("initDate", initDate); query.setDate("endDate", endDate); query.setEntity("pm", user); query.setString("statusClosed", Constants.STATUS_CLOSED); query.setString("statusArchived", Constants.STATUS_ARCHIVED); return query.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Find teemsheets for an employee by project * //from w w w .j a v a 2 s . c o m * @param initWeek * @param endWeek * @param employee * @return */ @SuppressWarnings("unchecked") public List<TimesheetWrap> findTimesheetsForEmployeeByProject(Date initWeek, Date endWeek, Employee employee, Project project) { String q = "SELECT DISTINCT NEW es.sm2.openppm.core.model.wrap.TimesheetWrap( " + "ts, " + "p.status," + "case when pa is null then 0 else pa.idActivity end, " + "case when pa is null then '' else pa.activityName end, " + "case when o is null then '' else o.operationName end, " + "case when p is null then 0 else p.idProject end, " + "case when p is null then '' else p.projectName end, " + "case when p is null then '' else p.chartLabel end, " + "case when p is null then '' else p.status end, " + "case when pm is null then 0 else pm.idEmployee end, " + "case when c is null then '' else c.fullName end) " + "FROM Timesheet ts " + "LEFT JOIN ts.employee e " + "LEFT JOIN ts.projectactivity pa " + "LEFT JOIN pa.project p " + "LEFT JOIN ts.operation o " + "LEFT JOIN p.employeeByProjectManager pm " + "LEFT JOIN pm.contact c " + "WHERE ts.employee = :employee " + "AND ts.initDate = :initWeek " + "AND ts.endDate = :endWeek " + "AND (p = :project OR ts.operation is not null ) " + "AND ((p.status = :statusClosed OR p.status = :statusArchived) " + "AND ts.status = :appLevel " + "OR (p.status != :statusClosed AND p.status != :statusArchived)" + "OR ts.operation is not null) "; Query query = getSession().createQuery(q); query.setDate("initWeek", initWeek); query.setDate("endWeek", endWeek); query.setEntity("employee", employee); query.setString("statusClosed", Constants.STATUS_CLOSED); query.setString("statusArchived", Constants.STATUS_ARCHIVED); query.setString("appLevel", Constants.TIMESTATUS_APP3); query.setEntity("project", project); return query.list(); }
From source file:fr.mael.microrss.dao.impl.ArticleDaoImpl.java
License:Open Source License
@Override public Article findLastArticle(Feed feed) { StringBuffer query = new StringBuffer("select a from Article a "); query.append("inner join a.feeds f "); query.append(// w w w . j a v a 2 s. c o m "where a.created = (select max(aa.created) from Article aa inner join aa.feeds ff where ff in (:feed)) "); query.append("and f in (:feed) "); query.append("order by a.id desc "); Query q = getSession().createQuery(query.toString()); q.setEntity("feed", feed); q.setMaxResults(1); return (Article) q.uniqueResult(); }
From source file:fr.mael.microrss.dao.impl.ArticleDaoImpl.java
License:Open Source License
@Override public Long nbArticlesForFeed(Feed feed) { StringBuffer query = new StringBuffer("select count(article) from Article article "); query.append("inner join article.feeds f "); query.append("where f in (:feed) "); Query q = getSession().createQuery(query.toString()); q.setEntity("feed", feed); return (Long) q.uniqueResult(); }
From source file:fr.mael.microrss.dao.impl.CategoryDaoImpl.java
License:Open Source License
@Override public Category collapse(Category category, boolean collapsed) { StringBuffer query = new StringBuffer("update Category cat set collapsed = :value "); query.append("where cat = :category "); Query q = getSessionFactory().getCurrentSession().createQuery(query.toString()); q.setEntity("category", category); q.setBoolean("value", collapsed); q.executeUpdate();//from ww w . j a v a 2 s . c o m return category; }
From source file:fr.mael.microrss.dao.impl.CategoryDaoImpl.java
License:Open Source License
@Override public List<Category> forUser(User user) { StringBuffer query = new StringBuffer("select distinct cat from Category cat "); query.append("left join fetch cat.userFeeds uf "); query.append("left join fetch uf.unreadUserFeed "); query.append("left join fetch uf.feed "); query.append("where cat.user = :user "); Query q = getSessionFactory().getCurrentSession().createQuery(query.toString()); q.setEntity("user", user); return (List<Category>) q.list(); }
From source file:fr.mael.microrss.dao.impl.UserArticleDaoImpl.java
License:Open Source License
@Override public List<UserArticle> articlesForFeedAndUser(User user, Feed feed, int start, int nb) { StringBuffer query = new StringBuffer("select ua from UserArticle ua "); query.append("inner join fetch ua.article a "); query.append("inner join fetch a.feeds f "); query.append("inner join f.userFeeds uf "); query.append("left join fetch ua.userLabels "); query.append("where uf.user = :user "); query.append("and ua.user = :user "); query.append("and f = :feed "); Query q = getSession().createQuery(query.toString()); q.setEntity("user", user); q.setEntity("feed", feed); q.setFirstResult(start);// w w w . ja va 2s . c o m q.setMaxResults(nb); return (List<UserArticle>) q.list(); }