Interface EventRepository

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

@Repository public interface EventRepository extends org.springframework.data.jpa.repository.JpaRepository<@NonNull Event,@NonNull Long>
The EventRepository provides database access for Event entities.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.data.domain.Page<Event>
    findByEventYear(int year, org.springframework.data.domain.Pageable pageable)
    Returns a Page of events whose startDate falls within the given year, ordered by their start date descending.
    Finds an Event by its ID and year with the full object graph eagerly fetched (courses, distances, and races).
    Returns all distinct years extracted from the startDate of existing events, ordered descending.

    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

    • findByEventYear

      @Query(value="SELECT DISTINCT e FROM Event e LEFT JOIN FETCH e.courses WHERE YEAR(e.startDate) = :year ORDER BY e.startDate DESC", countQuery="SELECT COUNT(DISTINCT e) FROM Event e WHERE YEAR(e.startDate) = :year") org.springframework.data.domain.Page<Event> findByEventYear(@Param("year") int year, org.springframework.data.domain.Pageable pageable)
      Returns a Page of events whose startDate falls within the given year, ordered by their start date descending.
      Parameters:
      year - the year to filter events by
      pageable - the pagination information
      Returns:
      a Page of events for the given year, ordered by start date descending
    • findByIdAndYearWithGraph

      @Query("SELECT DISTINCT e FROM Event e LEFT JOIN FETCH e.courses c LEFT JOIN FETCH c.distance LEFT JOIN FETCH c.races LEFT JOIN FETCH e.eventFiles WHERE e.id = :id AND YEAR(e.startDate) = :year") Optional<Event> findByIdAndYearWithGraph(@Param("id") Long id, @Param("year") int year)
      Finds an Event by its ID and year with the full object graph eagerly fetched (courses, distances, and races). This avoids N+1 queries and ensures Hibernate constructs the correct concrete subclass instances for the joined-table inheritance hierarchy of Distance.
      Parameters:
      id - the event ID
      year - the year to filter events by
      Returns:
      the event with its associated courses, distances, and races, or empty if not found
    • findDistinctYears

      @Query("SELECT DISTINCT YEAR(e.startDate) FROM Event e ORDER BY YEAR(e.startDate) DESC") List<Integer> findDistinctYears()
      Returns all distinct years extracted from the startDate of existing events, ordered descending.
      Returns:
      a list of distinct years in descending order