Browse Source

add support for cascade flag, helps avoid circularities

tags/2.0.1
Jonathan Cobb 4 years ago
parent
commit
ea4b74c95d
2 changed files with 5 additions and 1 deletions
  1. +4
    -1
      wizard-common/src/main/java/org/cobbzilla/wizard/model/entityconfig/EntityReferences.java
  2. +1
    -0
      wizard-common/src/main/java/org/cobbzilla/wizard/model/entityconfig/annotations/ECForeignKey.java

+ 4
- 1
wizard-common/src/main/java/org/cobbzilla/wizard/model/entityconfig/EntityReferences.java View File

@@ -34,6 +34,9 @@ public class EntityReferences {
public static final Predicate<Field> FIELD_HAS_FK public static final Predicate<Field> FIELD_HAS_FK
= f -> f.getAnnotation(ECForeignKey.class) != null; = f -> f.getAnnotation(ECForeignKey.class) != null;


public static final Predicate<Field> FIELD_HAS_CASCADING_FK
= f -> f.getAnnotation(ECForeignKey.class) != null && f.getAnnotation(ECForeignKey.class).cascade();

public static final Predicate<Field> FIELD_HAS_INDEX public static final Predicate<Field> FIELD_HAS_INDEX
= f -> f.getAnnotation(ECIndex.class) != null; = f -> f.getAnnotation(ECIndex.class) != null;


@@ -69,7 +72,7 @@ public class EntityReferences {
final List<Class<? extends Identifiable>> refs = new ArrayList<>(); final List<Class<? extends Identifiable>> refs = new ArrayList<>();
while (!clazz.getName().equals(Object.class.getName())) { while (!clazz.getName().equals(Object.class.getName())) {
refs.addAll(Arrays.stream(clazz.getDeclaredFields()) refs.addAll(Arrays.stream(clazz.getDeclaredFields())
.filter(EntityReferences.FIELD_HAS_FK)
.filter(EntityReferences.FIELD_HAS_CASCADING_FK)
.map(EntityReferences.FIELD_TO_FK_CLASS) .map(EntityReferences.FIELD_TO_FK_CLASS)
.collect(Collectors.toList())); .collect(Collectors.toList()));
clazz = clazz.getSuperclass(); clazz = clazz.getSuperclass();


+ 1
- 0
wizard-common/src/main/java/org/cobbzilla/wizard/model/entityconfig/annotations/ECForeignKey.java View File

@@ -13,5 +13,6 @@ public @interface ECForeignKey {
Class<? extends Identifiable> entity(); Class<? extends Identifiable> entity();
String field() default "uuid"; String field() default "uuid";
boolean index() default true; boolean index() default true;
boolean cascade() default true;


} }

Loading…
Cancel
Save