Package com.alpaca.persistence.impl
Class GenericDAOImpl<T,ID>
java.lang.Object
com.alpaca.persistence.impl.GenericDAOImpl<T,ID>
- Type Parameters:
T
- entity type managed by this DAOID
- type of the entity's identifier
- All Implemented Interfaces:
IGenericDAO<T,
ID>
- Direct Known Subclasses:
AdvertiserDAOImpl
,PermissionDAOImpl
,ProfileDAOImpl
,RoleDAOImpl
,UserDAOImpl
Abstract base implementation of
IGenericDAO
, providing generic CRUD and pagination
operations for any entity type T
with identifier type ID
.
Concrete DAO implementations must supply the specific GenericRepo
and entity class by
implementing the abstract getRepo()
and getEntity()
methods.
This class leverages Spring Data repositories to delegate standard persistence operations in a type-safe, reusable fashion.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteById
(ID id) Deletes the entity identified by the given ID, if it exists.boolean
existsAllByIds
(Collection<ID> ids) Verifies whether all entities corresponding to the provided identifiers exist.boolean
existsById
(ID id) Checks whether an entity exists with the given identifier.findAll()
Retrieves all entities of typeT
.findAllByIds
(Collection<ID> ids) Retrieves all entities matching the provided collection of identifiers.org.springframework.data.domain.Page
<T> findAllPage
(org.springframework.data.domain.Pageable pageable) Retrieves entities in a paginated fashion using the providedPageable
.Finds an entity by its identifier.Provides the entity class handled by this DAO implementation.protected abstract GenericRepo
<T, ID> getRepo()
Supplies the Spring Data repository for the specific entity type.Saves or updates the given entity.saveAll
(Collection<T> t) Saves or updates a collection of entities.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.alpaca.persistence.IGenericDAO
existsByUniqueProperties, updateById
-
Constructor Details
-
GenericDAOImpl
public GenericDAOImpl()
-
-
Method Details
-
getRepo
Supplies the Spring Data repository for the specific entity type.- Returns:
- the repository instance for
T
-
getEntity
Provides the entity class handled by this DAO implementation.- Returns:
- the
Class
object representingT
-
findById
Finds an entity by its identifier.- Specified by:
findById
in interfaceIGenericDAO<T,
ID> - Parameters:
id
- the identifier of the entity to find; may benull
- Returns:
- an
Optional
containing the entity if found, otherwise empty
-
findAllByIds
Retrieves all entities matching the provided collection of identifiers.- Specified by:
findAllByIds
in interfaceIGenericDAO<T,
ID> - Parameters:
ids
- the collection of identifiers; may benull
or empty- Returns:
- a
List
of entities found; empty if none match
-
deleteById
Deletes the entity identified by the given ID, if it exists.- Specified by:
deleteById
in interfaceIGenericDAO<T,
ID> - Parameters:
id
- the identifier of the entity to delete; may benull
-
save
Saves or updates the given entity.- Specified by:
save
in interfaceIGenericDAO<T,
ID> - Parameters:
t
- the entity to save; must not benull
- Returns:
- the saved entity instance
-
saveAll
Saves or updates a collection of entities.- Specified by:
saveAll
in interfaceIGenericDAO<T,
ID> - Parameters:
t
- the collection of entities to save; must not benull
- Returns:
- a
List
of saved entity instances
-
findAll
Retrieves all entities of typeT
.- Specified by:
findAll
in interfaceIGenericDAO<T,
ID> - Returns:
- a
List
of all entities; empty if none exist
-
findAllPage
public org.springframework.data.domain.Page<T> findAllPage(org.springframework.data.domain.Pageable pageable) Retrieves entities in a paginated fashion using the providedPageable
.- Specified by:
findAllPage
in interfaceIGenericDAO<T,
ID> - Parameters:
pageable
- pagination and sorting parameters; must not benull
- Returns:
- a
Page
of entities
-
existsById
Checks whether an entity exists with the given identifier.- Specified by:
existsById
in interfaceIGenericDAO<T,
ID> - Parameters:
id
- the identifier to check; may benull
- Returns:
true
if an entity exists with the specified ID;false
otherwise
-
existsAllByIds
Verifies whether all entities corresponding to the provided identifiers exist.- Specified by:
existsAllByIds
in interfaceIGenericDAO<T,
ID> - Parameters:
ids
- the collection of IDs to check; may benull
- Returns:
true
if the count of matching entities equals the number of IDs provided;false
otherwise
-