ENTITY
- The type of the data to be persisted.public interface Dao<ENTITY>
Dao
is an interface that allows basic CRUD operations to be performed.
Using a Dao
, you can insert, select, update, and delete records.Modifier and Type | Method and Description |
---|---|
void |
atomicDelete(ENTITY item)
Run a delete statement in the database within a transaction.
|
long |
atomicInsert(ENTITY item)
Insert a record into the database within a transaction that is
managed within the Dao.
|
void |
atomicUpdate(ENTITY item)
Run an update statement to change the values in the database associated
with an existing record.
|
void |
delete(ENTITY item)
Run a delete statement in the database.
|
<T> T |
foldingSelect(ENTITY template,
T identity,
BiFunction<T,ENTITY,T> accumulator,
String... columnNames)
Computes a result based on the entities found by a select statement
without realizing the entire list of found entities in memory.
|
long |
insert(ENTITY item)
Insert a record into the database.
|
Queries |
queries()
Access the
SQL this Dao is using. |
ENTITY |
select(long id)
Read a record from the database by its primary key.
|
List<ENTITY> |
selectAll()
Read all the records in the database of type ENTITY.
|
ENTITY |
selectByColumns(ENTITY item,
String... columnNames)
Select a single record from the database by some search criteria.
|
List<ENTITY> |
selectMany(List<Long> ids)
Read several records from the database by their primary keys.
|
List<ENTITY> |
selectManyByColumns(ENTITY item,
String... columnNames)
Select multiple records from the database by some search criteria.
|
void |
update(ENTITY item)
Run an update statement to change the values in the database associated
with an existing record.
|
long insert(ENTITY item)
Depending on how the Dao was constucted (whether from a regular
DaoBuilder
or an IndirectDaoBuilder
)
a particular instance of this class may or may not attempt
to mutate the state of the passed item by setting its primary
key.
item
- The instance to be inserted.void update(ENTITY item)
item
- An instance of the class with a populated primary key field
and updated field values.void delete(ENTITY item)
item
- An instance of type ENTITY with a populated primary key.ENTITY select(long id)
id
- The primary key of the record desired.List<ENTITY> selectMany(List<Long> ids)
ids
- The primary keys of the records desired.List<ENTITY> selectAll()
No laziness or caching is involved here. This simply tries to instantiate all the records it can based on the full table.
ENTITY selectByColumns(ENTITY item, String... columnNames)
item
- An instance of type ENTITY with populated values corresponding to the
column names to select by.columnNames
- The names of the database columnsList<ENTITY> selectManyByColumns(ENTITY item, String... columnNames)
item
- An instance of type ENTITY with populated values corresponding to the
column names to select by.columnNames
- The names of the database columnslong atomicInsert(ENTITY item)
Connection
when complete.item
- The instance to be inserted.void atomicUpdate(ENTITY item)
Connection
when complete.item
- An instance of the class with a populated primary key field
and updated field values.void atomicDelete(ENTITY item)
Connection
when complete.item
- An instance of type ENTITY with a populated primary key.<T> T foldingSelect(ENTITY template, T identity, BiFunction<T,ENTITY,T> accumulator, String... columnNames)
T
- The type of the value to be computed.template
- An instance of type ENTITY with populated values corresponding to the
column names to select by.identity
- The identity element of the return type.accumulator
- A function that computes the desired value based on
the values seen thus far and the next instance
of the entity found in the result set.columnNames
- The names of the columns to include in the select where clause.Queries queries()
SQL
this Dao
is using.
The SQL
provided is suitable for being passed to a
PreparedStatement
.
SQL
.Copyright © 2018. All rights reserved.