public List<JourneyRoute> getJourneyRoutes(Journey journey) { JourneyRouteDao journeyRouteDao = daoSession.getJourneyRouteDao(); List<JourneyRoute> journeyRoutes = journeyRouteDao .queryBuilder() .where(JourneyRouteDao.Properties.Journey_id.eq(journey.getId())) .list(); Collections.sort( journeyRoutes, new Comparator<JourneyRoute>() { public int compare(JourneyRoute journeyRoute1, JourneyRoute journeyRoute2) { String routeNumber1 = journeyRoute1.getRoute().getNumber(); String routeNumber2 = journeyRoute2.getRoute().getNumber(); if (routeNumber1.equals(routeNumber2)) { routeNumber1 += journeyRoute1.getRoute().getHeadsign(); routeNumber2 += journeyRoute2.getRoute().getHeadsign(); } else { try { int routeNumberInt1 = Integer.parseInt(routeNumber1); int routeNumberInt2 = Integer.parseInt(routeNumber2); return new Integer(routeNumberInt1).compareTo(routeNumberInt2); } catch (NumberFormatException e) { /* ignore */ } } return routeNumber1.compareTo(routeNumber2); } }); return journeyRoutes; }
public void clearJourneyRoutesFromDatabase(Journey journey) { JourneyRouteDao journeyRouteDao = daoSession.getJourneyRouteDao(); journeyRouteDao .queryBuilder() .where(JourneyRouteDao.Properties.Journey_id.eq(journey.getId())) .buildDelete() .executeDeleteWithoutDetachingEntities(); journey.resetJourneyRouteList(); }