ENTITY
- The type whose persistence is managed by this Dao
.PARENT
- The type of the parent (if any) of type ENTITY
.BUILDER
- The type of object that can build an ENTITY
instance.PARENTBUILDER
- The type of the object that can build a PARENT
instance.public class KeylessDaoImpl<ENTITY,PARENT,BUILDER,PARENTBUILDER> extends Object implements KeylessDao<ENTITY>, KeylessDaoDescriptor<ENTITY,BUILDER>
KeylessDao
implementation.
There is no good reason to directly construct this class yourself.
Use a IndirectKeylessDaoBuilder
.
Modifier and Type | Field and Description |
---|---|
protected Function<BUILDER,ENTITY> |
buildFunction |
protected List<ChildrenDescriptor<ENTITY,?,BUILDER,?>> |
childrenDescriptors |
protected Connection |
connection |
protected KeylessSqlBuilder<ENTITY> |
keylessSqlBuilder |
protected ParentColumn<ENTITY,PARENT,BUILDER,PARENTBUILDER> |
parentColumn |
protected SqlRunner<ENTITY,BUILDER> |
sqlRunner |
protected Supplier<BUILDER> |
supplier |
protected String |
tableName |
Constructor and Description |
---|
KeylessDaoImpl(Connection connection,
DaoDescriptor<ENTITY,BUILDER> daoDescriptor) |
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() |
List<ChildrenDescriptor<ENTITY,?,BUILDER,?>> |
childrenDescriptors()
The definitions of any entities that are owned by type
ENTITY |
List<Column<ENTITY,BUILDER>> |
dataColumns()
The columns that contain the data that make up the object
|
<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.
|
protected <A> A |
fromSingletonList(List<A> items) |
Long |
insert(ENTITY item)
Insert a record into the database.
|
List<JoinColumn<ENTITY,?,BUILDER,?>> |
joinColumns()
The columns that contain references to foreign keys to other objects
|
protected List<ENTITY> |
mapBuilders(List<BUILDER> bs) |
protected Envelope<ENTITY> |
newEnvelope(ENTITY item,
long id) |
ParentColumn<ENTITY,PARENT,BUILDER,PARENTBUILDER> |
parentColumn() |
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(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.
|
List<ENTITY> |
selectAll()
Read all the records in the database of type ENTITY.
|
List<ENTITY> |
selectAll(Order order)
Read all the records in the database of type ENTITY in the
required order.
|
ENTITY |
selectByColumns(ENTITY item,
String... columnNames)
Select a single record from the database by some search criteria.
|
List<ENTITY> |
selectManyByColumns(ENTITY template,
Order order,
String... columnNames)
Select multiple records from the database by some search criteria in the
required order.
|
List<ENTITY> |
selectManyByColumns(ENTITY item,
String... columnNames)
Select multiple records 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, dataColumnsWithParent, dataColumnsWithParent, hasParent, select
protected final Connection connection
protected final String tableName
protected final List<ChildrenDescriptor<ENTITY,?,BUILDER,?>> childrenDescriptors
protected final KeylessSqlBuilder<ENTITY> keylessSqlBuilder
protected final ParentColumn<ENTITY,PARENT,BUILDER,PARENTBUILDER> parentColumn
public KeylessDaoImpl(Connection connection, DaoDescriptor<ENTITY,BUILDER> daoDescriptor)
public String tableName()
KeylessDaoDescriptor
ENTITY
tableName
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public List<Column<ENTITY,BUILDER>> dataColumns()
KeylessDaoDescriptor
dataColumns
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public List<JoinColumn<ENTITY,?,BUILDER,?>> joinColumns()
KeylessDaoDescriptor
joinColumns
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 List<ChildrenDescriptor<ENTITY,?,BUILDER,?>> childrenDescriptors()
KeylessDaoDescriptor
ENTITY
childrenDescriptors
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public ParentColumn<ENTITY,PARENT,BUILDER,PARENTBUILDER> parentColumn()
parentColumn
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public Function<BUILDER,ENTITY> buildFunction()
buildFunction
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public Long atomicInsert(ENTITY item)
KeylessDao
Connection
when complete.atomicInsert
in interface KeylessDao<ENTITY>
item
- The instance to be inserted.public 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 List<ENTITY> selectAll()
KeylessDao
No laziness or caching is involved here. This simply tries to instantiate all the records it can based on the full table.
selectAll
in interface KeylessDao<ENTITY>
public List<ENTITY> selectAll(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.
selectAll
in interface KeylessDao<ENTITY>
order
- The ordering to usepublic ENTITY selectByColumns(ENTITY item, String... columnNames)
KeylessDao
selectByColumns
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> selectManyByColumns(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'.
selectManyByColumns
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> selectManyByColumns(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'.
selectManyByColumns
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
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 useprotected <A> A fromSingletonList(List<A> items)
Copyright © 2019. All rights reserved.