Answer the question
In order to leave comments, you need to log in
How to fix data sampling by time?
I have two fields in a table of type timestamp : date_departure and date_arrival .
And there is a corresponding QHL (I think that you can understand it in SQL) query for selecting data.
If my user entered the date_departure input field and did not enter date_arrival, then I call the first DAO functionality. If the user entered both fields - the second one.
I have:
public List<Schedule> getByStationsViaDate(Schedule schedule) {
return sessionFactory.getCurrentSession()
.createQuery("from Schedule where " +
"stationArrival = :stationArrival and " +
"stationDeparture = :stationDeparture and " +
"dateDeparture > :dateDeparture " +
"order by dateDeparture desc ")
.setParameter("stationArrival", schedule.getStationArrival())
.setParameter("stationDeparture", schedule.getStationDeparture())
.setParameter("dateDeparture", schedule.getDateDeparture())
.getResultList();
}
public List<Schedule> getByStationsViaDates(Schedule schedule) {
return sessionFactory.getCurrentSession()
.createQuery("from Schedule where " +
"stationArrival = :stationArrival and " +
"stationDeparture = :stationDeparture and " +
"dateDeparture > :dateDeparture and " +
"dateArrival < :dateArrival " +
"order by dateDeparture desc ")
.setParameter("stationArrival", schedule.getStationArrival())
.setParameter("stationDeparture", schedule.getStationDeparture())
.setParameter("dateDeparture", schedule.getDateDeparture())
.setParameter("dateArrival", schedule.getDateArrival())
.getResultList();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question