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 SchemaDescriptor<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
and IndirectKeylessDaoBuilder
.
Constructor and Description |
---|
IndirectDaoBuilder(String tableName,
Supplier<BUILDER> supplier,
Function<BUILDER,ENTITY> buildFunction)
Create a new
IndirectDaoBuilder 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()
The mechanism for building a new entity instance.
|
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 |
ColumnCollection<ENTITY,BUILDER> |
getColumnCollection() |
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()
The parent column, if there is one, of the
ENTITY . |
IndirectDaoBuilder<ENTITY,BUILDER> |
setSqlTypeName(String sqlTypeName)
Set the SQL type for the most recently added column.
|
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 |
List<List<String>> |
uniquenessConstraints()
A list of column name lists, each of which should be unique.
|
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 . |
<T,U> IndirectDaoBuilder<ENTITY,BUILDER> |
withConvertedGenericColumn(String columnName,
Function<ENTITY,U> getter,
BiConsumer<BUILDER,U> setter,
GenericColumn<T> genericColumn,
Converter<U,T> converter)
Describes a data element of type
U that can be stored in
a GenericColumn that stores objects of type T . |
<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. |
<T> IndirectDaoBuilder<ENTITY,BUILDER> |
withGenericColumn(String columnName,
Function<ENTITY,T> getter,
BiConsumer<BUILDER,T> setter,
GenericColumn<T> genericColumn)
Describes a data element of type
T that can be stored in
a GenericColumn . |
IndirectDaoBuilder<ENTITY,BUILDER> |
withInstantColumn(String columnName,
Function<ENTITY,Instant> getter,
BiConsumer<BUILDER,Instant> setter)
Describes a data element that represents a time stamp.
|
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.
|
<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> |
withLongColumn(String columnName,
Function<ENTITY,Long> getter,
BiConsumer<BUILDER,Long> setter)
Describes a numeric data element with no decimal or fractional part.
|
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.
|
IndirectDaoBuilder<ENTITY,BUILDER> |
withUniqueConstraint(String... columnNames)
Describe a unique constraint on this entity.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
hasParent, primaryKey
allColumns, dataColumns, joinColumns, nonJoinColumns, select
public IndirectDaoBuilder(String tableName, Supplier<BUILDER> supplier, Function<BUILDER,ENTITY> buildFunction)
IndirectDaoBuilder
instance.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 ColumnCollection<ENTITY,BUILDER> getColumnCollection()
getColumnCollection
in interface KeylessDaoDescriptor<ENTITY,BUILDER>
public List<ChildrenDescriptor<ENTITY,?,BUILDER,?>> childrenDescriptors()
DaoDescriptor
ENTITY
childrenDescriptors
in interface DaoDescriptor<ENTITY,BUILDER>
public ParentColumn<ENTITY,?,BUILDER,?> parentColumn()
DaoDescriptor
ENTITY
.parentColumn
in interface DaoDescriptor<ENTITY,BUILDER>
public Function<BUILDER,ENTITY> buildFunction()
KeylessDaoDescriptor
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 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> withLongColumn(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> withInstantColumn(String columnName, Function<ENTITY,Instant> getter, BiConsumer<BUILDER,Instant> 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 IndirectDaoBuilder<ENTITY,BUILDER> withParentColumn(String columnName)
columnName
- The name of the column that holds the foreign key reference.public IndirectDaoBuilder<ENTITY,BUILDER> notNull()
public IndirectDaoBuilder<ENTITY,BUILDER> setSqlTypeName(String sqlTypeName)
VARCHAR2(100)
" instead of just "TEXT
" you
can do so here. This make no difference to the queries that hrorm generates
or how results are parsed.sqlTypeName
- The name of the column in SQL.public <T> IndirectDaoBuilder<ENTITY,BUILDER> withGenericColumn(String columnName, Function<ENTITY,T> getter, BiConsumer<BUILDER,T> setter, GenericColumn<T> genericColumn)
T
that can be stored in
a GenericColumn
.
This interface exists to allow clients to inject whatever column types they need into Hrorm.
T
- The type of the data element on the entity.columnName
- The name of the column in the table that holds the data element.getter
- The function to call to get the value from an object instance.setter
- The function to call to set the value onto an object instance.genericColumn
- The column that supports type T
.public <T,U> IndirectDaoBuilder<ENTITY,BUILDER> withConvertedGenericColumn(String columnName, Function<ENTITY,U> getter, BiConsumer<BUILDER,U> setter, GenericColumn<T> genericColumn, Converter<U,T> converter)
U
that can be stored in
a GenericColumn
that stores objects of type T
.
This interface exists to allow clients to inject whatever column types they need into Hrorm.
T
- The type of the data element that can be persisted.U
- The type of the data element as it exists on the entity object.columnName
- The name of the column in the table that holds the data element.getter
- The function to call to get the value from an object instance.setter
- The function to call to set the value onto an object instance.genericColumn
- The column that supports type T
.converter
- A converter that can translate between types T
and U
.public IndirectDaoBuilder<ENTITY,BUILDER> withUniqueConstraint(String... columnNames)
Schema
.columnNames
- the names of the columns that are to be uniquepublic List<List<String>> uniquenessConstraints()
SchemaDescriptor
uniquenessConstraints
in interface SchemaDescriptor<ENTITY,BUILDER>
Copyright © 2019. All rights reserved.