@Retention(value=RUNTIME)
@Target(value=FIELD)
public @interface OneToManyCascade
SelectCascade.sourceParameterFieldNames()
are not known
by default. For more complex cascade relationships, use Cascade
.
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".
OneToManyCascade is the default for non-static, non-transient fields that are Collection
,
Map
, or array. For example:
For apublic class SomeParent { @Column(primaryKey=true) int someParentId; List<SomeChild> someChildList; // defaults to @OneToManyCascade ... } // equivalent to public class SomeParent { @Column(primaryKey=true) int someParentId; @OneToManyCascade List<SomeChild> someChildList; ... } public class SomeChild { @Column(primaryKey=true) int someChildId; int someParentId; // required foreign key name must be same as parent primary key for default OneToManyCascade ... }
Map
, the default cascade parameters are:
public class SomeParent { @Column(primaryKey=true) int someParentId; Map<Integer, SomeChild> someChildList; // defaults to @OneToManyCascade ... } // equivalent to public class SomeParent { @Column(primaryKey=true) int someParentId; // uses SomeChild.hashCode for map key @OneToManyCascade(selects=@SelectCascade(operation=HashMapSelectOperation.class, sourceParameterFieldNames="#primaryKeyFields", targetWhereName="#sourceFieldNames")) Map<Integer, SomeChild> someChildList; ... }
Modifier and Type | Optional Element and Description |
---|---|
DeleteCascade[] |
deletes
The cascade operations to perform when source row is deleted.
|
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
The cascade operations to perform when source row is inserted.
|
java.lang.String |
name
Names the cascade so that it occurs only when desired.
|
boolean |
readOnly
Indicates if cascade should never modify the database.
|
SaveCascade[] |
saves
The cascade operations to perform when source row is saved.
|
SelectCascade[] |
selects
Select cascade operations that will select target rows.
|
java.lang.Class<?> |
targetClass
Class type of target field to affect.
|
UpdateCascade[] |
updates
The cascade operations to perform when source row is updated.
|
public abstract boolean readOnly
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 nonscalar 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.