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 TypeMethodDescriptionvoiddeleteById(ID id) Deletes the entity identified by the given ID, if it exists.booleanexistsAllByIds(Collection<ID> ids) Verifies whether all entities corresponding to the provided identifiers exist.booleanexistsById(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, waitMethods 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
Classobject representingT
-
findById
Finds an entity by its identifier.- Specified by:
findByIdin interfaceIGenericDAO<T,ID> - Parameters:
id- the identifier of the entity to find; may benull- Returns:
- an
Optionalcontaining the entity if found, otherwise empty
-
findAllByIds
Retrieves all entities matching the provided collection of identifiers.- Specified by:
findAllByIdsin interfaceIGenericDAO<T,ID> - Parameters:
ids- the collection of identifiers; may benullor empty- Returns:
- a
Listof entities found; empty if none match
-
deleteById
Deletes the entity identified by the given ID, if it exists.- Specified by:
deleteByIdin interfaceIGenericDAO<T,ID> - Parameters:
id- the identifier of the entity to delete; may benull
-
save
Saves or updates the given entity.- Specified by:
savein 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:
saveAllin interfaceIGenericDAO<T,ID> - Parameters:
t- the collection of entities to save; must not benull- Returns:
- a
Listof saved entity instances
-
findAll
Retrieves all entities of typeT.- Specified by:
findAllin interfaceIGenericDAO<T,ID> - Returns:
- a
Listof 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:
findAllPagein interfaceIGenericDAO<T,ID> - Parameters:
pageable- pagination and sorting parameters; must not benull- Returns:
- a
Pageof entities
-
existsById
Checks whether an entity exists with the given identifier.- Specified by:
existsByIdin interfaceIGenericDAO<T,ID> - Parameters:
id- the identifier to check; may benull- Returns:
trueif an entity exists with the specified ID;falseotherwise
-
existsAllByIds
Verifies whether all entities corresponding to the provided identifiers exist.- Specified by:
existsAllByIdsin interfaceIGenericDAO<T,ID> - Parameters:
ids- the collection of IDs to check; may benull- Returns:
trueif the count of matching entities equals the number of IDs provided;falseotherwise
-