@Override public final void updateTrainingType(final ITraining training, final int typeIndex) { trainingDao.updateTrainingType(training, typeIndex); final List<ITraining> models = new ArrayList<>(); models.add(trainingDao.getTrainingByDate(training.getDatum())); cache.addAll(models); }
// -------------------------------TRAINING-------------------------------------------------- @Override public final List<ITraining> getAllTrainings(final IAthlete athlete) { if (cache.isEmpty()) { cache.addAll(trainingDao.getAllTrainings(athlete)); LOGGER.info(String.format("load %s records from database", cache.size())); // $NON-NLS-1$ } return cache.getAll(athlete); }
@Override public final void saveOrUpdateAll(final Collection<ITraining> trainings) { final List<ITraining> cachedTrainings = new ArrayList<>(); for (final ITraining training : trainings) { trainingDao.saveOrUpdate(training); cachedTrainings.add(training); } if (!cachedTrainings.isEmpty()) { cache.addAll(cachedTrainings); } }
@Override public final ITraining getTrainingById(final long datum) { ITraining training = cache.get(datum); if (training == null) { training = trainingDao.getTrainingByDate(datum); if (training != null) { final List<ITraining> models = new ArrayList<>(); models.add(training); cache.addAll(models); } } return training; }
@Override public final List<ITraining> getAllTrainingByRoute(final IAthlete athlete, final IRoute route) { LOGGER.info("Load records direct from database [getAllTrainingByRoute]"); // $NON-NLS-1$ return trainingDao.getAllTrainingsByRoute(athlete, route); }
@Override public List<ITraining> getTrainingsByAthleteAndDate( final IAthlete athlete, final DateTime von, final DateTime bis) { LOGGER.info("Load records direct from database [getTrainingsByAthleteAndDate]"); // $NON-NLS-1$ return trainingDao.getTrainingsByAthleteAndDate(athlete, von, bis); }
@Override public final void removeTrainingByDate(final long datum) { trainingDao.removeTrainingByDate(datum); cache.remove(datum); }
@Override public final ITraining getNewestTraining(final IAthlete athlete) { return trainingDao.getNewestTraining(athlete); }
@Override public final int saveOrUpdate(final ITraining training) { final int id = trainingDao.saveOrUpdate(training); cache.addAll(Arrays.asList(training)); return id; }