set JPAChecker agnostic of @ManyToOne primary key type
This commit is contained in:
parent
e156e528c1
commit
249e6ad2c8
@ -12,7 +12,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
@ -223,31 +222,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
}
|
||||
});
|
||||
}
|
||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
||||
: condCheckers.get(0).toCondition();
|
||||
final long count = ioDb.count(annotationManyToOne.targetEntity(), elem,
|
||||
conditionCheck);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else if (type == Integer.class || type == int.class) {
|
||||
final DecimalMax maxValueDecimal = AnnotationTools.getConstraintsDecimalMax(field);
|
||||
if (maxValueDecimal != null) {
|
||||
@ -346,47 +320,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
}
|
||||
});
|
||||
}
|
||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final long count = ioDb.count(annotationManyToOne.targetEntity(), elem);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (type == UUID.class) {
|
||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final long count = ioDb.count(annotationManyToOne.targetEntity(), elem);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (type == Boolean.class || type == boolean.class) {
|
||||
|
||||
} else if (type == Float.class || type == float.class) {
|
||||
@ -732,6 +665,29 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
||||
: condCheckers.get(0).toCondition();
|
||||
final long count = ioDb.count(annotationManyToOne.targetEntity(), elem, conditionCheck);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
final CollectionItemUnique collectionUnique = AnnotationTools.getCollectionItemUnique(field);
|
||||
if (collectionUnique != null) {
|
||||
if (!Collection.class.isAssignableFrom(field.getType())) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user