@Retention(value=RUNTIME)
@Target(value=FIELD)
public @interface Cascade
OneToManyCascade
or OneToOneCascade
.
More than one operation is allowed per field even though it is not likely that you would
need more than one. selects()
, updates()
, inserts()
,
deletes()
, and saves()
accepts arrays which allow an empty array to mean "do nothing".
Modifier and Type | Optional Element and Description |
---|---|
DeleteCascade[] |
deletes
Delete cascade operations for target fields.
|
java.lang.String |
foreignKeyReferenceField
Defines foreign key reference on target (child) rows.
|
java.lang.String[] |
foreignKeyValueFields
Defines foreign key(s) on target (child) rows.
|
InsertCascade[] |
inserts
Insert cascade operations for target fields.
|
java.lang.String |
name
Names the cascade so that it occurs only when desired.
|
SaveCascade[] |
saves
Save cascade operations for target fields.
|
SelectCascade[] |
selects
Select cascade operations for target fields.
|
java.lang.Class<?> |
targetClass
Class type of target field to affect.
|
UpdateCascade[] |
updates
Update cascade operations for target fields.
|
public abstract java.lang.Class<?> targetClass
Database.getTable(Class)
to
get table for cascade operation. targetClass()
is optional for scalar fields since
target class can be obtained from target field at runtime.
For non-scalar target field types, like arrays, Collection
types, and
Map
types, targetClass can be determined from the field. Array types can be determined
through Class.getComponentType()
. For collections and maps, target class can be determined
through the parameterized type with Field.getGenericType()
if the generic type is not
parameterized. For complex parameterized types, target class must be specified.
The following are examples of fields where targetClass=Something.class is optional in cascade annotations because it can be determined through reflection:
Something scalar; Something[] array; List<Something> list; Map<String, Something> map;
public abstract SelectCascade[] selects
public abstract InsertCascade[] inserts
public abstract UpdateCascade[] updates
public abstract SaveCascade[] saves
public abstract DeleteCascade[] deletes
public abstract java.lang.String[] foreignKeyValueFields
SelectCascade.setForeignKeyValues()
, InsertCascade.setForeignKeyValues()
,
UpdateCascade.setForeignKeyValues()
, DeleteCascade.setForeignKeyValues()
,
SaveCascade.setForeignKeyValues()
.
When target (parent) row is cascaded, then each target (child) row foreign key setters are invoked with values from source (parent) primary key.
Source row key(s) are primary keys in source row defined by Column.primaryKey()
,
Column.identity()
, or Row.primaryKeyFields()
.
When "#" is used, then cascade assumes that source key field names are the same as target (child) key field names. For example: Parent.parentId --> Child.parentId.
If explicit fields are named, then they must be in same order as source row primary key fields.
public abstract java.lang.String foreignKeyReferenceField
SelectCascade.setForeignKeyReference()
, InsertCascade.setForeignKeyReference()
,
UpdateCascade.setForeignKeyReference()
, DeleteCascade.setForeignKeyReference()
,
SaveCascade.setForeignKeyReference()
.
When target (parent) row is cascaded, then each target (child) row foreign key reference setter is invoked with reference to source (parent).
When "class" is used, then cascade assumes that target (child) key reference field name is parent class simple name (begins with lower case). For example: SomeParent (source) of SomeChild (target) will use SomeChild.someParent field and invoke SomeChild.setSomeParent(SomeParent).
public abstract java.lang.String name
Table.setRequiredCascades(String...)
or SqlOperation.setRequiredCascades(String...)
.
If no name is specified (empty string) and no required cascades are specified, then cascade will
occur by default since the default required cascade for Table
is an empty string.