Class BaseRepository<T,ID>

java.lang.Object
com.serinity.accesscontrol.repository.base.BaseRepository<T,ID>
Type Parameters:
T - entity type managed by the repository
ID - primary key type of the entity
Direct Known Subclasses:
AuditLogRepository, AuthSessionRepository, ProfileRepository, UserFaceRepository, UserRepository

public abstract class BaseRepository<T,ID> extends Object
A base repository that support the common crud actions
Since:
2026-02-04 BaseRepository.java
Version:
1.0
Author:
@ZouariOmar (zouariomar20@gmail.com)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.zouarioss.skinnedratorm.core.EntityManager
    Entity manager used for persistence operations.
    protected final Class<T>
    Runtime class of the managed entity.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BaseRepository(org.zouarioss.skinnedratorm.core.EntityManager em, Class<T> entityClass)
    Constructs a repository for the given entity class.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(T entity)
    Deletes an entity from the database.
    void
    Deletes an entity identified by its primary key, if it exists.
    Returns all entities of this type from the database.
    Finds an entity by its primary key.
    void
    save(T entity)
    Persists a new entity to the database.
    void
    update(T entity)
    Updates an existing entity in the database.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • em

      protected final org.zouarioss.skinnedratorm.core.EntityManager em
      Entity manager used for persistence operations.
    • entityClass

      protected final Class<T> entityClass
      Runtime class of the managed entity.
  • Constructor Details

    • BaseRepository

      public BaseRepository(org.zouarioss.skinnedratorm.core.EntityManager em, Class<T> entityClass)
      Constructs a repository for the given entity class.
      Parameters:
      em - the ORM EntityManager to use for DB operations
      entityClass - the entity class managed by this repository
  • Method Details

    • save

      public void save(T entity)
      Persists a new entity to the database.
      Parameters:
      entity - the entity to save
    • update

      public void update(T entity)
      Updates an existing entity in the database.
      Parameters:
      entity - the entity with updated field values
    • findById

      public Optional<T> findById(ID id)
      Finds an entity by its primary key.
      Parameters:
      id - the primary key value
      Returns:
      an Optional containing the entity, or empty if not found
    • delete

      public void delete(T entity)
      Deletes an entity from the database.
      Parameters:
      entity - the entity instance to remove
    • deleteById

      public void deleteById(ID id)
      Deletes an entity identified by its primary key, if it exists.
      Parameters:
      id - the primary key of the entity to delete
    • findAll

      public List<T> findAll()
      Returns all entities of this type from the database.
      Returns:
      a list of all persisted entities; never null