Пример #1
0
  public void deleteEvent(Event event) {
    List<User> list = getUsers();
    Collection<Activity> activities = event.getActivities();
    Set<Activity> tmpActivities = new HashSet<Activity>();
    for (Activity activityEntity : activities) {
      tmpActivities.add(activityEntity);
    }
    for (User user : list) {
      boolean userUpdated = false;
      if (user.getEvents().contains(event)) {
        for (Activity activity : tmpActivities) {
          user.getActivities().remove(activity);
          event.getActivities().remove(activity);
        }
        user.getEvents().remove(event);
        userUpdated = true;
      }
      if (userUpdated) {
        updateObject(user);
      }
    }

    deleteObject(event);
    //        for (Activity activity : tmpActivities) {
    //            deleteObject(activity);
    //        }
  }
Пример #2
0
 public List<Activity> getActivities(Event parent) {
   List<Activity> result = new ArrayList<Activity>();
   Session session = SessionFactoryUtil.getInstance().getCurrentSession();
   try {
     Transaction transaction = session.beginTransaction();
     Object event =
         session
             .createQuery("from Event as event where event.idevent= " + parent.getIdevent())
             .uniqueResult();
     transaction.commit();
     if (event != null) {
       Event eventEntity = (Event) event;
       Collection<Activity> activityList = eventEntity.getActivities();
       for (Activity activity : activityList) {
         result.add(activity);
       }
     }
   } finally {
     if (session.isOpen()) {
       session.flush();
       session.disconnect();
       session.close();
     }
   }
   return result;
 }