Class AbstractTranslatableService
-
- All Implemented Interfaces:
public abstract class AbstractTranslatableService<T extends ITranslatable<ID, TR>, ID extends Object, TR extends ITranslation<ID, ?>>Abstract service class for managing translatable entities.
-
-
Field Summary
Fields Modifier and Type Field Description private final JpaTranslatableRepository<T, ID, TR>repository
-
Constructor Summary
Constructors Constructor Description AbstractTranslatableService(JpaTranslatableRepository<T, ID, TR> repository)
-
Method Summary
Modifier and Type Method Description JpaTranslatableRepository<T, ID, TR>getRepository()The repository for accessing translatable entities. BooleanexistsByIdAndLocale(ID id, String locale)Checks if a translatable entity exists by its ID and locale. TfindByIdAndLocale(ID id, String locale)Finds a translatable entity by its ID and locale. List<T>findAllByLocale(String locale)Finds all translatable entities that have a translation with the given locale. Page<T>findAllByLocale(String locale, Pageable pageable)Finds all translatable entities that have a translation with the given locale, with pagination. List<TR>findTranslationsById(ID id)Finds all translations for a specific translatable entity by its ID. Page<TR>findTranslationsById(ID id, Pageable pageable)Finds all translations for a specific translatable entity by its ID, with pagination. Tsave(T entity)Saves a translatable entity. IntegerdeleteByLocale(String locale)Deletes all translatable entities that have a translation with the given locale. IntegerdeleteByIdAndLocale(ID id, String locale)Deletes a translatable entity if it has a translation with the given ID and locale. -
-
Constructor Detail
-
AbstractTranslatableService
AbstractTranslatableService(JpaTranslatableRepository<T, ID, TR> repository)
-
-
Method Detail
-
getRepository
JpaTranslatableRepository<T, ID, TR> getRepository()
The repository for accessing translatable entities.
-
existsByIdAndLocale
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 to check for.- Returns:
True if the entity exists with the given locale, false otherwise.
-
findByIdAndLocale
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 translation.- Returns:
T? The translatable entity, or null if not found.
-
findAllByLocale
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
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
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
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.
-
save
T save(T entity)
Saves a translatable entity.
- Parameters:
entity- The entity to save.- Returns:
The saved entity.
-
deleteByLocale
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
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 (usually 0 or 1).
-
-
-
-