List of usage examples for org.hibernate Query setTimestamp
@Deprecated @SuppressWarnings("unchecked") default Query<R> setTimestamp(String name, Date value)
From source file:com.medigy.service.impl.person.PatientWorklistServiceImpl.java
License:Open Source License
public PatientWorklistReturnValues getWorkList(final PatientWorklistParameters parameters) { final List<PatientWorkListItem> itemList = new ArrayList<PatientWorkListItem>(); Query patientWorkListQuery = null; // if for some reason no date is supplied, use todays date final Date selectedDate = parameters.getSelectedDate() != null ? parameters.getSelectedDate() : new Date(); final Date startingTime = parameters.getStartingTime(); final Date endingTime = parameters.getEndingTime(); Calendar cal = new GregorianCalendar(); final Date currentDate = new Date(); cal.setTime(currentDate);//w w w. j a v a2 s . c om // get current hour and minute final int currentHour = cal.get(Calendar.HOUR_OF_DAY); final int currentMinute = cal.get(Calendar.MINUTE); final String queryString = "SELECT \n" + "patient.id, \n" + "patient.lastName, \n" + "patient.firstName, \n" + "roles.person.id, \n" + "roles.person.lastName, \n " + "roles.person.firstName, \n" + "appt.scheduledTime, \n" + "appt.startTime, \n" + "appt.checkoutTime, \n" + "appt.id, \n" + "appt.patientType.label \n" + "FROM HealthCareEncounter appt \n" + " join appt.patient as patient \n" + " left join appt.roles as roles \n" + " with roles.type.id = " + HealthCareVisitRoleType.Cache.REQ_PHYSICIAN.getEntity().getSystemId() + " \n" + "WHERE \n" + " appt.scheduledTime >= :beforeTime and \n" + " appt.scheduledTime < :afterTime " + "ORDER BY \n" + " appt.scheduledTime, patient.lastName, patient.firstName"; // now set the calendar to the selected date and the current hour/minute cal.setTime(selectedDate); if (startingTime == null) { cal.set(Calendar.HOUR_OF_DAY, currentHour); cal.set(Calendar.MINUTE, currentMinute); // save this date! final Date baseComparisonTime = cal.getTime(); final int beforeMinutes = parameters.getBeforeMinutes(); final int afterMinutes = parameters.getAfterMinutes(); cal.add(Calendar.MINUTE, 0 - beforeMinutes); final Date beforeTime = cal.getTime(); cal.setTime(baseComparisonTime); cal.add(Calendar.MINUTE, afterMinutes); final Date afterTime = cal.getTime(); patientWorkListQuery = getSession().createQuery(queryString); patientWorkListQuery.setTimestamp("beforeTime", beforeTime); patientWorkListQuery.setTimestamp("afterTime", afterTime); } else { final Calendar startCal = new GregorianCalendar(); startCal.setTime(startingTime); final Calendar endCal = new GregorianCalendar(); endCal.setTime(endingTime); cal.set(Calendar.HOUR_OF_DAY, startCal.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, startCal.get(Calendar.MINUTE)); final Date beforeTime = cal.getTime(); cal.set(Calendar.HOUR_OF_DAY, endCal.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, endCal.get(Calendar.MINUTE)); final Date afterTime = cal.getTime(); patientWorkListQuery = getSession().createQuery(queryString); patientWorkListQuery.setTimestamp("beforeTime", beforeTime); patientWorkListQuery.setTimestamp("afterTime", afterTime); } final List list = patientWorkListQuery.list(); if (log.isInfoEnabled()) log.info(patientWorkListQuery.getQueryString() + " \n" + list.size()); final Map<Long, Float> accountBalance = getAccountBalance(parameters); //final Map<Long, Float> patientBalance = getPatientBalance(parameters); for (int i = 0; i < list.size(); i++) { final Object rowObject = list.get(i); if (rowObject instanceof Object[]) { final PatientWorkListItemImpl item = new PatientWorkListItemImpl(); final Object[] columnValues = (Object[]) rowObject; item.setPatientId((Long) columnValues[0]); item.setAccountBalance(accountBalance.get(item.getPatientId())); //item.setPatientBalance(patientBalance.get(item.getPatientId())); item.setPatientLastName((String) columnValues[1]); item.setPatientFirstName((String) columnValues[2]); item.setPhysicianId((Long) columnValues[3]); item.setPhysicianLastName((String) columnValues[4]); item.setPhysicianFirstName((String) columnValues[5]); item.setAppointmentTimestamp((Date) columnValues[6]); item.setCheckinTimestamp((Date) columnValues[7]); item.setCheckoutTimestamp((Date) columnValues[8]); item.setEncounterId((Long) columnValues[9]); item.setPatientType((String) columnValues[10]); itemList.add(item); } } return new PatientWorklistReturnValues() { public List<PatientWorkListItem> getItems() { return itemList; } public ServiceParameters getParameters() { return parameters; } public String getErrorMessage() { return null; } }; }
From source file:com.mimp.hibernate.HiberPersonal.java
public ArrayList<Log> getLogParticularPorDia(long idPersonal, String dia) { timeStampFormat timestamp = new timeStampFormat(); Session session = sessionFactory.getCurrentSession(); session.beginTransaction();/* w w w.j a v a 2 s . c o m*/ String diain = dia + " 00:00:00"; String diafin = dia + " 23:59:59"; String hql = "FROM Log L where L.personal = :id and L.fecha >= :diain and L.fecha <= :diafin"; Query query = session.createQuery(hql); query.setLong("id", idPersonal); query.setTimestamp("diain", timestamp.stringToTimestampLog(diain)); query.setTimestamp("diafin", timestamp.stringToTimestampLog(diafin)); List log = query.list(); ArrayList<Log> allLogsParticularPorDia = new ArrayList(); for (Iterator iter = log.iterator(); iter.hasNext();) { Log temp = (Log) iter.next(); Hibernate.initialize(temp.getPersonal()); allLogsParticularPorDia.add(temp); } return allLogsParticularPorDia; }
From source file:com.mimp.hibernate.HiberPersonal.java
public ArrayList<Log> getLogPersonalPorDia(String dia) { timeStampFormat timestamp = new timeStampFormat(); Session session = sessionFactory.getCurrentSession(); session.beginTransaction();//from ww w . j a v a 2s .c o m String diain = dia + " 00:00:00"; String diafin = dia + " 23:59:59"; String hql = "FROM Log L where L.fecha >= :diain and L.fecha <= :diafin"; Query query = session.createQuery(hql); query.setTimestamp("diain", timestamp.stringToTimestampLog(diain)); query.setTimestamp("diafin", timestamp.stringToTimestampLog(diafin)); List log = query.list(); ArrayList<Log> allLogsParticularPorDia = new ArrayList(); for (Iterator iter = log.iterator(); iter.hasNext();) { Log temp = (Log) iter.next(); Hibernate.initialize(temp.getPersonal()); allLogsParticularPorDia.add(temp); } return allLogsParticularPorDia; }
From source file:com.mx.teknei.pcabordo.lib.dao.impl.SfpfItinDAO.java
@Override public List<SfpfItin> compareTwoDatesInHora_Sali(Long dateMore, Long dateLess, int id_Ruta, int id_Estado) { List<SfpfItin> itin = null; Transaction trans = null;/*from ww w. jav a2s . co m*/ Session session = null; try { session = LoadConnection.getSessionFactory().openSession(); } catch (ExceptionInInitializerError eiie) { System.out.println("Error al iniciar la coneccion a BD postgres:" + eiie.getMessage()); } catch (Exception e) { System.err.println("Error en LoadConnection." + e.getMessage()); } try { trans = session.beginTransaction(); Query query = session.createQuery( "FROM SfpfItin AS c WHERE c.horaSaliItin BETWEEN :stDate AND :edDate AND sfruRuta = :ruta AND idEsta = :id_esta");//AND sfruRuta = :ruta AND idEsta = :id_esta" query.setTimestamp("stDate", new Timestamp(dateMore)); query.setTimestamp("edDate", new Timestamp(dateLess)); SfruRuta rutaEnty = new SfruRuta(); rutaEnty.setIdRuta(id_Ruta); query.setParameter("ruta", rutaEnty); query.setParameter("id_esta", id_Estado); itin = query.list(); } catch (Exception e) { System.out.println("-ERROR DAO:" + e.getMessage() + "--" + this.getClass().getSimpleName()); } finally { session.close(); } return itin; }
From source file:com.opengamma.masterdb.security.hibernate.HibernateSecurityMasterSession.java
License:Open Source License
private IdentifierAssociationBean createIdentifierAssociationBean(Date now, String scheme, String identifier, SecurityBean security) {//from www. j a va 2s . c om final IdentifierAssociationBean association = new IdentifierAssociationBean(security, new ExternalIdBean(scheme, identifier)); Query query = getSession().getNamedQuery("IdentifierAssociationBean.one.previousAssociation"); query.setString("scheme", scheme); query.setString("identifier", identifier); query.setTimestamp("now", now); IdentifierAssociationBean other = (IdentifierAssociationBean) query.uniqueResult(); if (other != null) { association.setValidStartDate(other.getValidEndDate()); } query = getSession().getNamedQuery("IdentifierAssociationBean.one.nextAssociation"); query.setString("scheme", scheme); query.setString("identifier", identifier); query.setTimestamp("now", now); other = (IdentifierAssociationBean) query.uniqueResult(); if (other != null) { association.setValidEndDate(other.getValidEndDate()); } Long id = (Long) getSession().save(association); association.setId(id); getSession().flush(); return association; }
From source file:com.opengamma.masterdb.security.hibernate.HibernateSecurityMasterSession.java
License:Open Source License
@Override public IdentifierAssociationBean getCreateOrUpdateIdentifierAssociationBean(Date now, String scheme, String identifier, SecurityBean security) { Query query = getSession().getNamedQuery("IdentifierAssociationBean.one.byDateIdentifier"); query.setString("scheme", scheme); query.setString("identifier", identifier); query.setTimestamp("now", now); IdentifierAssociationBean association = (IdentifierAssociationBean) query.uniqueResult(); if (association == null) { association = createIdentifierAssociationBean(now, scheme, identifier, security); } else {/*from www.j av a 2s .c o m*/ if (!association.getSecurity().getId().equals(security.getId())) { // terminate the previous record, and create a new one association.setValidEndDate(now); getSession().update(association); getSession().flush(); association = createIdentifierAssociationBean(now, scheme, identifier, security); } } return association; }
From source file:com.opengamma.masterdb.security.hibernate.HibernateSecurityMasterSession.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from ww w .ja v a2 s.c o m*/ public List<FutureBundleBean> getFutureBundleBeans(Date now, FutureSecurityBean future) { Query query; if (now != null) { query = getSession().getNamedQuery("FutureBundleBean.many.byDateFuture"); query.setTimestamp("now", now); } else { query = getSession().getNamedQuery("FutureBundleBean.many.byFuture"); } query.setParameter("future", future); return query.list(); }
From source file:com.opengamma.masterdb.security.hibernate.HibernateSecurityMasterSession.java
License:Open Source License
@Override public FutureBundleBean nextFutureBundleBean(Date now, FutureSecurityBean future) { Query query = getSession().getNamedQuery("FutureBundleBean.one.nextBundle"); query.setTimestamp("now", now); query.setParameter("future", future); return (FutureBundleBean) query.uniqueResult(); }
From source file:com.painiu.core.dao.hibernate.PhotoDAOHibernate.java
License:Open Source License
public List getInterestingnessPhotoIdsGroupByDate(final Date fromDate, final Date toDate, final int limit) { return (List) getReadOnlyHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query queryObject = session.getNamedQuery("getPhotoInterestingGroupByDate"); queryObject.setInteger("limit", limit); queryObject.setTimestamp("fromDate", fromDate); queryObject.setTimestamp("toDate", toDate); return queryObject.list(); }//from w w w . jav a 2 s .com }); }
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 ww w. j a v a 2s . com 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()); } }