use Objects.requireNonNull in generated code for repositories
instead of directly throwing IllegalArgumentException
This commit is contained in:
parent
02cf728bcb
commit
8d30649cf1
|
@ -17,6 +17,7 @@ import static org.hibernate.processor.annotation.AnnotationMetaEntity.usingReact
|
|||
import static org.hibernate.processor.annotation.AnnotationMetaEntity.usingReactiveSessionAccess;
|
||||
import static org.hibernate.processor.annotation.AnnotationMetaEntity.usingStatelessSession;
|
||||
import static org.hibernate.processor.util.Constants.ENTITY_MANAGER;
|
||||
import static org.hibernate.processor.util.Constants.OBJECTS;
|
||||
import static org.hibernate.processor.util.TypeUtils.hasAnnotation;
|
||||
|
||||
/**
|
||||
|
@ -76,4 +77,15 @@ public abstract class AbstractAnnotatedMethod implements MetaAttribute {
|
|||
return emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
void nullCheck(StringBuilder declaration, String paramName) {
|
||||
declaration
|
||||
.append('\t')
|
||||
.append(annotationMetaEntity.staticImport(OBJECTS, "requireNonNull"))
|
||||
.append('(')
|
||||
.append(paramName.replace('.', '$'))
|
||||
.append(", \"Null ")
|
||||
.append(paramName)
|
||||
.append("\");\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,15 +114,6 @@ public abstract class AbstractCriteriaMethod extends AbstractFinderMethod {
|
|||
}
|
||||
}
|
||||
|
||||
private static void nullCheck(StringBuilder declaration, String paramName) {
|
||||
declaration
|
||||
.append("\tif (")
|
||||
.append(paramName.replace('.', '$'))
|
||||
.append(" == null) throw new IllegalArgumentException(\"Null ")
|
||||
.append(paramName)
|
||||
.append("\");\n");
|
||||
}
|
||||
|
||||
void where(StringBuilder declaration, List<String> paramTypes) {
|
||||
declaration
|
||||
.append("\t_query.where(");
|
||||
|
|
|
@ -180,13 +180,4 @@ public class IdFinderMethod extends AbstractFinderMethod {
|
|||
declaration
|
||||
.append(")");
|
||||
}
|
||||
|
||||
private static void nullCheck(StringBuilder declaration, String parameterName) {
|
||||
declaration
|
||||
.append("\tif (")
|
||||
.append(parameterName)
|
||||
.append(" == null) throw new IllegalArgumentException(\"Null ")
|
||||
.append(parameterName)
|
||||
.append("\");\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class LifecycleMethod extends AbstractAnnotatedMethod {
|
|||
public String getAttributeDeclarationString() {
|
||||
StringBuilder declaration = new StringBuilder();
|
||||
preamble(declaration);
|
||||
nullCheck(declaration);
|
||||
nullCheck(declaration, parameterName);
|
||||
declaration.append("\ttry {\n");
|
||||
delegateCall(declaration);
|
||||
returnArgument(declaration);
|
||||
|
@ -194,15 +194,6 @@ public class LifecycleMethod extends AbstractAnnotatedMethod {
|
|||
}
|
||||
}
|
||||
|
||||
private void nullCheck(StringBuilder declaration) {
|
||||
declaration
|
||||
.append("\tif (")
|
||||
.append(parameterName)
|
||||
.append(" == null) throw new IllegalArgumentException(\"Null ")
|
||||
.append(parameterName)
|
||||
.append("\");\n");
|
||||
}
|
||||
|
||||
private void convertException(StringBuilder declaration, String exception, String convertedException) {
|
||||
declaration
|
||||
.append("\tcatch (")
|
||||
|
|
|
@ -123,6 +123,7 @@ public final class Constants {
|
|||
public static final String MAP_ATTRIBUTE = "jakarta.persistence.metamodel.MapAttribute";
|
||||
|
||||
public static final String JAVA_OBJECT = "java.lang.Object";
|
||||
public static final String OBJECTS = "java.util.Objects";
|
||||
public static final String ITERABLE = "java.lang.Iterable";
|
||||
public static final String COLLECTION = "java.util.Collection";
|
||||
public static final String LIST = "java.util.List";
|
||||
|
|
Loading…
Reference in New Issue