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(ENTITY item,
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.
|
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() |
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> |
selectManyByColumns(ENTITY template,
Map<String,Operator> columnNamesMap)
Select multiple records from the database by some search criteria.
|
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, columnMap, dataColumnsWithParent, dataColumnsWithParent, hasParent
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 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, Map<String,Operator> columnNamesMap)
KeylessDao
This method will perform a select on the database and return the results
found. The where clause will be generated to include tests of the column
names specified in the columnNames
parameter. Each entry in
that Map
should be accompanied by an Operation
specifying what comparison should be used, e.g. =, LIKE, >, etc.
selectManyByColumns
in interface KeylessDao<ENTITY>
template
- An instance of type ENTITY with populated values corresponding to the
column names to select by.columnNamesMap
- The names of the database columns paired with the operation
that should be used to construct the SQL select statement.public <T> T foldingSelect(ENTITY item, T identity, BiFunction<T,ENTITY,T> accumulator, String... columnNames)
KeylessDao
foldingSelect
in interface KeylessDao<ENTITY>
T
- The type of the value to be computed.item
- 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.protected <A> A fromSingletonList(List<A> items)
Copyright © 2019. All rights reserved.