ENTITY
- The type whose persistence is managed by this Dao
.BUILDER
- The type of object that can build an ENTITY
instance.public abstract class AbstractDao<ENTITY,BUILDER> extends Object implements KeylessDaoDescriptor<ENTITY,BUILDER>, KeylessDao<ENTITY>
Dao
implementations.
Most users of hrorm will have no need to directly use this.
Modifier and Type | Field and Description |
---|---|
protected Connection |
connection |
protected SqlBuilder<ENTITY> |
sqlBuilder |
protected SqlRunner<ENTITY,BUILDER> |
sqlRunner |
Constructor and Description |
---|
AbstractDao(Connection connection,
DaoDescriptor<ENTITY,BUILDER> daoDescriptor) |
AbstractDao(Connection connection,
KeylessDaoDescriptor<ENTITY,BUILDER> keylessDaoDescriptor) |
Modifier and Type | Method and Description |
---|---|
Long |
atomicInsert(ENTITY item)
Insert a record into the database within a transaction that is
managed within the
Dao . |
Function<BUILDER,ENTITY> |
buildFunction()
The mechanism for building a new entity instance.
|
protected abstract List<ChildrenDescriptor<ENTITY,?,BUILDER,?>> |
childrenDescriptors() |
<T> T |
foldingSelect(T identity,
BiFunction<T,ENTITY,T> accumulator,
Where where)
Computes a result based on the entities found by a select statement
without realizing the entire list of found entities in memory.
|
static <A> A |
fromSingletonList(List<A> items) |
ColumnCollection<ENTITY,BUILDER> |
getColumnCollection() |
abstract Long |
insert(ENTITY item)
Insert a record into the database.
|
BigDecimal |
runBigDecimalFunction(SqlFunction function,
String columnName,
Where where)
Computes an aggregated BigDecimal value, based on the select criteria specified
and the given SqlFunction and column name.
|
Long |
runLongFunction(SqlFunction function,
String columnName,
Where where)
Computes an aggregated
Long value, based on the select criteria specified
and the given SqlFunction and column name. |
List<ENTITY> |
select()
Read all the records in the database of type ENTITY.
|
List<ENTITY> |
select(ENTITY template,
Order order,
String... columnNames)
Select multiple records from the database by some search criteria in the
required order.
|
List<ENTITY> |
select(ENTITY item,
String... columnNames)
Select multiple records from the database by some search criteria.
|
List<ENTITY> |
select(Order order)
Read all the records in the database of type ENTITY in the
required order.
|
List<ENTITY> |
select(Where where)
Run a select in the data store for entities matching the given where predicates.
|
List<ENTITY> |
select(Where where,
Order order)
Run a select in the data store for entities matching the given where predicates
returned in the order specified.
|
<T,U,V> List<Triplet<T,U,V>> |
selectDistinct(String firstColumnName,
String secondColumnName,
String thirdColumnName,
Where where)
Select unique value triplets from the database for a particular triplet of columns.
|
<T,U> List<Pair<T,U>> |
selectDistinct(String firstColumnName,
String secondColumnName,
Where where)
Select unique value pairs from the database for a particular pair of columns.
|
<T> List<T> |
selectDistinct(String columnName,
Where where)
Select unique values from the database for a particular column.
|
ENTITY |
selectOne(ENTITY item,
String... columnNames)
Select a single record from the database by some search criteria.
|
ENTITY |
selectOne(Where where)
Select a single record from the database by some search criteria.
|
Supplier<BUILDER> |
supplier()
The mechanism to use to instantiate a new instance of type
ENTITY ,
generally a no-argument constructor of the class. |
String |
tableName()
The name of the table that is used to persist type
ENTITY |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
allColumns, dataColumns, joinColumns, nonJoinColumns, select
protected final Connection connection
protected final SqlBuilder<ENTITY> sqlBuilder
public AbstractDao(Connection connection, KeylessDaoDescriptor<ENTITY,BUILDER> keylessDaoDescriptor)
public AbstractDao(Connection connection, DaoDescriptor<ENTITY,BUILDER> daoDescriptor)
protected abstract List<ChildrenDescriptor<ENTITY,?,BUILDER,?>> childrenDescriptors()
public abstract Long insert(ENTITY item)
KeylessDao
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.
insert
in interface KeylessDao<ENTITY>
item
- The instance to be inserted.public String tableName()
KeylessDaoDescriptor
ENTITY
tableName
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public Supplier<BUILDER> supplier()
KeylessDaoDescriptor
ENTITY
,
generally a no-argument constructor of the class.supplier
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public Function<BUILDER,ENTITY> buildFunction()
KeylessDaoDescriptor
buildFunction
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public ColumnCollection<ENTITY,BUILDER> getColumnCollection()
getColumnCollection
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public Long atomicInsert(ENTITY item)
KeylessDao
Dao
. The Dao
will either commit or rollback
the transaction and close the underlying Connection
when complete.atomicInsert
in interface KeylessDao<ENTITY>
item
- The instance to be inserted.public List<ENTITY> select()
KeylessDao
No laziness or caching is involved here. This simply tries to instantiate all the records it can based on the full table.
select
in interface KeylessDao<ENTITY>
public List<ENTITY> select(Order order)
KeylessDao
No laziness or caching is involved here. This simply tries to instantiate all the records it can based on the full table.
select
in interface KeylessDao<ENTITY>
order
- The ordering to usepublic ENTITY selectOne(ENTITY item, String... columnNames)
KeylessDao
If multiple records are found that match the passed item, an exception will be thrown.
If no records are found, null
will be returned.
selectOne
in interface KeylessDao<ENTITY>
item
- An instance of type ENTITY with populated values corresponding to the
column names to select by.columnNames
- The names of the database columnspublic ENTITY selectOne(Where where)
KeylessDao
If multiple records are found that match the given criteria, an exception will be thrown.
If no records are found, null
will be returned.
selectOne
in interface KeylessDao<ENTITY>
where
- The predicates to drive selection.public List<ENTITY> select(ENTITY item, String... columnNames)
KeylessDao
The SQL generated will specify a select by the column names passed, where the values are equal to the values specified in the passed template object. All the values must match, as the where clause will be formed by joining the various column names with 'AND'.
select
in interface KeylessDao<ENTITY>
item
- An instance of type ENTITY with populated values corresponding to the
column names to select by.columnNames
- The names of the database columnspublic List<ENTITY> select(ENTITY template, Order order, String... columnNames)
KeylessDao
The SQL generated will specify a select by the column names passed, where the values are equal to the values specified in the passed template object. All the values must match, as the where clause will be formed by joining the various column names with 'AND'.
select
in interface KeylessDao<ENTITY>
template
- An instance of type ENTITY with populated values corresponding to the
column names to select by.order
- The ordering to usecolumnNames
- The names of the database columnspublic Long runLongFunction(SqlFunction function, String columnName, Where where)
KeylessDao
Long
value, based on the select criteria specified
and the given SqlFunction
and column name.
Will run SQL that looks like this:
select FUNCTION(COLUMN) from TABLE where ...
runLongFunction
in interface KeylessDao<ENTITY>
function
- The function to runcolumnName
- The column to apply the function towhere
- Predicates to drive selection of resultspublic BigDecimal runBigDecimalFunction(SqlFunction function, String columnName, Where where)
KeylessDao
Will run SQL that looks like this:
select FUNCTION(COLUMN) from TABLE where ...
runBigDecimalFunction
in interface KeylessDao<ENTITY>
function
- The function to runcolumnName
- The column to apply the function towhere
- Predicates to drive selection of resultspublic <T> T foldingSelect(T identity, BiFunction<T,ENTITY,T> accumulator, Where where)
KeylessDao
foldingSelect
in interface KeylessDao<ENTITY>
T
- The type of the value to be computed.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.where
- Predicates to drive selection of resultspublic List<ENTITY> select(Where where)
KeylessDao
select
in interface KeylessDao<ENTITY>
where
- The predicates to drive selection.public List<ENTITY> select(Where where, Order order)
KeylessDao
select
in interface KeylessDao<ENTITY>
where
- The predicates to drive selection.order
- The ordering to usepublic <T> List<T> selectDistinct(String columnName, Where where)
KeylessDao
The response will be of the type associated with the class being persisted, not the database type.
selectDistinct
in interface KeylessDao<ENTITY>
T
- The type that this column represents, on the ENTITY
,
not necessarily the type of the database column.columnName
- The column to search for unique values.where
- Filters on the search.public <T,U> List<Pair<T,U>> selectDistinct(String firstColumnName, String secondColumnName, Where where)
KeylessDao
The response will be of the types associated with the class being persisted, not the database type.
selectDistinct
in interface KeylessDao<ENTITY>
T
- The type that the first column represents, on the ENTITY
,
not necessarily the type of the database column.U
- The type that the second column represents, on the ENTITY
,
not necessarily the type of the database column.firstColumnName
- The column name for to search for T
values.secondColumnName
- The column name for to search for U
values.where
- Filters on the search.public <T,U,V> List<Triplet<T,U,V>> selectDistinct(String firstColumnName, String secondColumnName, String thirdColumnName, Where where)
KeylessDao
The response will be of the types associated with the class being persisted, not the database type.
selectDistinct
in interface KeylessDao<ENTITY>
T
- The type that the first column represents, on the ENTITY
,
not necessarily the type of the database column.U
- The type that the second column represents, on the ENTITY
,
not necessarily the type of the database column.V
- The type that the second column represents, on the ENTITY
,
not necessarily the type of the database column.firstColumnName
- The column name for to search for T
values.secondColumnName
- The column name for to search for U
values.thirdColumnName
- The column name for to search for V
values.where
- Filters on the search.public static <A> A fromSingletonList(List<A> items)
Copyright © 2019. All rights reserved.