Ejemplo n.º 1
0
  @Override
  public List<Lecture> save(List<Lecture> lectures) {
    try {
      Dao<Lecture, Integer> lDao = getDao();
      Dao<Speaker, Integer> sDao = getSpeakerDao();
      Dao<LectureSpeaker, Integer> lsDao = getLectureSpeakerDao();
      Dao<Category, Integer> cDao = getCategoryDao();
      Dao<Place, Integer> pDao = getPlaceDao();

      for (Lecture lecture : lectures) {
        pDao.createIfNotExists(lecture.getPlace());
        cDao.createIfNotExists(lecture.getCategory());

        lecture.setUserFavorite(false);
        lDao.createIfNotExists(lecture);
        for (Speaker s1 : lecture.getSpeakers()) {
          Speaker s2 = sDao.createIfNotExists(s1);
          lsDao.create(new LectureSpeaker(lecture, s2));
        }
      }
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
    return lectures;
  }