Module org.jooq
Package org.jooq.impl

Class DAOImpl<R extends UpdatableRecord<R>,​P,​T>

  • All Implemented Interfaces:
    DAO<R,​P,​T>

    public abstract class DAOImpl<R extends UpdatableRecord<R>,​P,​T>
    extends Object
    implements DAO<R,​P,​T>
    A common base implementation for generated DAO.

    Unlike many other elements in the jOOQ API, DAO may be used in the context of Spring, CDI, or EJB lifecycle management. This means that no methods in the DAO type hierarchy must be made final. See also https://github.com/jOOQ/ jOOQ/issues/4696 for more details.

    Author:
    Lukas Eder
    • Method Detail

      • setConfiguration

        public void setConfiguration​(Configuration configuration)
        Inject a configuration.

        This method is maintained to be able to configure a DAO using Spring. It is not exposed in the public API.

      • configuration

        public Configuration configuration()
        Description copied from interface: DAO
        Expose the configuration in whose context this DAO is operating.
        Specified by:
        configuration in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Returns:
        the DAO's underlying Configuration
      • settings

        public Settings settings()
        Description copied from interface: DAO
        The settings wrapped by this context.

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

        Specified by:
        settings in interface DAO<R extends UpdatableRecord<R>,​P,​T>
      • dialect

        public SQLDialect dialect()
        Description copied from interface: DAO
        The SQLDialect wrapped by this context.

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

        Specified by:
        dialect in interface DAO<R extends UpdatableRecord<R>,​P,​T>
      • mapper

        public 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.

        Subclasses may override this method to provide custom implementations.

        Specified by:
        mapper in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Returns:
        the DAO's underlying RecordMapper
      • insert

        public void insert​(P object)
        Description copied from interface: DAO
        Performs an INSERT statement for a given POJO.
        Specified by:
        insert in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        object - The POJO to be inserted
      • insert

        public void insert​(P... objects)
        Description copied from interface: DAO
        Performs a batch INSERT statement for a given set of POJOs.
        Specified by:
        insert in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be inserted
        See Also:
        DAO.insert(Collection)
      • insert

        public void insert​(Collection<P> objects)
        Description copied from interface: DAO
        Performs a batch INSERT statement for a given set of POJOs.
        Specified by:
        insert in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be inserted
        See Also:
        DAO.insert(Object...)
      • update

        public void update​(P object)
        Description copied from interface: DAO
        Performs an UPDATE statement for a given POJO.
        Specified by:
        update in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        object - The POJO to be updated
      • update

        public void update​(P... objects)
        Description copied from interface: DAO
        Performs a batch UPDATE statement for a given set of POJOs.
        Specified by:
        update in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be updated
        See Also:
        DAO.update(Collection)
      • merge

        public void merge​(P object)
        Description copied from interface: DAO
        Performs an MERGE statement for a given POJO.
        Specified by:
        merge in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        object - The POJO to be merged
      • merge

        public void merge​(P... objects)
        Description copied from interface: DAO
        Performs a batch MERGE statement for a given set of POJOs.
        Specified by:
        merge in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be merged
        See Also:
        DAO.update(Collection)
      • delete

        public void delete​(P object)
        Description copied from interface: DAO
        Performs a DELETE statement for a POJO
        Specified by:
        delete in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        object - The POJO to be deleted
        See Also:
        DAO.delete(Collection)
      • delete

        public void delete​(P... objects)
        Description copied from interface: DAO
        Performs a DELETE statement for a given set of POJOs.
        Specified by:
        delete in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        objects - The POJOs to be deleted
        See Also:
        DAO.delete(Collection)
      • deleteById

        public void deleteById​(T... ids)
        Description copied from interface: DAO
        Performs a DELETE statement for a given set of IDs.
        Specified by:
        deleteById in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        ids - The IDs to be deleted
        See Also:
        DAO.delete(Collection)
      • exists

        public boolean exists​(P object)
        Description copied from interface: DAO
        Checks if a given POJO exists.
        Specified by:
        exists in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        object - The POJO whose existence is checked
        Returns:
        Whether the POJO already exists
      • existsById

        public boolean existsById​(T id)
        Description copied from interface: DAO
        Checks if a given ID exists.
        Specified by:
        existsById in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        id - The ID whose existence is checked
        Returns:
        Whether the ID already exists
      • count

        public long count()
        Description copied from interface: DAO
        Count all records of the underlying table.
        Specified by:
        count in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Returns:
        The number of records of the underlying table
      • findAll

        public List<P> findAll()
        Description copied from interface: DAO
        Find all records of the underlying table.
        Specified by:
        findAll in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Returns:
        All records of the underlying table
      • findById

        public P findById​(T id)
        Description copied from interface: DAO
        Find a record of the underlying table by ID.
        Specified by:
        findById in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        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.
      • fetchRange

        public <Z> List<P> fetchRange​(Field<Z> field,
                                      Z lowerInclusive,
                                      Z upperInclusive)
        Description copied from interface: DAO
        Find records by a given field and a range of values.
        Specified by:
        fetchRange in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        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
      • fetch

        public <Z> List<P> fetch​(Field<Z> field,
                                 Z... values)
        Description copied from interface: DAO
        Find records by a given field and a set of values.
        Specified by:
        fetch in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        field - The field to compare values against
        values - The accepted values
        Returns:
        A list of records fulfilling field IN (values)
      • fetchOne

        public <Z> P fetchOne​(Field<Z> field,
                              Z value)
        Description copied from interface: DAO
        Find a unique record by a given field and a value.
        Specified by:
        fetchOne in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        field - The field to compare value against
        value - The accepted value
        Returns:
        A record fulfilling field = value, or null
      • fetchOptional

        public <Z> Optional<P> fetchOptional​(Field<Z> field,
                                             Z value)
        Description copied from interface: DAO
        Find a unique record by a given field and a value.
        Specified by:
        fetchOptional in interface DAO<R extends UpdatableRecord<R>,​P,​T>
        Parameters:
        field - The field to compare value against
        value - The accepted value
        Returns:
        A record fulfilling field = value
      • compositeKeyRecord

        protected T compositeKeyRecord​(Object... values)