ENTITY
- The type of the class that the Dao
will support.BUILDER
- The type of the class that can be used to construct new ENTITY
instances and accept individual data elements.public class IndirectDaoBuilder<ENTITY,BUILDER> extends Object implements DaoDescriptor<ENTITY,BUILDER>
IndirectDaoBuilder
is used for times when the class representing
the persisted entity is immutable. It allows the relationships between the database
table, the entity class, and the entity's builder class to be defined.
Also see DaoBuilder
.
Constructor and Description |
---|
IndirectDaoBuilder(String tableName,
Supplier<BUILDER> supplier,
Function<BUILDER,ENTITY> buildFunction)
Create a new DaoBuilder instance.
|
Modifier and Type | Method and Description |
---|---|
Dao<ENTITY> |
buildDao(Connection connection)
Creates a
Dao for performing CRUD operations of type ENTITY . |
Function<BUILDER,ENTITY> |
buildFunction() |
KeylessDao<ENTITY> |
buildKeylessDao(Connection connection)
Creates a
Dao for performing CRUD operations of type ENTITY . |
Queries |
buildQueries()
Build the SQL that will be used by
DAO objects created by this builder. |
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
|
List<JoinColumn<ENTITY,?,BUILDER,?>> |
joinColumns()
The columns that contain references to foreign keys to other objects
|
IndirectDaoBuilder<ENTITY,BUILDER> |
notNull()
Sets the most recent column added to this DaoBuilder to prevent it allowing
nulls on inserts or updates.
|
ParentColumn<ENTITY,?,BUILDER,?> |
parentColumn() |
PrimaryKey<ENTITY,BUILDER> |
primaryKey()
The primary key for objects of type
ENTITY |
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 |
IndirectDaoBuilder<ENTITY,BUILDER> |
withBigDecimalColumn(String columnName,
Function<ENTITY,BigDecimal> getter,
BiConsumer<BUILDER,BigDecimal> setter)
Describes a numeric data element with a decimal part.
|
IndirectDaoBuilder<ENTITY,BUILDER> |
withBooleanColumn(String columnName,
Function<ENTITY,Boolean> getter,
BiConsumer<BUILDER,Boolean> setter)
Describes a data element that represents a true/false value that is
backed by a SQL boolean column.
|
<CHILD,CHILDBUILDER> |
withChildren(Function<ENTITY,List<CHILD>> getter,
BiConsumer<BUILDER,List<CHILD>> setter,
DaoDescriptor<CHILD,CHILDBUILDER> childDaoDescriptor)
Describes a relationship between the object
ENTITY and its several
child objects of type U . |
<E> IndirectDaoBuilder<ENTITY,BUILDER> |
withConvertingStringColumn(String columnName,
Function<ENTITY,E> getter,
BiConsumer<BUILDER,E> setter,
Converter<E,String> converter)
Describes a data element with a particular type (like an enumeration) that
is persisted using a
String representation. |
IndirectDaoBuilder<ENTITY,BUILDER> |
withIntegerBooleanColumn(String columnName,
Function<ENTITY,Boolean> getter,
BiConsumer<BUILDER,Boolean> setter)
Describes a data element that represents a true/false value
and is backed by a column holding an integer value.
|
IndirectDaoBuilder<ENTITY,BUILDER> |
withIntegerColumn(String columnName,
Function<ENTITY,Long> getter,
BiConsumer<BUILDER,Long> setter)
Describes a numeric data element with no decimal or fractional part.
|
<U> IndirectDaoBuilder<ENTITY,BUILDER> |
withJoinColumn(String columnName,
Function<ENTITY,U> getter,
BiConsumer<BUILDER,U> setter,
DaoDescriptor<U,?> daoDescriptor)
Describes a data element that is represented by an
Object of some
other type U with its own table for persistence. |
IndirectDaoBuilder<ENTITY,BUILDER> |
withLocalDateTimeColumn(String columnName,
Function<ENTITY,LocalDateTime> getter,
BiConsumer<BUILDER,LocalDateTime> setter)
Describes a data element that represents a time stamp.
|
<P> IndirectDaoBuilder<ENTITY,BUILDER> |
withParentColumn(String columnName)
Indicator that the column is a reference to an owning parent object.
|
<P> IndirectDaoBuilder<ENTITY,BUILDER> |
withParentColumn(String columnName,
Function<ENTITY,P> getter,
BiConsumer<BUILDER,P> setter)
Indicator that the column is a reference to an owning parent object.
|
IndirectDaoBuilder<ENTITY,BUILDER> |
withPrimaryKey(String columnName,
String sequenceName,
Function<ENTITY,Long> getter,
BiConsumer<BUILDER,Long> setter)
Set data about the primary key of the table for this type.
|
IndirectDaoBuilder<ENTITY,BUILDER> |
withStringBooleanColumn(String columnName,
Function<ENTITY,Boolean> getter,
BiConsumer<BUILDER,Boolean> setter)
Describes a data element that represents a true/false value
and is backed by a column holding a String value.
|
IndirectDaoBuilder<ENTITY,BUILDER> |
withStringColumn(String columnName,
Function<ENTITY,String> getter,
BiConsumer<BUILDER,String> setter)
Describes a text or string data element.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
allColumns, dataColumnsWithParent, dataColumnsWithParent, hasParent, select
public IndirectDaoBuilder(String tableName, Supplier<BUILDER> supplier, Function<BUILDER,ENTITY> buildFunction)
tableName
- The name of the table in the database.supplier
- A mechanism (generally a constructor) for creating a new instance.buildFunction
- How to create an instance of the entity class from its builder.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 List<Column<ENTITY,BUILDER>> dataColumns()
KeylessDaoDescriptor
dataColumns
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public PrimaryKey<ENTITY,BUILDER> primaryKey()
DaoDescriptor
ENTITY
primaryKey
in interface DaoDescriptor<ENTITY,BUILDER>
public List<ChildrenDescriptor<ENTITY,?,BUILDER,?>> childrenDescriptors()
KeylessDaoDescriptor
ENTITY
childrenDescriptors
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public ParentColumn<ENTITY,?,BUILDER,?> parentColumn()
parentColumn
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public List<JoinColumn<ENTITY,?,BUILDER,?>> joinColumns()
KeylessDaoDescriptor
joinColumns
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public Function<BUILDER,ENTITY> buildFunction()
buildFunction
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public Dao<ENTITY> buildDao(Connection connection)
Dao
for performing CRUD operations of type ENTITY
.connection
- The SQL connection this Dao
will use
for its operations.Dao
.public KeylessDao<ENTITY> buildKeylessDao(Connection connection)
Dao
for performing CRUD operations of type ENTITY
.connection
- The SQL connection this Dao
will use
for its operations.Dao
.public Queries buildQueries()
DAO
objects created by this builder.public IndirectDaoBuilder<ENTITY,BUILDER> withStringColumn(String columnName, Function<ENTITY,String> getter, BiConsumer<BUILDER,String> setter)
columnName
- The name of the column that holds the data element.getter
- The function on ENTITY
that returns the data element.setter
- The function on ENTITY
that consumes the data element.public IndirectDaoBuilder<ENTITY,BUILDER> withIntegerColumn(String columnName, Function<ENTITY,Long> getter, BiConsumer<BUILDER,Long> setter)
columnName
- The name of the column that holds the data element.getter
- The function on ENTITY
that returns the data element.setter
- The function on ENTITY
that consumes the data element.public IndirectDaoBuilder<ENTITY,BUILDER> withBigDecimalColumn(String columnName, Function<ENTITY,BigDecimal> getter, BiConsumer<BUILDER,BigDecimal> setter)
columnName
- The name of the column that holds the data element.getter
- The function on ENTITY
that returns the data element.setter
- The function on ENTITY
that consumes the data element.public <E> IndirectDaoBuilder<ENTITY,BUILDER> withConvertingStringColumn(String columnName, Function<ENTITY,E> getter, BiConsumer<BUILDER,E> setter, Converter<E,String> converter)
String
representation.E
- The type being converted for persistence.columnName
- The name of the column that holds the data element.getter
- The function on ENTITY
that returns the data element.setter
- The function on ENTITY
that consumes the data element.converter
- A mechanism for converting between a String
and
the type E
that the object contains.public IndirectDaoBuilder<ENTITY,BUILDER> withLocalDateTimeColumn(String columnName, Function<ENTITY,LocalDateTime> getter, BiConsumer<BUILDER,LocalDateTime> setter)
columnName
- The name of the column that holds the data element.getter
- The function on ENTITY
that returns the data element.setter
- The function on ENTITY
that consumes the data element.public IndirectDaoBuilder<ENTITY,BUILDER> withBooleanColumn(String columnName, Function<ENTITY,Boolean> getter, BiConsumer<BUILDER,Boolean> setter)
columnName
- The name of the column that holds the data element.getter
- The function on ENTITY
that returns the data element.setter
- The function on ENTITY
that consumes the data element.public IndirectDaoBuilder<ENTITY,BUILDER> withStringBooleanColumn(String columnName, Function<ENTITY,Boolean> getter, BiConsumer<BUILDER,Boolean> setter)
columnName
- The name of the column that holds the data element.getter
- The function on ENTITY
that returns the data element.setter
- The function on ENTITY
that consumes the data element.public IndirectDaoBuilder<ENTITY,BUILDER> withIntegerBooleanColumn(String columnName, Function<ENTITY,Boolean> getter, BiConsumer<BUILDER,Boolean> setter)
columnName
- The name of the column that holds the data element.getter
- The function on ENTITY
that returns the data element.setter
- The function on ENTITY
that consumes the data element.public <U> IndirectDaoBuilder<ENTITY,BUILDER> withJoinColumn(String columnName, Function<ENTITY,U> getter, BiConsumer<BUILDER,U> setter, DaoDescriptor<U,?> daoDescriptor)
Object
of some
other type U
with its own table for persistence.
Join columns describe entities that have their own independent existence and
their persistence is a pre-requisite for the persistence of dependent objects.
Imagine a schema that describes cities and states. Every city entity should
be assigned to exactly one state. If the city is modified or deleted, it
has no repercusions to the state entity. The only thing that can happen is
that the city is assigned to a new state.U
- The type of the data element.columnName
- The name of the column with the foreign key to the other table.
This column must be an integer type and must reference the primary
key of the other table.getter
- The function on ENTITY
that returns the data element.setter
- The function on ENTITY
that consumes the data element.daoDescriptor
- The description of how the mapping for the subordinate element
is persisted. Both Dao
and DaoBuilder
objects implement the DaoDescriptor
interface.public <CHILD,CHILDBUILDER> IndirectDaoBuilder<ENTITY,BUILDER> withChildren(Function<ENTITY,List<CHILD>> getter, BiConsumer<BUILDER,List<CHILD>> setter, DaoDescriptor<CHILD,CHILDBUILDER> childDaoDescriptor)
ENTITY
and its several
child objects of type U
.
When hrorm inserts or updates objects with children it will attempt to
create, update, or delete child elements as necessary.
The above should be emphasized. For the purposes of persistence, Hrorm
treats child objects (and grandchild and further generations of objects
transitively) as wholly owned by the parent object. On an update or
delete of the parent, the child objects will be updated or deleted as
necessary. Imagine a schema with a recipe entity and an ingredient
entity. The ingredient entities are children of various recipes. If
the recipe for bechamel is deleted, it makes no sense to have an
orphaned ingredient entry for one cup of butter. It will therefore be
deleted.CHILD
- The type of the child data elements.CHILDBUILDER
- The type of the builder of child data elementsgetter
- The function on ENTITY
that returns the children.setter
- The function on ENTITY
that consumes the children.childDaoDescriptor
- The description of how the mapping for the subordinate elements
are persisted. Both Dao
and DaoBuilder
objects implement the DaoDescriptor
interface.public IndirectDaoBuilder<ENTITY,BUILDER> withPrimaryKey(String columnName, String sequenceName, Function<ENTITY,Long> getter, BiConsumer<BUILDER,Long> setter)
columnName
- The name of the column in the table that holds the primary key.sequenceName
- The name of the sequence that will provide new keys.getter
- The function to call to get the primary key value from an object instance.setter
- The function to call to set the primary key value to an object instance.public <P> IndirectDaoBuilder<ENTITY,BUILDER> withParentColumn(String columnName, Function<ENTITY,P> getter, BiConsumer<BUILDER,P> setter)
P
- The type of the parent object.columnName
- The name of the column that holds the foreign key reference.getter
- The function to call for setting the parent onto the child.setter
- The function to call for getting the parent from the child.public <P> IndirectDaoBuilder<ENTITY,BUILDER> withParentColumn(String columnName)
P
- The type of the parent object.columnName
- The name of the column that holds the foreign key reference.public IndirectDaoBuilder<ENTITY,BUILDER> notNull()
Copyright © 2019. All rights reserved.