List of usage examples for org.hibernate Query setDate
@Deprecated @SuppressWarnings("unchecked") default Query<R> setDate(String name, Date val)
From source file:com.ocare.obook.dao.impl.ReservationDaoImpl.java
@Override public List<StatisticReportModule> getReservationReportWithRange(final Date fromDate, final Date toDate) { return getHibernateTemplate().execute(new HibernateCallback<List<StatisticReportModule>>() { @Override/*from w ww.ja v a 2 s . co m*/ public List<StatisticReportModule> doInHibernate(Session sn) throws HibernateException { Query query = sn.createQuery( "select ex.nameEn as moduleName ,count(ex.nameEn) as occuranceNumber , sum(r.paid) as moduleSum from Reservation r inner join r.examineType ex where r.status =:status and r.reservationDate BETWEEN :fromDate AND :toDate group by ex.nameEn"); query.setString("status", "CONFIRMED"); query.setDate("fromDate", fromDate); query.setDate("toDate", toDate); List<StatisticReportModule> reportReservationStatuses = query .setResultTransformer(Transformers.aliasToBean(StatisticReportModule.class)).list(); // return result List return reportReservationStatuses; } }); }
From source file:com.ocare.obook.dao.impl.ReservationDaoImpl.java
@Override public List<StatisticReportModule> getInsuranceReportWithRange(final Date fromDate, final Date toDate) { return getHibernateTemplate().execute(new HibernateCallback<List<StatisticReportModule>>() { @Override/*from ww w. ja va 2 s.co m*/ public List<StatisticReportModule> doInHibernate(Session sn) throws HibernateException { Query query = sn.createQuery( "select i.nameEn as moduleName ,count(i.nameEn) as occuranceNumber , sum(r.paid) as moduleSum from Reservation r inner join r.patient p inner join p.insuranceCompany i where r.status =:status and r.reservationDate BETWEEN :fromDate AND :toDate group by i.nameEn"); query.setString("status", "CONFIRMED"); query.setDate("fromDate", fromDate); query.setDate("toDate", toDate); List<StatisticReportModule> reportReservationStatuses = query .setResultTransformer(Transformers.aliasToBean(StatisticReportModule.class)).list(); // return result List return reportReservationStatuses; } }); }
From source file:com.ocare.obook.dao.impl.ReservationDaoImpl.java
@Override public List<Reservation> getDoneReservationsForShift(final Date day, final Integer shift) { return getHibernateTemplate().execute(new HibernateCallback<List<Reservation>>() { @Override/*from w w w .j a va 2 s . c o m*/ public List<Reservation> doInHibernate(Session sn) throws HibernateException { Query query = sn.createQuery( "select r from Reservation r inner join r.workingTime wt where r.reservationDate = :day and wt.id= :shift and r.status= :status order by attendenceTimeTo asc"); query.setDate("day", day); query.setString("status", "CONFIRMED"); query.setInteger("shift", shift); return (List<Reservation>) query.list(); } }); }
From source file:com.qcadoo.model.internal.search.SearchQueryImpl.java
License:Open Source License
@Override public void addParameters(final Query query) { for (Map.Entry<String, String> parameter : strings.entrySet()) { query.setString(parameter.getKey(), parameter.getValue()); }/*from w ww. jav a 2s .c o m*/ for (Map.Entry<String, Boolean> parameter : booleans.entrySet()) { query.setBoolean(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Byte> parameter : bytes.entrySet()) { query.setByte(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Short> parameter : shorts.entrySet()) { query.setShort(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Integer> parameter : integers.entrySet()) { query.setInteger(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Long> parameter : longs.entrySet()) { query.setLong(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Float> parameter : floats.entrySet()) { query.setFloat(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Double> parameter : doubles.entrySet()) { query.setDouble(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, BigDecimal> parameter : bigDecimals.entrySet()) { query.setBigDecimal(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : dates.entrySet()) { query.setDate(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : times.entrySet()) { query.setTime(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : timestamps.entrySet()) { query.setTimestamp(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Object> parameter : parameters.entrySet()) { query.setParameter(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Collection<? extends Object>> parametersList : parameterLists.entrySet()) { query.setParameterList(parametersList.getKey(), parametersList.getValue()); } for (Map.Entry<String, Object> parameter : entities.entrySet()) { query.setEntity(parameter.getKey(), parameter.getValue()); } }
From source file:com.salesmanager.core.service.catalog.impl.db.dao.ProductDao.java
License:Open Source License
public void updateProductListAvailability(boolean available, int merchantId, List<Long> ids) { try {/* w ww . ja v a2s .c om*/ Query q = super.getSession().createQuery( "update Product p set p.productDateAvailable=:pda where p.merchantId=:mId and p.productId in(:pId)") .setParameterList("pId", ids).setInteger("mId", merchantId); if (!available) { Calendar c1 = Calendar.getInstance(); c1.add(Calendar.YEAR, 100); q.setDate("pda", c1.getTime()); } else { q.setDate("pda", new Date(new Date().getTime())); } q.executeUpdate(); } catch (RuntimeException re) { log.error("update failed", re); throw re; } }
From source file:com.salesmanager.core.service.order.impl.dao.OrderDao.java
License:Open Source License
public SearchOrderResponse searchInvoice(SearchOrdersCriteria searchCriteria) { Criteria criteria = super.getSession().createCriteria(Order.class) .add(Restrictions.eq("merchantId", searchCriteria.getMerchantId())) .add(Restrictions.eq("channel", OrderConstants.INVOICE_CHANNEL)) .add(Restrictions.eq("orderStatus", OrderConstants.STATUSINVOICED)) .addOrder(org.hibernate.criterion.Order.desc("orderId")) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); StringBuffer q = new StringBuffer(); q.append(" select o from Order o where o.merchantId=:mId"); q.append(" and channel=:channel and orderStatus=:status"); if (searchCriteria != null) { if (!StringUtils.isBlank(searchCriteria.getCustomerName())) { q.append(" and o.customerName like %:cName%"); }//from ww w . j a v a2s . c om if (searchCriteria.getOrderId() != -1) { q.append(" and o.orderId=:oId"); } if (searchCriteria.getEdate() != null || searchCriteria.getSdate() != null) { if (searchCriteria.getSdate() != null) { q.append(" and o.datePurchased > :sDate"); } else { q.append(" and o.datePurchased > :sDate"); } if (searchCriteria.getEdate() != null) { q.append(" and o.datePurchased < :eDate"); } else { q.append(" and o.datePurchased < :eDate"); } } } q.append(" order by o.orderId desc"); Query c = super.getSession().createQuery(q.toString()); c.setInteger("channel", OrderConstants.INVOICE_CHANNEL); c.setInteger("status", OrderConstants.STATUSINVOICED); c.setInteger("mId", searchCriteria.getMerchantId()); if (searchCriteria != null) { if (!StringUtils.isBlank(searchCriteria.getCustomerName())) { criteria.add(Restrictions.like("customerName", "%" + searchCriteria.getCustomerName() + "%")); c.setString("cName", "%" + searchCriteria.getCustomerName() + "%"); } if (searchCriteria.getOrderId() != -1) { criteria.add(Restrictions.eq("orderId", searchCriteria.getOrderId())); c.setLong("oId", searchCriteria.getOrderId()); } if (searchCriteria.getEdate() != null || searchCriteria.getSdate() != null) { if (searchCriteria.getSdate() != null) { criteria.add(Restrictions.ge("datePurchased", searchCriteria.getSdate())); c.setDate("sDate", searchCriteria.getSdate()); } else { criteria.add(Restrictions.ge("datePurchased", DateUtils.addDays(new Date(), -1))); c.setDate("sDate", DateUtils.addDays(new Date(), -1)); } if (searchCriteria.getEdate() != null) { criteria.add(Restrictions.le("datePurchased", searchCriteria.getEdate())); c.setDate("eDate", searchCriteria.getEdate()); } else { criteria.add(Restrictions.ge("datePurchased", DateUtils.addDays(new Date(), +1))); c.setDate("eDate", DateUtils.addDays(new Date(), +1)); } } } criteria.setProjection(Projections.rowCount()); Integer count = (Integer) criteria.uniqueResult(); criteria.setProjection(null); int max = searchCriteria.getQuantity(); List list = null; if (max != -1 && count > 0) { list = c.setMaxResults(searchCriteria.getUpperLimit(count)) .setFirstResult(searchCriteria.getLowerLimit()).list(); } else { list = c.list(); } SearchOrderResponse response = new SearchOrderResponse(); response.setCount(count); response.setOrders(list); return response; }
From source file:com.salesmanager.core.service.order.impl.dao.OrderDao.java
License:Open Source License
public SearchOrderResponse searchOrder(SearchOrdersCriteria searchCriteria) { Criteria criteria = super.getSession().createCriteria(Order.class) .add(Restrictions.eq("merchantId", searchCriteria.getMerchantId())) .add(Restrictions.eq("channel", OrderConstants.ONLINE_CHANNEL)) .addOrder(org.hibernate.criterion.Order.desc("orderId")) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); StringBuffer q = new StringBuffer(); q.append(" select o from Order o where o.merchantId=:mId"); q.append(" and channel=:channel"); if (searchCriteria != null) { if (!StringUtils.isBlank(searchCriteria.getCustomerName())) { q.append(" and o.customerName like :cName"); }/*from w w w. jav a2 s.c om*/ if (searchCriteria.getOrderId() != -1) { q.append(" and o.orderId= :oId"); } if (searchCriteria.getEdate() != null || searchCriteria.getSdate() != null) { if (searchCriteria.getSdate() != null) { q.append(" and o.datePurchased > :sDate"); } else { q.append(" and o.datePurchased > :sDate"); } if (searchCriteria.getEdate() != null) { q.append(" and o.datePurchased < :eDate"); } else { q.append(" and o.datePurchased < :eDate"); } } } q.append(" order by o.orderId desc"); Query c = super.getSession().createQuery(q.toString()); c.setInteger("channel", OrderConstants.ONLINE_CHANNEL); c.setInteger("mId", searchCriteria.getMerchantId()); if (searchCriteria != null) { if (!StringUtils.isBlank(searchCriteria.getCustomerName())) { criteria.add(Restrictions.like("customerName", "%" + searchCriteria.getCustomerName() + "%")); c.setString("cName", "%" + searchCriteria.getCustomerName() + "%"); } if (searchCriteria.getOrderId() != -1) { criteria.add(Restrictions.eq("orderId", searchCriteria.getOrderId())); c.setLong("oId", searchCriteria.getOrderId()); } if (searchCriteria.getEdate() != null || searchCriteria.getSdate() != null) { if (searchCriteria.getSdate() != null) { criteria.add(Restrictions.ge("datePurchased", searchCriteria.getSdate())); c.setDate("sDate", searchCriteria.getSdate()); } else { criteria.add(Restrictions.ge("datePurchased", DateUtils.addDays(new Date(), -1))); c.setDate("sDate", DateUtils.addDays(new Date(), -1)); } if (searchCriteria.getEdate() != null) { criteria.add(Restrictions.le("datePurchased", searchCriteria.getEdate())); c.setDate("eDate", searchCriteria.getEdate()); } else { criteria.add(Restrictions.ge("datePurchased", DateUtils.addDays(new Date(), +1))); c.setDate("eDate", DateUtils.addDays(new Date(), +1)); } } } criteria.setProjection(Projections.rowCount()); Integer count = (Integer) criteria.uniqueResult(); criteria.setProjection(null); int max = searchCriteria.getQuantity(); List list = null; if (max != -1 && count > 0) { c.setMaxResults(searchCriteria.getUpperLimit(count)); c.setFirstResult(searchCriteria.getLowerLimit()); list = c.list(); } else { list = c.list(); } SearchOrderResponse response = new SearchOrderResponse(); response.setCount(count); response.setOrders(list); return response; }
From source file:com.springmvc.videoteca.spring.dao.PeliculaDAOImpl.java
public List<Pelicula> findEstrenos() { Date semanaAnterior;/* w w w .j a v a2 s .c om*/ semanaAnterior = obtenerSemanaAnterior(); Query q = super.getSession().createQuery("SELECT p FROM Pelicula p WHERE p.fechaestreno >= :fecha "); q.setDate("fecha", semanaAnterior); return q.list(); }
From source file:com.sumaga.learnerssystem.daoimpl.ClassDetailsDAOImpl.java
public ArrayList<Classdetails> getClassDetailByDate(Date date) { Session session = getSession();// ww w. j a v a2 s.c o m session.beginTransaction(); Query namedQuery = session.getNamedQuery("Classdetails.findByDate"); namedQuery.setDate("date", date); List list = namedQuery.list(); session.getTransaction().commit(); session.close(); return (ArrayList<Classdetails>) list; }
From source file:com.sumaga.learnerssystem.daoimpl.LpermitDAOImpl.java
public ArrayList<Lpermit> getLPermitByDate(Date date) { Session openSession = getSession();/*from ww w .ja v a2 s .co m*/ openSession.beginTransaction(); Query namedQuery = openSession.getNamedQuery("Lpermit.findByIssueDate"); namedQuery.setDate("date", date); List list = namedQuery.list(); openSession.getTransaction().commit(); openSession.close(); return (ArrayList<Lpermit>) list; }