Module org.jooq
Package org.jooq

Interface DAO<R extends TableRecord<R>,​P,​T>

  • Type Parameters:
    R - The generic record type.
    P - The generic POJO type.
    T - The generic primary key type. This is a regular <T> type for single-column keys, or a Record subtype for composite keys.
    All Known Implementing Classes:
    DAOImpl

    public interface DAO<R extends TableRecord<R>,​P,​T>
    A generic DAO interface for a pojo and a primary key type.

    This type is implemented by generated DAO classes to provide a common API for common actions on POJOs

    Author:
    Lukas Eder
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      Configuration configuration()
      Expose the configuration in whose context this DAO is operating.
      long count()
      Count all records of the underlying table.
      void delete​(Collection<P> objects)
      Performs a DELETE statement for a given set of POJOs
      void delete​(P object)
      Performs a DELETE statement for a POJO
      void delete​(P... objects)
      Performs a DELETE statement for a given set of POJOs
      void deleteById​(Collection<T> ids)
      Performs a DELETE statement for a given set of IDs
      void deleteById​(T... ids)
      Performs a DELETE statement for a given set of IDs
      SQLDialect dialect()
      The SQLDialect wrapped by this context.
      boolean exists​(P object)
      Checks if a given POJO exists
      boolean existsById​(T id)
      Checks if a given ID exists
      SQLDialect family()
      The SQLDialect.family() wrapped by this context.
      <Z> List<P> fetch​(Field<Z> field, Z... values)
      Find records by a given field and a set of values.
      <Z> P fetchOne​(Field<Z> field, Z value)
      Find a unique record by a given field and a value.
      <Z> Optional<P> fetchOptional​(Field<Z> field, Z value)
      Find a unique record by a given field and a value.
      <Z> List<P> fetchRange​(Field<Z> field, Z lowerInclusive, Z upperInclusive)
      Find records by a given field and a range of values.
      List<P> findAll()
      Find all records of the underlying table.
      P findById​(T id)
      Find a record of the underlying table by ID.
      T getId​(P object)
      Extract the ID value from a POJO.
      Table<R> getTable()
      Get the underlying table.
      Class<P> getType()
      Get the underlying POJO type.
      void insert​(Collection<P> objects)
      Performs a batch INSERT statement for a given set of POJOs
      void insert​(P object)
      Performs an INSERT statement for a given POJO
      void insert​(P... objects)
      Performs a batch INSERT statement for a given set of POJOs
      RecordMapper<R,​P> mapper()
      Expose the RecordMapper that is used internally by this DAO to map from records of type R to POJOs of type P.
      Settings settings()
      The settings wrapped by this context.
      void update​(Collection<P> objects)
      Performs a batch UPDATE statement for a given set of POJOs
      void update​(P object)
      Performs an UPDATE statement for a given POJO
      void update​(P... objects)
      Performs a batch UPDATE statement for a given set of POJOs
    • Method Detail

      • configuration

        Configuration configuration()
        Expose the configuration in whose context this DAO is operating.
        Returns:
        the DAO's underlying Configuration
      • settings

        Settings settings()
        The settings wrapped by this context.

        This method is a convenient way of accessing configuration().settings().

      • dialect

        SQLDialect dialect()
        The SQLDialect wrapped by this context.

        This method is a convenient way of accessing configuration().dialect().

      • family

        SQLDialect family()
        The SQLDialect.family() wrapped by this context.

        This method is a convenient way of accessing configuration().family().

      • mapper

        RecordMapper<R,​P> mapper()
        Expose the RecordMapper that is used internally by this DAO to map from records of type R to POJOs of type P.
        Returns:
        the DAO's underlying RecordMapper
      • insert

        void insert​(P object)
             throws DataAccessException
        Performs an INSERT statement for a given POJO
        Parameters:
        object - The POJO to be inserted
        Throws:
        DataAccessException - if something went wrong executing the query
      • update

        void update​(P object)
             throws DataAccessException
        Performs an UPDATE statement for a given POJO
        Parameters:
        object - The POJO to be updated
        Throws:
        DataAccessException - if something went wrong executing the query
      • exists

        boolean exists​(P object)
                throws DataAccessException
        Checks if a given POJO exists
        Parameters:
        object - The POJO whose existence is checked
        Returns:
        Whether the POJO already exists
        Throws:
        DataAccessException - if something went wrong executing the query
      • existsById

        boolean existsById​(T id)
                    throws DataAccessException
        Checks if a given ID exists
        Parameters:
        id - The ID whose existence is checked
        Returns:
        Whether the ID already exists
        Throws:
        DataAccessException - if something went wrong executing the query
      • count

        long count()
            throws DataAccessException
        Count all records of the underlying table.
        Returns:
        The number of records of the underlying table
        Throws:
        DataAccessException - if something went wrong executing the query
      • findAll

        List<P> findAll()
                 throws DataAccessException
        Find all records of the underlying table.
        Returns:
        All records of the underlying table
        Throws:
        DataAccessException - if something went wrong executing the query
      • findById

        P findById​(T id)
            throws DataAccessException
        Find a record of the underlying table by ID.
        Parameters:
        id - The ID of a record in the underlying table
        Returns:
        A record of the underlying table given its ID, or null if no record was found.
        Throws:
        DataAccessException - if something went wrong executing the query
      • fetch

        <Z> List<P> fetch​(Field<Z> field,
                          Z... values)
                   throws DataAccessException
        Find records by a given field and a set of values.
        Parameters:
        field - The field to compare values against
        values - The accepted values
        Returns:
        A list of records fulfilling field IN (values)
        Throws:
        DataAccessException - if something went wrong executing the query
      • fetchRange

        <Z> List<P> fetchRange​(Field<Z> field,
                               Z lowerInclusive,
                               Z upperInclusive)
                        throws DataAccessException
        Find records by a given field and a range of values.
        Parameters:
        field - The field to compare values against
        lowerInclusive - The range's lower bound (inclusive), or unbounded if null.
        upperInclusive - The range's upper bound (inclusive), or unbounded if null.
        Returns:
        A list of records fulfilling field BETWEEN lowerInclusive AND upperInclusive
        Throws:
        DataAccessException - if something went wrong executing the query
      • fetchOne

        <Z> P fetchOne​(Field<Z> field,
                       Z value)
                throws DataAccessException
        Find a unique record by a given field and a value.
        Parameters:
        field - The field to compare value against
        value - The accepted value
        Returns:
        A record fulfilling field = value, or null
        Throws:
        DataAccessException - This exception is thrown
        • if something went wrong executing the query
        • if the query returned more than one value
      • fetchOptional

        <Z> Optional<P> fetchOptional​(Field<Z> field,
                                      Z value)
                               throws DataAccessException
        Find a unique record by a given field and a value.
        Parameters:
        field - The field to compare value against
        value - The accepted value
        Returns:
        A record fulfilling field = value
        Throws:
        DataAccessException - This exception is thrown
        • if something went wrong executing the query
        • if the query returned more than one value
      • getTable

        Table<R> getTable()
        Get the underlying table.
      • getType

        Class<P> getType()
        Get the underlying POJO type.
      • getId

        T getId​(P object)
        Extract the ID value from a POJO.