Package com.alpaca.service
Interface IGenericService<T,ID>
- Type Parameters:
T
- The type of entity.ID
- The type of the entity's identifier.
- All Known Subinterfaces:
IAdvertiserService
,IPermissionService
,IProfileService
,IRoleService
,IUserService
- All Known Implementing Classes:
AdvertiserServiceImpl
,GenericServiceImpl
,PermissionServiceImpl
,ProfileServiceImpl
,RoleServiceImpl
,UserServiceImpl
public interface IGenericService<T,ID>
Generic service interface providing common CRUD operations.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteById
(ID id) Deletes an entity by its identifier.boolean
existsAllByIds
(Collection<ID> ids) Checks if multiple entities exist by their identifiers.boolean
existsById
(ID id) Checks if an entity exists by its identifier.boolean
Checks if an entity exists based on its unique properties.findAll()
Retrieves all entities.findAllByIds
(Collection<ID> ids) Finds all entities by their identifiers.findAllByIdsToSet
(Collection<ID> ids) Finds all entities by their identifiers and returns them as a set.org.springframework.data.domain.Page
<T> findAllPage
(org.springframework.data.domain.Pageable pageable) Retrieves all entities with pagination support.Finds an entity by its identifier.Saves a new entity.saveAll
(Collection<T> t) Saves multiple entities.updateById
(T t, ID id) Updates an existing entity by its identifier.
-
Method Details
-
findById
Finds an entity by its identifier.- Parameters:
id
- The identifier of the entity - must not be null.- Returns:
- The entity if found.
- Throws:
BadRequestException
- if the ID is null.NotFoundException
- if the entity is not found.
-
findAllByIds
Finds all entities by their identifiers.- Parameters:
ids
- A collection of entity identifiers - must not be null or empty.- Returns:
- A list of found entities.
- Throws:
BadRequestException
- if the IDs are null or empty.NotFoundException
- if any entity is not found.
-
findAllByIdsToSet
Finds all entities by their identifiers and returns them as a set.- Parameters:
ids
- A collection of entity identifiers - must not be null or empty.- Returns:
- A set of found entities.
- Throws:
BadRequestException
- if the IDs are null or empty.NotFoundException
- if any entity is not found.
-
save
Saves a new entity.- Parameters:
t
- The entity to save - must not be null.- Returns:
- The saved entity.
- Throws:
BadRequestException
- if the entity is null or already exists.
-
saveAll
Saves multiple entities.- Parameters:
t
- A collection of entities to save - must not be null or empty.- Returns:
- A list of saved entities.
- Throws:
BadRequestException
- if the list is null or empty.
-
updateById
Updates an existing entity by its identifier.- Parameters:
t
- The updated entity data - must not be null.id
- The identifier of the entity to update - must not be null.- Returns:
- The updated entity.
- Throws:
BadRequestException
- if the ID or entity is null.NotFoundException
- if the entity does not exist.
-
deleteById
Deletes an entity by its identifier.- Parameters:
id
- The identifier of the entity to delete - must not be null.- Throws:
BadRequestException
- if the ID is null.NotFoundException
- if the entity does not exist.
-
findAll
Retrieves all entities.- Returns:
- A list of all entities.
-
findAllPage
org.springframework.data.domain.Page<T> findAllPage(org.springframework.data.domain.Pageable pageable) Retrieves all entities with pagination support.- Parameters:
pageable
- The pagination configuration - must not be null.- Returns:
- A
Page
containing the paginated entities. - Throws:
BadRequestException
- if the pageable parameter is null.
-
existsById
Checks if an entity exists by its identifier.- Parameters:
id
- The identifier of the entity - must not be null.- Returns:
true
if the entity exists, otherwisefalse
.
-
existsAllByIds
Checks if multiple entities exist by their identifiers.- Parameters:
ids
- A collection of entity identifiers - must not be null or empty.- Returns:
true
if all entities exist, otherwisefalse
.
-
existsByUniqueProperties
Checks if an entity exists based on its unique properties.- Parameters:
t
- The entity containing unique properties to check - must not be null.- Returns:
true
if an entity with the same unique properties exists, otherwisefalse
.
-