-
- 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 aRecordsubtype 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 Configurationconfiguration()Expose the configuration in whose context thisDAOis operating.longcount()Count all records of the underlying table.voiddelete(Collection<P> objects)Performs aDELETEstatement for a given set of POJOsvoiddelete(P object)Performs aDELETEstatement for a POJOvoiddelete(P... objects)Performs aDELETEstatement for a given set of POJOsvoiddeleteById(Collection<T> ids)Performs aDELETEstatement for a given set of IDsvoiddeleteById(T... ids)Performs aDELETEstatement for a given set of IDsSQLDialectdialect()TheSQLDialectwrapped by this context.booleanexists(P object)Checks if a given POJO existsbooleanexistsById(T id)Checks if a given ID existsSQLDialectfamily()TheSQLDialect.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> PfetchOne(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.PfindById(T id)Find a record of the underlying table by ID.TgetId(P object)Extract the ID value from a POJO.Table<R>getTable()Get the underlying table.Class<P>getType()Get the underlying POJO type.voidinsert(Collection<P> objects)Performs a batchINSERTstatement for a given set of POJOsvoidinsert(P object)Performs anINSERTstatement for a given POJOvoidinsert(P... objects)Performs a batchINSERTstatement for a given set of POJOsRecordMapper<R,P>mapper()Expose theRecordMapperthat is used internally by thisDAOto map from records of typeRto POJOs of typeP.Settingssettings()The settings wrapped by this context.voidupdate(Collection<P> objects)Performs a batchUPDATEstatement for a given set of POJOsvoidupdate(P object)Performs anUPDATEstatement for a given POJOvoidupdate(P... objects)Performs a batchUPDATEstatement for a given set of POJOs
-
-
-
Method Detail
-
configuration
Configuration configuration()
Expose the configuration in whose context thisDAOis operating.- Returns:
- the
DAO's underlyingConfiguration
-
settings
Settings settings()
The settings wrapped by this context.This method is a convenient way of accessing
configuration().settings().
-
dialect
SQLDialect dialect()
TheSQLDialectwrapped by this context.This method is a convenient way of accessing
configuration().dialect().
-
family
SQLDialect family()
TheSQLDialect.family()wrapped by this context.This method is a convenient way of accessing
configuration().family().
-
mapper
RecordMapper<R,P> mapper()
Expose theRecordMapperthat is used internally by thisDAOto map from records of typeRto POJOs of typeP.- Returns:
- the
DAO's underlyingRecordMapper
-
insert
void insert(P object) throws DataAccessException
Performs anINSERTstatement for a given POJO- Parameters:
object- The POJO to be inserted- Throws:
DataAccessException- if something went wrong executing the query
-
insert
void insert(P... objects) throws DataAccessException
Performs a batchINSERTstatement 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
void insert(Collection<P> objects) throws DataAccessException
Performs a batchINSERTstatement 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
void update(P object) throws DataAccessException
Performs anUPDATEstatement for a given POJO- Parameters:
object- The POJO to be updated- Throws:
DataAccessException- if something went wrong executing the query
-
update
void update(P... objects) throws DataAccessException
Performs a batchUPDATEstatement 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
void update(Collection<P> objects) throws DataAccessException
Performs a batchUPDATEstatement 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...)
-
delete
void delete(P object) throws DataAccessException
Performs aDELETEstatement for a POJO- Parameters:
object- The POJO to be deleted- Throws:
DataAccessException- if something went wrong executing the query- See Also:
delete(Collection)
-
delete
void delete(P... objects) throws DataAccessException
Performs aDELETEstatement 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
void delete(Collection<P> objects) throws DataAccessException
Performs aDELETEstatement 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
void deleteById(T... ids) throws DataAccessException
Performs aDELETEstatement 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
void deleteById(Collection<T> ids) throws DataAccessException
Performs aDELETEstatement 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
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 DataAccessExceptionCount 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
nullif 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 againstvalues- 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 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
<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
<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 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
-
-