@Override public Set<EventCalendar> getOwnedItems(String id) { PersistenceManager pm = PMF.get().getPersistenceManager(); User user = (User) pm.getObjectById(User.class, id); Set<EventCalendar> result = user.getOwnedCalendars(); pm.close(); return result; }
public EventCalendar removeItem(String id, String itemId) { PersistenceManager pm = PMF.get().getPersistenceManager(); User user = pm.getObjectById(User.class, id); EventCalendarDao calDao = new EventCalendarDaoImpl(); EventCalendar cal = calDao.get(itemId); user.removeCalendar(cal); pm.makePersistent(user); pm.close(); return cal; }
public User setAdministrator(User obj) { PersistenceManager pm = PMF.get().getPersistenceManager(); User result = this.getComplete(obj.getId(), pm); if (result != null) { result.setAdministrator(obj.isAdministrator()); } pm.makePersistent(result); pm.close(); return result; }
public List<EventCalendar> getItems(String id, String zoneName) throws Exception { PersistenceManager pm = PMF.get().getPersistenceManager(); FetchPlan fp = pm.getFetchPlan().addGroup("userGroup"); fp.setMaxFetchDepth(1); User user = pm.detachCopy(pm.getObjectById(User.class, id)); pm.close(); EventCalendarDaoImpl eventDao = new EventCalendarDaoImpl(); List<EventCalendar> result = eventDao.getCalendarsById(user.getCalendarKeys(), 0); // addGeoLocatedCals(result, geoLoc, zoneName); return result; }
public EventCalendar addOwnedItem(String id, EventCalendar cal) { PersistenceManager pm = PMF.get().getPersistenceManager(); try { User user = pm.getObjectById(User.class, id); user.addOwnedCalendar(cal); pm.makePersistent(cal); pm.makePersistent(user); } catch (Exception e) { e.printStackTrace(); } finally { pm.close(); } return cal; }
private List<EventCalendar> getFollowingCals(String userId) throws Exception { PersistenceManager pm = PMF.get().getPersistenceManager(); FetchPlan fp = pm.getFetchPlan().addGroup("userGroup"); fp.setMaxFetchDepth(2); User user = pm.detachCopy(pm.getObjectById(User.class, userId)); pm.close(); log.info("Loading feed"); EventCalendarDaoImpl eventDao = new EventCalendarDaoImpl(); List<EventCalendar> cals = eventDao.getCalendarsById(user.getCalendarKeys(), 1); log.info("Loading feed: following cals count: " + cals.size()); for (EventCalendar cal : cals) cal.setSource("following"); return cals; }
public void removeOwnedItem(String id, String itemId) { PersistenceManager pm = PMF.get().getPersistenceManager(); User user = pm.getObjectById(User.class, id); EventCalendar cal = null; Set<EventCalendar> items = user.getOwnedCalendars(); for (EventCalendar item : items) { if (item.getId().equals(itemId)) { cal = item; pm.deletePersistent(cal); } } user.removeOwnedCalendar(cal); pm.makePersistent(user); pm.close(); }
public void updateOwnedItem(String id, EventCalendar cal) { PersistenceManager pm = PMF.get().getPersistenceManager(); User user = pm.getObjectById(User.class, id); Set<EventCalendar> items = user.getOwnedCalendars(); for (EventCalendar item : items) { if (item.getId().equals(cal.getId())) { try { item.merge(cal); item.setDateLastUpdated(new Date()); pm.makePersistent(item); } catch (Exception e) { e.printStackTrace(); } } } pm.close(); }
@Override public User update(User obj) { PersistenceManager pm = PMF.get().getPersistenceManager(); User result = this.getComplete(obj.getId(), pm); if (result != null) { obj.setAdministrator(result.isAdministrator()); try { result.merge(obj); result.setDateLastUpdated(new Date()); } catch (Exception e) { e.printStackTrace(); } } pm.makePersistent(result); pm.close(); return result; }