Class EventDAO

java.lang.Object
org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl<EventEntity, Long>
org.exoplatform.agenda.dao.EventDAO
All Implemented Interfaces:
org.exoplatform.commons.api.persistence.GenericDAO<EventEntity, Long>

public class EventDAO extends org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl<EventEntity, Long>
  • Constructor Details

  • Method Details

    • delete

      public void delete(EventEntity entity)
      Specified by:
      delete in interface org.exoplatform.commons.api.persistence.GenericDAO<EventEntity, Long>
      Overrides:
      delete in class org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl<EventEntity, Long>
    • deleteCalendarEvents

      public void deleteCalendarEvents(long calendarId)
    • moveCalendarEvents

      public List<Long> moveCalendarEvents(long fromCalendarId, long toCalendarId)
      Moves all events of a calendar to another calendar in a single bulk update, keeping every event row (and its attendees, reminders, conferences, recurrences and remote identifiers) untouched apart from its calendar membership.
      Parameters:
      fromCalendarId - technical identifier of the calendar the events are moved away from
      toCalendarId - technical identifier of the calendar receiving the events
      Returns:
      List of technical identifiers of the moved events, empty when the source calendar had no events
    • deleteEventAfterRead

      public EventEntity deleteEventAfterRead(long eventId)
      Deletes an event whose attendees, conferences or reminders may have been read through this persistence context. They are deleted in bulk, which leaves such instances managed and pointing at a removed event when the context is flushed, so the pending changes are flushed and the context cleared first. The clear detaches every entity the persistence context holds, not only this event's children: a caller must not keep a managed entity across this call and rely on dirty checking or on a lazy collection of it afterwards.
      Parameters:
      eventId - the event to delete
      Returns:
      the deleted entity, null when there was none
    • deleteEvent

      public EventEntity deleteEvent(long eventId)
    • create

      public EventEntity create(EventEntity entity)
      Specified by:
      create in interface org.exoplatform.commons.api.persistence.GenericDAO<EventEntity, Long>
      Overrides:
      create in class org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl<EventEntity, Long>
    • update

      public EventEntity update(EventEntity entity)
      Specified by:
      update in interface org.exoplatform.commons.api.persistence.GenericDAO<EventEntity, Long>
      Overrides:
      update in class org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl<EventEntity, Long>
    • deleteAll

      public void deleteAll()
      Specified by:
      deleteAll in interface org.exoplatform.commons.api.persistence.GenericDAO<EventEntity, Long>
      Overrides:
      deleteAll in class org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl<EventEntity, Long>
    • updateAll

      public void updateAll(List<EventEntity> entities)
      Specified by:
      updateAll in interface org.exoplatform.commons.api.persistence.GenericDAO<EventEntity, Long>
      Overrides:
      updateAll in class org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl<EventEntity, Long>
    • executeDeleteCalendarEventsQuery

      public void executeDeleteCalendarEventsQuery(long calendarId)
    • getEventIds

      public List<Long> getEventIds(Date startDate, Date endDate, List<Long> ownerIds, List<Long> attendeeIds, List<org.exoplatform.agenda.constant.EventAttendeeResponse> responseTypes, List<Long> excludedCalendarIds, int limit)
      Retrieves the identifiers of the events matching a period and the given owner, attendee and response criteria.
      Parameters:
      startDate - beginning of the period, mandatory
      endDate - end of the period, null for an open period
      ownerIds - identity identifiers of the calendar owners to keep, empty or null to keep every owner
      attendeeIds - identity identifiers to filter on attendees, empty or null to ignore attendees
      responseTypes - attendee responses to keep, only used together with attendeeIds
      excludedCalendarIds - technical identifiers of the calendars whose events must be left out, whatever the owner criteria kept; empty or null to exclude nothing
      limit - maximum number of identifiers to return, 0 for no limit
      Returns:
      List of matching event technical identifiers
    • getEventIds

      public List<Long> getEventIds(Date startDate, Date endDate, List<Long> ownerIds, List<Long> attendeeIds, List<org.exoplatform.agenda.constant.EventAttendeeResponse> responseTypes, List<Long> excludedCalendarIds, List<Long> calendarIds, int limit)
      Retrieves the identifiers of the events matching a period and the given owner, attendee and response criteria, plus the events of some calendars whatever those criteria say (EXO-90357).

      One statement. The owner and attendee criteria form one conjunction, the listed calendars are or-ed with it: an event is kept when it matches the criteria, or when its calendar is listed. The attendee join becomes an outer one when calendars are listed, since an event of a shared calendar has no attendee row for the reader; DISTINCT keeps an event with several attendee rows once. The exclusion still applies to everything.

      Parameters:
      startDate - beginning of the period, mandatory
      endDate - end of the period, null for an open period
      ownerIds - identity identifiers of the calendar owners to keep, empty or null to keep every owner
      attendeeIds - identity identifiers to filter on attendees, empty or null to ignore attendees
      responseTypes - attendee responses to keep, only used together with attendeeIds
      excludedCalendarIds - technical identifiers of the calendars whose events must be left out, whatever else keeps them
      calendarIds - technical identifiers of the calendars whose events are kept whatever the owner and attendee criteria say; empty or null for none
      limit - maximum number of identifiers to return, 0 for no limit
      Returns:
      List of matching event technical identifiers
    • getUserEventCalenderIds

      public List<Long> getUserEventCalenderIds(Long userIdentityId)
    • getPendingEventIds

      public List<Long> getPendingEventIds(Long userIdentityId, List<Long> attendeeIds, List<Long> calenderIds, Date fromDate, int offset, int limit)
    • countPendingEvents

      public Long countPendingEvents(Long userIdentityId, List<Long> attendeeIds, List<Long> calenderIds, Date fromDate)
    • getPendingEventIdsByOwnerIds

      public List<Long> getPendingEventIdsByOwnerIds(Long userIdentityId, List<Long> ownerIds, List<Long> attendeeIds, Date fromDate, int offset, int limit)
    • countPendingEventsByOwnerIds

      public long countPendingEventsByOwnerIds(Long userIdentityId, List<Long> ownerIds, List<Long> attendeeIds, Date fromDate)
    • getEventDatePollIds

      public List<Long> getEventDatePollIds(Long userIdentityId, List<Long> attendeeIds, Date fromDate, int offset, int limit)
    • getEventDatePollIds

      public List<Long> getEventDatePollIds(Long userIdentityId, List<Long> attendeeIds, Date start, Date end)
    • countEventDatePolls

      public Long countEventDatePolls(List<Long> attendeeIds, Date fromDate)
    • getEventDatePollIdsByOwnerIds

      public List<Long> getEventDatePollIdsByOwnerIds(Long userIdentityId, List<Long> ownerIds, List<Long> attendeeIds, Date fromDate, int offset, int limit)
    • getEventDatePollIdsByOwnerIds

      public List<Long> getEventDatePollIdsByOwnerIds(Long userIdentityId, List<Long> ownerIds, List<Long> attendeeIds, Date start, Date end)
    • countEventDatePollsByOwnerIds

      public Long countEventDatePollsByOwnerIds(List<Long> ownerIds, List<Long> attendeeIds, Date fromDate)
    • getParentRecurrentEventIds

      public List<EventEntity> getParentRecurrentEventIds(Date startDate, Date endDate)
    • getExceptionalOccurenceIdsByPeriod

      public List<Long> getExceptionalOccurenceIdsByPeriod(long parentRecurrentEventId, Date startDate, Date endDate)
    • getExceptionalOccurenceIds

      public List<Long> getExceptionalOccurenceIds(long parentRecurrentEventId)
    • detachAll

      public void detachAll()
      Detaches every entity the thread's persistence context holds, after writing out what a running transaction has not flushed yet, so the next reads and deletes start from what the database holds. A bulk delete, as the attendee and reminder ones are, leaves the entities it removes managed: once an event was saved in the same context (agenda's reminder listener materialising a series' next days, say), deleting it fails at the flush on its attendee rows still referencing it. Nothing is lost: outside a transaction every write was already committed, and inside one it is flushed first. A caller that keeps a managed entity and uses it afterwards must reload it.
    • getExceptionalOccurences

      public List<EventEntity> getExceptionalOccurences(long parentRecurrentEventId)
      Reads the exceptional occurrences of a recurrent event in one statement, ordered by start date, with their recurrence fetched.
      Parameters:
      parentRecurrentEventId - a parent recurrent event technical identifier
      Returns:
      List of its exceptional occurrence rows
    • lockEvent

      public boolean lockEvent(long eventId)
      Locks an event row with a pessimistic write lock (SELECT … FOR UPDATE), held until the current transaction ends. It requires an active transaction, and every lock of the transaction must come before its first plain read: on MySQL and MariaDB, a plain read fixes the snapshot the following reads see. So it reads the row's identifier only, and loads no entity whose eager associations would be read right after it.

      No lock timeout is set: a transaction asking for a locked row, on a request thread or in the @Asynchronous ContentAgendaEventSyncListener, waits until the holder's transaction ends. The holder's decide step is the intended bound: it holds the lock for its own reads and writes, and publishes its broadcasts and notifications after the commit, but for the metadata broadcast social makes while the event's properties are saved. Past it, the database's own limit applies: InnoDB fails the waiting statement after innodb_lock_wait_timeout, 50 seconds by default; PostgreSQL waits as long as lock_timeout allows, without limit by default.

      Parameters:
      eventId - event technical identifier
      Returns:
      whether the row exists, and so is locked
    • getCapacityReachedDate

      public Date getCapacityReachedDate(long eventId)
      Reads when an event row's pool was marked as having reached its capacity, as the database holds it, not as an entity of the persistence context holds it. The changes of the persistence context are written first: on MySQL and MariaDB, whose plain reads see the snapshot of the transaction's first read, a row this transaction has updated is read with the mark last committed.
      Parameters:
      eventId - event technical identifier
      Returns:
      the instant, or null when the row is not marked or does not exist
    • saveCapacityReachedDate

      public void saveCapacityReachedDate(long eventId, Date capacityReachedDate)
      Writes when an event row's pool was marked as having reached its capacity, and nothing else of the row: the one update of a column a save of the whole row leaves as it is. It requires an active transaction: the mark is written under the event lock a decide step holds, never in a transaction of its own.
      Parameters:
      eventId - event technical identifier
      capacityReachedDate - the instant, or null to clear the mark
    • flushAndClear

      public void flushAndClear()
      Writes the pending changes of the thread's persistence context, then detaches every entity it holds, so that the next read loads its rows afresh.
    • deleteExceptionalOccurences

      public void deleteExceptionalOccurences(long parentRecurrentEventId)