use of io.requery.OneToMany in project requery by requery.
the class AttributeMember method processAssociativeAnnotations.
private void processAssociativeAnnotations(ProcessingEnvironment processingEnvironment, ElementValidator validator) {
Optional<Annotation> oneToOne = annotationOf(OneToOne.class);
Optional<Annotation> oneToMany = annotationOf(OneToMany.class);
Optional<Annotation> manyToOne = annotationOf(ManyToOne.class);
Optional<Annotation> manyToMany = annotationOf(ManyToMany.class);
oneToOne = oneToOne.isPresent() ? oneToOne : annotationOf(javax.persistence.OneToOne.class);
oneToMany = oneToMany.isPresent() ? oneToMany : annotationOf(javax.persistence.OneToMany.class);
manyToOne = manyToOne.isPresent() ? manyToOne : annotationOf(javax.persistence.ManyToOne.class);
manyToMany = manyToMany.isPresent() ? manyToMany : annotationOf(javax.persistence.ManyToMany.class);
if (Stream.of(oneToOne, oneToMany, manyToOne, manyToMany).filter(Optional::isPresent).count() > 1) {
validator.error("Cannot have more than one associative annotation per field");
}
if (oneToOne.isPresent()) {
cardinality = Cardinality.ONE_TO_ONE;
ReflectiveAssociation reflect = new ReflectiveAssociation(oneToOne.get());
mappedBy = reflect.mappedBy();
cascadeActions = reflect.cascade();
if (!isForeignKey()) {
isReadOnly = true;
if (!isKey()) {
isUnique = true;
}
}
}
if (oneToMany.isPresent()) {
isIterable = true;
cardinality = Cardinality.ONE_TO_MANY;
isReadOnly = true;
ReflectiveAssociation reflect = new ReflectiveAssociation(oneToMany.get());
mappedBy = reflect.mappedBy();
cascadeActions = reflect.cascade();
checkIterable(validator);
processOrderBy();
}
if (manyToOne.isPresent()) {
cardinality = Cardinality.MANY_TO_ONE;
isForeignKey = true;
ReflectiveAssociation reflect = new ReflectiveAssociation(manyToOne.get());
cascadeActions = reflect.cascade();
if (deleteAction == null) {
deleteAction = ReferentialAction.CASCADE;
}
if (updateAction == null) {
updateAction = ReferentialAction.CASCADE;
}
}
if (manyToMany.isPresent()) {
isIterable = true;
cardinality = Cardinality.MANY_TO_MANY;
ReflectiveAssociation reflect = new ReflectiveAssociation(manyToMany.get());
mappedBy = reflect.mappedBy();
cascadeActions = reflect.cascade();
Optional<JunctionTable> junctionTable = annotationOf(JunctionTable.class);
Optional<javax.persistence.JoinTable> joinTable = annotationOf(javax.persistence.JoinTable.class);
if (junctionTable.isPresent()) {
Elements elements = processingEnvironment.getElementUtils();
associativeDescriptor = new JunctionTableAssociation(elements, this, junctionTable.get());
} else if (joinTable.isPresent()) {
associativeDescriptor = new JoinTableAssociation(joinTable.get());
}
isReadOnly = true;
checkIterable(validator);
processOrderBy();
}
if (isForeignKey()) {
if (deleteAction == ReferentialAction.SET_NULL && !isNullable()) {
validator.error("Cannot SET_NULL on optional attribute", ForeignKey.class);
}
// user mirror so generated type can be referenced
Optional<? extends AnnotationMirror> mirror = Mirrors.findAnnotationMirror(element(), ForeignKey.class);
if (mirror.isPresent()) {
referencedType = mirror.flatMap(m -> Mirrors.findAnnotationValue(m, "references")).map(value -> value.getValue().toString()).orElse(null);
} else if (!typeMirror().getKind().isPrimitive()) {
referencedType = typeMirror().toString();
}
}
}
Aggregations