Interface ArticleRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Article,,Long> org.springframework.data.jpa.repository.JpaRepository<@NonNull Article,,@NonNull Long> org.springframework.data.repository.ListCrudRepository<Article,,Long> org.springframework.data.repository.ListPagingAndSortingRepository<Article,,Long> org.springframework.data.repository.PagingAndSortingRepository<Article,,Long> org.springframework.data.repository.query.QueryByExampleExecutor<Article>,org.springframework.data.repository.Repository<Article,Long>
@Repository
public interface ArticleRepository
extends org.springframework.data.jpa.repository.JpaRepository<@NonNull Article,@NonNull Long>
The
ArticleRepository provides database access for Article entities.-
Method Summary
Modifier and TypeMethodDescriptionlongcountByEventId(Long eventId) Returns the number ofarticlesrelated to the event with the given ID.org.springframework.data.domain.Page<Article> findAllByOrderByPublishedDateDesc(@NonNull org.springframework.data.domain.Pageable pageable) Returns aPageof allarticlesordered by their published date descending.org.springframework.data.domain.Page<Article> findByAthleteId(Long athleteId, @NonNull org.springframework.data.domain.Pageable pageable) Returns aPageofarticlesauthored by the athlete with the given ID, ordered by published date descending.org.springframework.data.domain.Page<Article> findByEventId(Long eventId, @NonNull org.springframework.data.domain.Pageable pageable) Returns aPageofarticlesassociated with a given event ID.findBySlug(String slug) Finds anArticleby its unique URL slug.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
-
countByEventId
@Query("SELECT COUNT(DISTINCT a) FROM Article a JOIN a.relatedEvents e WHERE e.id = :eventId") long countByEventId(@Param("eventId") Long eventId) Returns the number ofarticlesrelated to the event with the given ID.- Parameters:
eventId- the ID of theEvent- Returns:
- the number of articles related to the given event (0 if none)
-
findAllByOrderByPublishedDateDesc
org.springframework.data.domain.Page<Article> findAllByOrderByPublishedDateDesc(@NonNull org.springframework.data.domain.Pageable pageable) Returns aPageof allarticlesordered by their published date descending.- Parameters:
pageable- the pagination information- Returns:
- a
Pageofarticlesordered by published date descending
-
findByAthleteId
@Query("SELECT DISTINCT a FROM Article a JOIN a.author au JOIN au.athlete at WHERE at.id = :athleteId ORDER BY a.publishedDate DESC") org.springframework.data.domain.Page<Article> findByAthleteId(@Param("athleteId") Long athleteId, @NonNull org.springframework.data.domain.Pageable pageable) Returns aPageofarticlesauthored by the athlete with the given ID, ordered by published date descending. -
findByEventId
@Query("SELECT DISTINCT a FROM Article a JOIN a.relatedEvents e WHERE e.id = :eventId") org.springframework.data.domain.Page<Article> findByEventId(@Param("eventId") Long eventId, @NonNull org.springframework.data.domain.Pageable pageable) Returns aPageofarticlesassociated with a given event ID. -
findByPublishedDateIsNotNullOrderByPublishedDateDesc
-
findBySlug
Finds anArticleby its unique URL slug.
-