Interface IndividualResultRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<IndividualResult,,Long> org.springframework.data.jpa.repository.JpaRepository<@NonNull IndividualResult,,@NonNull Long> org.springframework.data.repository.ListCrudRepository<IndividualResult,,Long> org.springframework.data.repository.ListPagingAndSortingRepository<IndividualResult,,Long> org.springframework.data.repository.PagingAndSortingRepository<IndividualResult,,Long> org.springframework.data.repository.query.QueryByExampleExecutor<IndividualResult>,org.springframework.data.repository.Repository<IndividualResult,Long>
@Repository
public interface IndividualResultRepository
extends org.springframework.data.jpa.repository.JpaRepository<@NonNull IndividualResult,@NonNull Long>
The
IndividualResultRepository provides database access for IndividualResult
entities.-
Method Summary
Modifier and TypeMethodDescriptionfindByRaceIdWithGraph(Long raceId) Returns aListofIndividualResultfor the race with the givenraceId, ordered by theirrankascending.org.springframework.data.domain.Page<Race> findRacesByAthleteId(Long athleteId, org.springframework.data.domain.Pageable pageable) Returns aPageofracesthat have at least oneIndividualResultrecorded for the athlete with the givenathleteId, ordered by theirdatedescending and, as a tiebreaker, by theiriddescending.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByRaceIdWithGraph
@Query("SELECT ir FROM IndividualResult ir LEFT JOIN FETCH ir.athlete LEFT JOIN FETCH ir.team LEFT JOIN FETCH ir.sourceResult sr LEFT JOIN FETCH sr.team WHERE ir.race.id = :raceId ORDER BY ir.rank ASC") List<IndividualResult> findByRaceIdWithGraph(@Param("raceId") Long raceId) Returns aListofIndividualResultfor the race with the givenraceId, ordered by theirrankascending.The athlete, team, and source result are eagerly fetched to avoid N+1 queries when mapping to DTOs. For derived results (where
sourceResultis not null), the triathlon performance fields must be read from the source result.- Parameters:
raceId- the ID of the race to fetch results for- Returns:
- a
ListofIndividualResultfor the given race, ordered by rank
-
findRacesByAthleteId
@Query(value="SELECT DISTINCT r FROM Race r LEFT JOIN FETCH r.courses c LEFT JOIN FETCH c.event e WHERE EXISTS ( SELECT 1 FROM IndividualResult ir WHERE ir.race = r AND ir.athlete.id = :athleteId) ORDER BY r.date DESC, r.id DESC", countQuery="SELECT COUNT(DISTINCT r) FROM Race r WHERE EXISTS ( SELECT 1 FROM IndividualResult ir WHERE ir.race = r AND ir.athlete.id = :athleteId)") org.springframework.data.domain.Page<Race> findRacesByAthleteId(@Param("athleteId") Long athleteId, org.springframework.data.domain.Pageable pageable) Returns aPageofracesthat have at least oneIndividualResultrecorded for the athlete with the givenathleteId, ordered by theirdatedescending and, as a tiebreaker, by theiriddescending.- Parameters:
athleteId- the ID of the athlete to filter races bypageable- the pagination information- Returns:
- a
Pageofracesfor the given athlete, ordered by date and, as a tiebreaker, by id descending
-