T
- The class that the Dao will support.public class DaoBuilder<T> extends Object implements DaoDescriptor<T>
Constructor and Description |
---|
DaoBuilder(String tableName,
Supplier<T> supplier)
Create a new DaoBuilder instance.
|
Modifier and Type | Method and Description |
---|---|
Dao<T> |
buildDao(Connection connection)
Creates a
Dao for performing CRUD operations of type T . |
List<ChildrenDescriptor<T,?>> |
childrenDescriptors()
The definitions of any entities that are owned by type
T |
List<TypedColumn<T>> |
dataColumns()
The columns that contain the data that make up the object
|
List<JoinColumn<T,?>> |
joinColumns()
The columns that contain references to foreign keys to other objects
|
DaoBuilder<T> |
notNull()
Sets the most recent column added to this DaoBuilder to prevent it allowing
nulls on inserts or updates.
|
PrimaryKey<T> |
primaryKey()
The primary key for objects of type
T |
Supplier<T> |
supplier()
The mechanism to use to instantiate a new instance of type
T ,
generally a no-argument constructor of the class. |
String |
tableName()
The name of the table that is used to persist type
T |
DaoBuilder<T> |
withBigDecimalColumn(String columnName,
Function<T,BigDecimal> getter,
BiConsumer<T,BigDecimal> setter)
Describes a numeric data element with a decimal part.
|
DaoBuilder<T> |
withBooleanColumn(String columnName,
Function<T,Boolean> getter,
BiConsumer<T,Boolean> setter)
Describes a data element that represents a true/false value.
|
<U> DaoBuilder<T> |
withChildren(String parentChildColumnName,
BiConsumer<U,Long> parentSetter,
Function<T,List<U>> getter,
BiConsumer<T,List<U>> setter,
DaoDescriptor<U> daoDescriptor)
Describes a relationship between the object
T and its several
child objects of type U . |
<E> DaoBuilder<T> |
withConvertingStringColumn(String columnName,
Function<T,E> getter,
BiConsumer<T,E> setter,
Converter<E,String> converter)
Describes a data element with a particular type (like an enumeration) that
is persisted using a
String representation. |
DaoBuilder<T> |
withIntegerColumn(String columnName,
Function<T,Long> getter,
BiConsumer<T,Long> setter)
Describes a numeric data element with no decimal or fractional part.
|
<U> DaoBuilder<T> |
withJoinColumn(String columnName,
Function<T,U> getter,
BiConsumer<T,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. |
DaoBuilder<T> |
withLocalDateTimeColumn(String columnName,
Function<T,LocalDateTime> getter,
BiConsumer<T,LocalDateTime> setter)
Describes a data element that represents a time stamp.
|
DaoBuilder<T> |
withPrimaryKey(String columnName,
String sequenceName,
Function<T,Long> getter,
BiConsumer<T,Long> setter)
Set data about the primary key of the table for this type.
|
DaoBuilder<T> |
withStringColumn(String columnName,
Function<T,String> getter,
BiConsumer<T,String> setter)
Describes a text or string data element.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
allColumns, columnMap
public String tableName()
DaoDescriptor
T
tableName
in interface DaoDescriptor<T>
public Supplier<T> supplier()
DaoDescriptor
T
,
generally a no-argument constructor of the class.supplier
in interface DaoDescriptor<T>
public List<TypedColumn<T>> dataColumns()
DaoDescriptor
dataColumns
in interface DaoDescriptor<T>
public PrimaryKey<T> primaryKey()
DaoDescriptor
T
primaryKey
in interface DaoDescriptor<T>
public List<ChildrenDescriptor<T,?>> childrenDescriptors()
DaoDescriptor
T
childrenDescriptors
in interface DaoDescriptor<T>
public List<JoinColumn<T,?>> joinColumns()
DaoDescriptor
joinColumns
in interface DaoDescriptor<T>
public Dao<T> buildDao(Connection connection)
Dao
for performing CRUD operations of type T
.connection
- The SQL connection this Dao
will use
for its operations.Dao
.public DaoBuilder<T> withStringColumn(String columnName, Function<T,String> getter, BiConsumer<T,String> setter)
columnName
- The name of the column that holds the data element.getter
- The function on T
that returns the data element.setter
- The function on T
that consumes the data element.public DaoBuilder<T> withIntegerColumn(String columnName, Function<T,Long> getter, BiConsumer<T,Long> setter)
columnName
- The name of the column that holds the data element.getter
- The function on T
that returns the data element.setter
- The function on T
that consumes the data element.public DaoBuilder<T> withBigDecimalColumn(String columnName, Function<T,BigDecimal> getter, BiConsumer<T,BigDecimal> setter)
columnName
- The name of the column that holds the data element.getter
- The function on T
that returns the data element.setter
- The function on T
that consumes the data element.public <E> DaoBuilder<T> withConvertingStringColumn(String columnName, Function<T,E> getter, BiConsumer<T,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 T
that returns the data element.setter
- The function on T
that consumes the data element.converter
- A mechanism for converting between a String
and
the type E
that the object contains.public DaoBuilder<T> withLocalDateTimeColumn(String columnName, Function<T,LocalDateTime> getter, BiConsumer<T,LocalDateTime> setter)
columnName
- The name of the column that holds the data element.getter
- The function on T
that returns the data element.setter
- The function on T
that consumes the data element.public DaoBuilder<T> withBooleanColumn(String columnName, Function<T,Boolean> getter, BiConsumer<T,Boolean> setter)
columnName
- The name of the column that holds the data element.getter
- The function on T
that returns the data element.setter
- The function on T
that consumes the data element.public <U> DaoBuilder<T> withJoinColumn(String columnName, Function<T,U> getter, BiConsumer<T,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 T
that returns the data element.setter
- The function on T
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 <U> DaoBuilder<T> withChildren(String parentChildColumnName, BiConsumer<U,Long> parentSetter, Function<T,List<U>> getter, BiConsumer<T,List<U>> setter, DaoDescriptor<U> daoDescriptor)
T
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.
Contrast this behavior with the join column functionality, which describes
the situation wherein the object makes no sense without the joined relation.U
- The type of the child data elements.parentChildColumnName
- The name on of the column on the child table that defines
the persisted link between the children objects of type U
and the parent object of type T
.parentSetter
- The function that allows the primary key of object T
onto
the child object U
.getter
- The function on T
that returns the children.setter
- The function on T
that consumes the children.daoDescriptor
- The description of how the mapping for the subordinate elements
are persisted. Both Dao
and DaoBuilder
objects implement the DaoDescriptor
interface.public DaoBuilder<T> withPrimaryKey(String columnName, String sequenceName, Function<T,Long> getter, BiConsumer<T,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 DaoBuilder<T> notNull()
Copyright © 2018. All rights reserved.