Interface JpaTranslatableRepository
-
- All Implemented Interfaces:
-
org.springframework.data.jpa.repository.JpaRepository,org.springframework.data.repository.CrudRepository,org.springframework.data.repository.ListCrudRepository,org.springframework.data.repository.ListPagingAndSortingRepository,org.springframework.data.repository.PagingAndSortingRepository,org.springframework.data.repository.Repository,org.springframework.data.repository.query.QueryByExampleExecutor
@NoRepositoryBean() public interface JpaTranslatableRepository<T extends ITranslatable<ID, TR>, ID extends Object, TR extends ITranslation<ID, ?>> implements JpaRepository<T, ID>
Repository interface for translatable entities. This interface extends the JpaRepository interface and provides methods for working with translatable entities.
-
-
Method Summary
Modifier and Type Method Description abstract BooleanexistsByIdAndLocale(ID id, String locale)Checks if a translatable entity exists by its ID and locale. abstract TfindByIdAndLocale(ID id, String locale)Finds a translatable entity by its ID and locale. abstract List<T>findAllByLocale(String locale)Finds all translatable entities that have a translation with the given locale. abstract Page<T>findAllByLocale(String locale, Pageable pageable)Finds all translatable entities that have a translation with the given locale, with pagination. abstract List<TR>findTranslationsById(ID id)Finds all translations for a specific translatable entity by its ID. abstract Page<TR>findTranslationsById(ID id, Pageable pageable)Finds all translations for a specific translatable entity by its ID, with pagination. abstract IntegerdeleteByLocale(String locale)Deletes all translatable entities that have a translation with the given locale. abstract IntegerdeleteByIdAndLocale(ID id, String locale)Deletes a translatable entity if it has a translation with the given ID and locale. -
Methods inherited from class org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save -
Methods inherited from class org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAll -
Methods inherited from class org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush -
Methods inherited from class org.springframework.data.repository.ListPagingAndSortingRepository
findAll -
Methods inherited from class org.springframework.data.repository.PagingAndSortingRepository
findAll -
Methods inherited from class org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
existsByIdAndLocale
@Query(value = " SELECT COUNT(e) > 0 FROM #{#entityName} e JOIN e.translations t WHERE e.id = :id AND t.locale = :locale ") abstract Boolean existsByIdAndLocale(ID id, String locale)Checks if a translatable entity exists by its ID and locale.
- Parameters:
id- The ID of the entity.locale- The locale of the entity.- Returns:
True if the entity exists, false otherwise.
-
findByIdAndLocale
@Query(value = "SELECT e FROM #{#entityName} e JOIN e.translations t WHERE e.id = :id AND t.locale = :locale") abstract T findByIdAndLocale(ID id, String locale)Finds a translatable entity by its ID and locale.
- Parameters:
id- The ID of the entity.locale- The locale of the entity.- Returns:
The translatable entity, or null if not found.
-
findAllByLocale
@Query(value = "SELECT DISTINCT e FROM #{#entityName} e JOIN e.translations t WHERE t.locale = :locale") abstract List<T> findAllByLocale(String locale)Finds all translatable entities that have a translation with the given locale.
- Parameters:
locale- The locale to filter by.- Returns:
List of translatable entities.
-
findAllByLocale
@Query(value = "SELECT DISTINCT e FROM #{#entityName} e JOIN e.translations t WHERE t.locale = :locale") abstract Page<T> findAllByLocale(String locale, Pageable pageable)Finds all translatable entities that have a translation with the given locale, with pagination.
- Parameters:
locale- The locale to filter by.pageable- Pagination information.- Returns:
Page of translatable entities.
-
findTranslationsById
@Query(value = "SELECT t FROM #{#entityName} e JOIN e.translations t WHERE e.id = :id") abstract List<TR> findTranslationsById(ID id)Finds all translations for a specific translatable entity by its ID.
- Parameters:
id- The ID of the entity.- Returns:
List of translations for the entity.
-
findTranslationsById
@Query(value = "SELECT t FROM #{#entityName} e JOIN e.translations t WHERE e.id = :id") abstract Page<TR> findTranslationsById(ID id, Pageable pageable)Finds all translations for a specific translatable entity by its ID, with pagination.
- Parameters:
id- The ID of the entity.pageable- Pagination information.- Returns:
Page of translations for the entity.
-
deleteByLocale
@Modifying()@Query(value = " DELETE FROM #{#entityName} e WHERE EXISTS ( SELECT 1 FROM e.translations t WHERE t.locale = :locale ) ") abstract Integer deleteByLocale(String locale)Deletes all translatable entities that have a translation with the given locale.
- Parameters:
locale- The locale of the translations to delete.- Returns:
The number of deleted entities.
-
deleteByIdAndLocale
@Modifying()@Query(value = " DELETE FROM #{#entityName} e WHERE e.id = :id AND EXISTS ( SELECT 1 FROM e.translations t WHERE t.locale = :locale ) ") abstract Integer deleteByIdAndLocale(ID id, String locale)Deletes a translatable entity if it has a translation with the given ID and locale.
- Parameters:
id- The ID of the entity.locale- The locale of the translation.- Returns:
The number of deleted entities.
-
-
-
-