From 4cf31db9f9002dad279bb50856ff5d1b60cfb76d Mon Sep 17 00:00:00 2001 From: scrudden Date: Sat, 20 Jan 2018 16:20:17 +0000 Subject: [PATCH] Fix for issue #26. UpdateTravelTimes now working. Date formats also reset. --- .../db/structs/ArrivalDeparture.java | 4 ++-- .../java/org/transitime/db/structs/Match.java | 4 ++-- .../java/org/transitime/db/structs/Trip.java | 11 +++++++++- .../main/java/org/transitime/utils/Time.java | 22 +++++++++---------- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/transitime/src/main/java/org/transitime/db/structs/ArrivalDeparture.java b/transitime/src/main/java/org/transitime/db/structs/ArrivalDeparture.java index 64b3a01fd..31553899f 100755 --- a/transitime/src/main/java/org/transitime/db/structs/ArrivalDeparture.java +++ b/transitime/src/main/java/org/transitime/db/structs/ArrivalDeparture.java @@ -774,7 +774,7 @@ public static List getArrivalsDeparturesFromDb( IntervalTimer timer = new IntervalTimer(); // Get the database session. This is supposed to be pretty light weight - Session session = dbName != null ? HibernateUtils.getSession(dbName, true) : HibernateUtils.getSession(true); + Session session = dbName != null ? HibernateUtils.getSession(dbName, false) : HibernateUtils.getSession(true); // Create the query. Table name is case sensitive and needs to be the // class name instead of the name of the db table. @@ -827,7 +827,7 @@ public static Long getArrivalsDeparturesCountFromDb( IntervalTimer timer = new IntervalTimer(); Long count = null; // Get the database session. This is supposed to be pretty light weight - Session session = dbName != null ? HibernateUtils.getSession(dbName, true) : HibernateUtils.getSession(true); + Session session = dbName != null ? HibernateUtils.getSession(dbName, false) : HibernateUtils.getSession(true); // Create the query. Table name is case sensitive and needs to be the // class name instead of the name of the db table. diff --git a/transitime/src/main/java/org/transitime/db/structs/Match.java b/transitime/src/main/java/org/transitime/db/structs/Match.java index 0b4bf293b..a15c1831c 100644 --- a/transitime/src/main/java/org/transitime/db/structs/Match.java +++ b/transitime/src/main/java/org/transitime/db/structs/Match.java @@ -306,7 +306,7 @@ public static List getMatchesFromDb( IntervalTimer timer = new IntervalTimer(); // Get the database session. This is supposed to be pretty light weight - Session session = HibernateUtils.getSession(projectId, true); + Session session = HibernateUtils.getSession(projectId, false); // Create the query. Table name is case sensitive and needs to be the // class name instead of the name of the db table. @@ -352,7 +352,7 @@ public static Long getMatchesCountFromDb( IntervalTimer timer = new IntervalTimer(); // Get the database session. This is supposed to be pretty light weight - Session session = HibernateUtils.getSession(projectId, true); + Session session = HibernateUtils.getSession(projectId, false); // Create the query. Table name is case sensitive and needs to be the // class name instead of the name of the db table. diff --git a/transitime/src/main/java/org/transitime/db/structs/Trip.java b/transitime/src/main/java/org/transitime/db/structs/Trip.java index 0a7899bcf..c91194d9c 100644 --- a/transitime/src/main/java/org/transitime/db/structs/Trip.java +++ b/transitime/src/main/java/org/transitime/db/structs/Trip.java @@ -1183,7 +1183,16 @@ public static Long countTravelTimesForTrips(Session session, query.setInteger("rev", travelTimesRev); Long count = null; try { - Integer bcount = (Integer) query.uniqueResult(); + + Integer bcount; + if(query.uniqueResult() instanceof BigInteger) + { + bcount = ((BigInteger)query.uniqueResult()).intValue(); + }else + { + bcount = (Integer) query.uniqueResult(); + } + if (bcount != null) count = bcount.longValue(); } catch (HibernateException e) { diff --git a/transitime/src/main/java/org/transitime/utils/Time.java b/transitime/src/main/java/org/transitime/utils/Time.java index 2fddc8733..68ef2080e 100755 --- a/transitime/src/main/java/org/transitime/utils/Time.java +++ b/transitime/src/main/java/org/transitime/utils/Time.java @@ -77,29 +77,27 @@ public class Time { // These two are for reading in dates in various formats private static final DateFormat defaultDateFormat = - new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat.getDateInstance(DateFormat.SHORT); private static final DateFormat dateFormatDashesShortYear = - new SimpleDateFormat("MM-dd-yy"); - private static final DateFormat readableDateFormat = - new SimpleDateFormat("yyyy-MM-dd"); + new SimpleDateFormat("MM-dd-yyyy"); private static final DateFormat readableDateFormat24 = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); + new SimpleDateFormat("MM-dd-yyyy HH:mm:ss z"); private static final DateFormat readableDateFormat24NoSecs = - new SimpleDateFormat("yyyy-MM-dd HH:mm"); + new SimpleDateFormat("MM-dd-yyyy HH:mm"); private static final DateFormat readableDateFormat24Msec = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); + new SimpleDateFormat("MM-dd-yyyy HH:mm:ss.SSS z"); private static final DateFormat readableDateFormat24NoTimeZoneMsec = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + new SimpleDateFormat("MM-dd-yyyy HH:mm:ss.SSS"); private static final DateFormat readableDateFormat24NoTimeZoneNoMsec = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); private static final DateFormat timeFormat24 = new SimpleDateFormat("HH:mm:ss z"); @@ -120,11 +118,11 @@ public class Time { // Note that this one is not static. It is for when need to include // timezone via a Time object. private final DateFormat readableDateFormat24MsecForTimeZone = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); + new SimpleDateFormat("MM-dd-yyyy HH:mm:ss.SSS z"); private final DateFormat readableTimeFormatForTimeZone = new SimpleDateFormat("HH:mm:ss"); private final DateFormat readableDateFormatForTimeZone = - new SimpleDateFormat("yyyy-MM-dd"); + new SimpleDateFormat("MM-dd-yyyy"); // So can output headings and such with a consistent number of decimal places private static final DecimalFormat oneDigitFormat = new DecimalFormat("0.0"); @@ -444,7 +442,7 @@ public static Date parse(String datetimeStr) throws ParseException { /** * Parses the dateStr and returns a Date object. Format of - * date is "yyyy-MM-dd". + * date is "MM-dd-yyyy". * * @param dateStr * @return