Interface BaseDao

  • All Known Implementing Classes:
    DefaultBaseDao

    public interface BaseDao
    The Dao class is the interface for all database access.
    • Method Detail

      • getEntityManager

        javax.persistence.EntityManager getEntityManager()
      • create

        <T extends BaseEntity> T create​(T obj)
        Inserts a new instance in the database.
        Parameters:
        obj - The object to create.
        Returns:
        The instance with ID.
      • read

        <T extends BaseEntity> T read​(Class<T> entityClass,
                                      UUID id)
        Retrieves an object by ID.
        Parameters:
        id - The ID.
        Returns:
        The object if found; null otherwise.
      • readByHandle

        <T extends NamedEntity> T readByHandle​(Class<T> entityClass,
                                               String handle)
        Finds a user by handle. Returns the user on success. Returns null on failure.
        Parameters:
        handle - The user's handle.
        Returns:
        The user on success; null on failure.
      • readPage

        <T extends BaseEntityList<T> readPage​(Class<T> entityClass,
                                                int page,
                                                int pageSize)
        Returns a page of objects.
        Parameters:
        entityClass - The entity class.
        page - The page index (zero indexed).
        pageSize - The page size.
        Returns:
        A page of objects.
      • update

        <T extends BaseEntity> T update​(T obj)
        Updates an object.
        Parameters:
        obj - The object to update.
      • delete

        <T extends BaseEntity> void delete​(T obj)
        Soft deletes an object. The data is still in the database, but with deleted flag.
        Parameters:
        obj - The object to delete.
      • purge

        <T extends BaseEntity> void purge​(T obj)
        Hard deletes an object. This purges the data from the database.
        Parameters:
        obj - The object to delete.
      • countAll

        <T extends BaseEntity> long countAll​(Class<T> entityClass)
        Counts all rows of a type.
        Parameters:
        entityClass - The entity class.
        Returns:
        The count of rows.
      • firstOrNull

        static <T extends BaseEntity> T firstOrNull​(List<T> list)
        Returns null if the list is empty. Returns the first element otherwise. JPA getSingleResult() throws an exception if no results, which is an annoying design. So instead you can call getResultList() and wrap it with firstOrNull(), which is the more expected result.
        Parameters:
        list -
        Returns: