-
- 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 aRecord
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 @NotNull Configuration
configuration()
Expose the configuration in whose context thisDAO
is operating.long
count()
Count all records of the underlying table.void
delete(Collection<P> objects)
Performs aDELETE
statement for a given set of POJOs.void
delete(P object)
Performs aDELETE
statement for a POJOvoid
delete(P... objects)
Performs aDELETE
statement for a given set of POJOs.void
deleteById(Collection<T> ids)
Performs aDELETE
statement for a given set of IDs.void
deleteById(T... ids)
Performs aDELETE
statement for a given set of IDs.@NotNull SQLDialect
dialect()
TheSQLDialect
wrapped by this context.boolean
exists(P object)
Checks if a given POJO exists.boolean
existsById(T id)
Checks if a given ID exists.@NotNull SQLDialect
family()
TheSQLDialect.family()
wrapped by this context.<Z> @NotNull 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> @NotNull Optional<P>
fetchOptional(Field<Z> field, Z value)
Find a unique record by a given field and a value.<Z> @NotNull List<P>
fetchRange(Field<Z> field, Z lowerInclusive, Z upperInclusive)
Find records by a given field and a range of values.@NotNull 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.@NotNull Table<R>
getTable()
Get the underlying table.@NotNull Class<P>
getType()
Get the underlying POJO type.void
insert(Collection<P> objects)
Performs a batchINSERT
statement for a given set of POJOs.void
insert(P object)
Performs anINSERT
statement for a given POJO.void
insert(P... objects)
Performs a batchINSERT
statement for a given set of POJOs.@NotNull RecordMapper<R,P>
mapper()
Expose theRecordMapper
that is used internally by thisDAO
to map from records of typeR
to POJOs of typeP
.void
merge(Collection<P> objects)
Performs a batchMERGE
statement for a given set of POJOs.void
merge(P object)
Performs anMERGE
statement for a given POJO.void
merge(P... objects)
Performs a batchMERGE
statement for a given set of POJOs.@NotNull Settings
settings()
The settings wrapped by this context.void
update(Collection<P> objects)
Performs a batchUPDATE
statement for a given set of POJOs.void
update(P object)
Performs anUPDATE
statement for a given POJO.void
update(P... objects)
Performs a batchUPDATE
statement for a given set of POJOs.
-
-
-
Method Detail
-
configuration
@NotNull @NotNull Configuration configuration()
Expose the configuration in whose context thisDAO
is operating.- Returns:
- the
DAO
's underlyingConfiguration
-
settings
@NotNull @NotNull Settings settings()
The settings wrapped by this context.This method is a convenient way of accessing
configuration().settings()
.
-
dialect
@NotNull @NotNull SQLDialect dialect()
TheSQLDialect
wrapped by this context.This method is a convenient way of accessing
configuration().dialect()
.
-
family
@NotNull @NotNull SQLDialect family()
TheSQLDialect.family()
wrapped by this context.This method is a convenient way of accessing
configuration().family()
.
-
mapper
@NotNull @NotNull RecordMapper<R,P> mapper()
Expose theRecordMapper
that is used internally by thisDAO
to map from records of typeR
to POJOs of typeP
.- Returns:
- the
DAO
's underlyingRecordMapper
-
insert
@Support void insert(P object) throws DataAccessException
Performs anINSERT
statement for a given POJO.- Parameters:
object
- The POJO to be inserted- Throws:
DataAccessException
- if something went wrong executing the query
-
insert
@Support void insert(P... objects) throws DataAccessException
Performs a batchINSERT
statement for a given set of POJOs.- Parameters:
objects
- The POJOs to be inserted- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
insert(Collection)
-
insert
@Support void insert(Collection<P> objects) throws DataAccessException
Performs a batchINSERT
statement for a given set of POJOs.- Parameters:
objects
- The POJOs to be inserted- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
insert(Object...)
-
update
@Support void update(P object) throws DataAccessException
Performs anUPDATE
statement for a given POJO.- Parameters:
object
- The POJO to be updated- Throws:
DataAccessException
- if something went wrong executing the query
-
update
@Support void update(P... objects) throws DataAccessException
Performs a batchUPDATE
statement for a given set of POJOs.- Parameters:
objects
- The POJOs to be updated- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
update(Collection)
-
update
@Support void update(Collection<P> objects) throws DataAccessException
Performs a batchUPDATE
statement for a given set of POJOs.- Parameters:
objects
- The POJOs to be updated- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
update(Object...)
-
merge
@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,H2,HSQLDB,INFORMIX,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SQLITE,SQLSERVER,SYBASE,TERADATA}) void merge(P object) throws DataAccessException
Performs anMERGE
statement for a given POJO.- Parameters:
object
- The POJO to be merged- Throws:
DataAccessException
- if something went wrong executing the query
-
merge
@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,H2,HSQLDB,INFORMIX,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SQLITE,SQLSERVER,SYBASE,TERADATA}) void merge(P... objects) throws DataAccessException
Performs a batchMERGE
statement for a given set of POJOs.- Parameters:
objects
- The POJOs to be merged- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
update(Collection)
-
merge
@Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,CUBRID,DB2,DERBY,H2,HSQLDB,INFORMIX,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES_9_5,SQLITE,SQLSERVER,SYBASE,TERADATA}) void merge(Collection<P> objects) throws DataAccessException
Performs a batchMERGE
statement for a given set of POJOs.- Parameters:
objects
- The POJOs to be merged- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
update(Object...)
-
delete
@Support void delete(P object) throws DataAccessException
Performs aDELETE
statement for a POJO- Parameters:
object
- The POJO to be deleted- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
delete(Collection)
-
delete
@Support void delete(P... objects) throws DataAccessException
Performs aDELETE
statement for a given set of POJOs.- Parameters:
objects
- The POJOs to be deleted- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
delete(Collection)
-
delete
@Support void delete(Collection<P> objects) throws DataAccessException
Performs aDELETE
statement for a given set of POJOs.- Parameters:
objects
- The POJOs to be deleted- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
delete(Object...)
-
deleteById
@Support void deleteById(T... ids) throws DataAccessException
Performs aDELETE
statement for a given set of IDs.- Parameters:
ids
- The IDs to be deleted- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
delete(Collection)
-
deleteById
@Support void deleteById(Collection<T> ids) throws DataAccessException
Performs aDELETE
statement for a given set of IDs.- Parameters:
ids
- The IDs to be deleted- Throws:
DataAccessException
- if something went wrong executing the query- See Also:
delete(Object...)
-
exists
@Support 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
@Support 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
@Support 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
@NotNull @Support @NotNull 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
@Nullable @Support 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
@NotNull @Support <Z> @NotNull 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 againstvalues
- The accepted values- Returns:
- A list of records fulfilling
field IN (values)
- Throws:
DataAccessException
- if something went wrong executing the query
-
fetchRange
@NotNull @Support <Z> @NotNull 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 againstlowerInclusive
- The range's lower bound (inclusive), or unbounded ifnull
.upperInclusive
- The range's upper bound (inclusive), or unbounded ifnull
.- Returns:
- A list of records fulfilling
field BETWEEN lowerInclusive AND upperInclusive
- Throws:
DataAccessException
- if something went wrong executing the query
-
fetchOne
@Nullable @Support <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 againstvalue
- The accepted value- Returns:
- A record fulfilling
field = value
, ornull
- Throws:
DataAccessException
- This exception is thrown- if something went wrong executing the query
- if the query returned more than one value
-
fetchOptional
@NotNull @Support <Z> @NotNull 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 againstvalue
- 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
-
-