Interface CaldavCalendarSyncDAO

All Superinterfaces:
org.springframework.data.repository.CrudRepository<CaldavCalendarSyncEntity,Long>, org.springframework.data.jpa.repository.JpaRepository<CaldavCalendarSyncEntity,Long>, org.springframework.data.repository.ListCrudRepository<CaldavCalendarSyncEntity,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<CaldavCalendarSyncEntity,Long>, org.springframework.data.repository.PagingAndSortingRepository<CaldavCalendarSyncEntity,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<CaldavCalendarSyncEntity>, org.springframework.data.repository.Repository<CaldavCalendarSyncEntity,Long>

public interface CaldavCalendarSyncDAO extends org.springframework.data.jpa.repository.JpaRepository<CaldavCalendarSyncEntity,Long>
Persistence access to the calendar pairs.

Two shapes of read, deliberately kept apart. Everything scoped to one user on one server is read whole: a person has a handful of calendars, and paginating that would cost more than it saves. Everything that spans users — what the background sweep does — is paginated, because that set grows with the deployment and a full read of it would grow with it.

  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.data.domain.Page<CaldavCalendarSyncEntity>
    findByServerId(long serverId, org.springframework.data.domain.Pageable pageable)
    Every pair on one server, paginated.
    findByUserIdentityIdAndServerId(long userIdentityId, long serverId)
    Every pair a user holds on one server.
    findByUserIdentityIdAndServerIdAndLocalCalendarSyncUid(long userIdentityId, long serverId, String localCalendarSyncUid)
    The pair bound to one local calendar.
    findByUserIdentityIdAndServerIdAndOrigin(long userIdentityId, long serverId, org.exoplatform.caldav.model.SyncOrigin origin)
    The pairs of one origin a user holds on a server.
    org.springframework.data.domain.Page<CaldavCalendarSyncEntity>
    findDue(org.exoplatform.caldav.model.CalendarSyncStatus status, Date before, org.springframework.data.domain.Pageable pageable)
    Pairs in a given state whose last synchronisation ended before a cutoff, or has never ended.
    org.springframework.data.domain.Page<Long>
    findDueAccounts(org.exoplatform.caldav.model.CalendarSyncStatus status, Date before, org.springframework.data.domain.Pageable pageable)
    The users whose bindings are due, oldest first.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findByUserIdentityIdAndServerId

      List<CaldavCalendarSyncEntity> findByUserIdentityIdAndServerId(long userIdentityId, long serverId)
      Every pair a user holds on one server. The set the engine matches remote collections against, in memory: matching by href in SQL would need an index on a column too long for one on MySQL, and this set is small enough that the question does not arise.
      Parameters:
      userIdentityId - identity of the user
      serverId - declared server registration
      Returns:
      the user's pairs on that server, in no particular order
    • findByUserIdentityIdAndServerIdAndLocalCalendarSyncUid

      Optional<CaldavCalendarSyncEntity> findByUserIdentityIdAndServerIdAndLocalCalendarSyncUid(long userIdentityId, long serverId, String localCalendarSyncUid)
      The pair bound to one local calendar. The lookup the outbound half performs before deciding whether a calendar needs creating remotely.
      Parameters:
      userIdentityId - identity of the user
      serverId - declared server registration
      localCalendarSyncUid - agenda's immutable calendar anchor
      Returns:
      the pair, if the calendar is already bound
    • findByUserIdentityIdAndServerIdAndOrigin

      List<CaldavCalendarSyncEntity> findByUserIdentityIdAndServerIdAndOrigin(long userIdentityId, long serverId, org.exoplatform.caldav.model.SyncOrigin origin)
      The pairs of one origin a user holds on a server. Used with SyncOrigin.MIRROR to find the single mirror pair — a list rather than an optional because the database cannot enforce that uniqueness (the anchor is null there, and standard SQL leaves NULL rows outside a unique index), so the caller must be able to see a duplicate rather than have one silently picked for it.
      Parameters:
      userIdentityId - identity of the user
      serverId - declared server registration
      origin - which side created the collection
      Returns:
      the matching pairs
    • findDue

      @Query("SELECT p FROM CaldavCalendarSyncEntity p WHERE p.status = :status AND (p.lastSyncEnd IS NULL OR p.lastSyncEnd < :before)") org.springframework.data.domain.Page<CaldavCalendarSyncEntity> findDue(@Param("status") org.exoplatform.caldav.model.CalendarSyncStatus status, @Param("before") Date before, org.springframework.data.domain.Pageable pageable)
      Pairs in a given state whose last synchronisation ended before a cutoff, or has never ended. What the background sweep selects on.

      Written as JPQL rather than derived from the method name: the derived form of this predicate needs the status repeated on both sides of the OR, which produces a name nobody can read and a parameter that must be passed twice.

      Parameters:
      status - the state to select
      before - pairs last synchronised strictly before this instant
      pageable - page and sort; required, this set spans every user
      Returns:
      one page of due pairs
    • findDueAccounts

      @Query("SELECT p.userIdentityId FROM CaldavCalendarSyncEntity p WHERE p.status = :status AND (p.lastSyncEnd IS NULL OR p.lastSyncEnd < :before) GROUP BY p.userIdentityId ORDER BY MIN(COALESCE(p.lastSyncEnd, {d \'1970-01-01\'})) ASC") org.springframework.data.domain.Page<Long> findDueAccounts(@Param("status") org.exoplatform.caldav.model.CalendarSyncStatus status, @Param("before") Date before, org.springframework.data.domain.Pageable pageable)
      The users whose bindings are due, oldest first. The sweep works account by account, so this is the set it must page through. Paging the BINDINGS instead let one user's collections fill a whole batch — a user with forty of them, all stale after an outage, occupied every run and no other account was ever reached. Grouping puts one row per user in the page, so a batch of ten is ten users however many collections each of them holds. Ordered by each user's oldest binding, so the account waiting longest is served first.
      Parameters:
      status - the binding state that counts as sweepable
      before - bindings last synchronised strictly before this instant
      pageable - page and sort; required, this set spans every user
      Returns:
      one page of user identities
    • findByServerId

      org.springframework.data.domain.Page<CaldavCalendarSyncEntity> findByServerId(long serverId, org.springframework.data.domain.Pageable pageable)
      Every pair on one server, paginated. Used when a registration is deactivated or removed and its bindings have to be dealt with.
      Parameters:
      serverId - declared server registration
      pageable - page and sort; required, this set spans every user
      Returns:
      one page of pairs on that server