-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Apply Nullability to spring-integration-jpa
#10157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/** | ||
* Provides parser classes to provide Xml namespace support for the Jpa components. | ||
*/ | ||
@org.jspecify.annotations.NullMarked | ||
package org.springframework.integration.jpa.config.xml; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import org.jspecify.annotations.Nullable; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.BeanFactory; | ||
|
@@ -35,7 +36,6 @@ | |
import org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory; | ||
import org.springframework.integration.jpa.support.parametersource.ParameterSource; | ||
import org.springframework.integration.jpa.support.parametersource.ParameterSourceFactory; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.messaging.MessagingException; | ||
import org.springframework.util.Assert; | ||
|
@@ -71,27 +71,27 @@ public class JpaExecutor implements InitializingBean, BeanFactoryAware { | |
|
||
private final JpaOperations jpaOperations; | ||
|
||
private List<JpaParameter> jpaParameters; | ||
private @Nullable List<JpaParameter> jpaParameters; | ||
|
||
private Class<?> entityClass; | ||
private @Nullable Class<?> entityClass; | ||
|
||
private String jpaQuery; | ||
private @Nullable String jpaQuery; | ||
|
||
private String nativeQuery; | ||
private @Nullable String nativeQuery; | ||
|
||
private String namedQuery; | ||
private @Nullable String namedQuery; | ||
|
||
private Expression maxResultsExpression; | ||
private @Nullable Expression maxResultsExpression; | ||
|
||
private Expression firstResultExpression; | ||
private @Nullable Expression firstResultExpression; | ||
|
||
private Expression idExpression; | ||
private @Nullable Expression idExpression; | ||
|
||
private PersistMode persistMode = PersistMode.MERGE; | ||
|
||
private ParameterSourceFactory parameterSourceFactory = null; | ||
private @Nullable ParameterSourceFactory parameterSourceFactory = null; | ||
|
||
private ParameterSource parameterSource; | ||
private @Nullable ParameterSource parameterSource; | ||
|
||
private boolean flush = false; | ||
|
||
|
@@ -111,10 +111,12 @@ public class JpaExecutor implements InitializingBean, BeanFactoryAware { | |
* default a {@link BeanPropertyParameterSourceFactory} implementation is | ||
* used for the sqlParameterSourceFactory property. | ||
*/ | ||
private Boolean usePayloadAsParameterSource = null; | ||
private @Nullable Boolean usePayloadAsParameterSource = null; | ||
|
||
@SuppressWarnings("NullAway.Init") | ||
private BeanFactory beanFactory; | ||
|
||
@SuppressWarnings("NullAway.Init") | ||
private EvaluationContext evaluationContext; | ||
|
||
/** | ||
|
@@ -157,6 +159,10 @@ public JpaExecutor(JpaOperations jpaOperations) { | |
this.jpaOperations = jpaOperations; | ||
} | ||
|
||
/** | ||
* deprecated setIntegrationEvaluationContext, in favor of the one obtained from the application context. | ||
*/ | ||
@Deprecated(since = "7.0", forRemoval = true) | ||
public void setIntegrationEvaluationContext(EvaluationContext evaluationContext) { | ||
this.evaluationContext = evaluationContext; | ||
} | ||
|
@@ -398,10 +404,7 @@ public void afterPropertiesSet() { | |
else if (this.flush) { | ||
this.flushSize = 1; | ||
} | ||
|
||
if (this.evaluationContext == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it harmful to remove in this version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, so instead of depredated method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. We never remove a public API in our classes just because. |
||
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.beanFactory); | ||
} | ||
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.beanFactory); | ||
} | ||
|
||
/** | ||
|
@@ -414,7 +417,7 @@ else if (this.flush) { | |
* @return Either the number of affected entities when using a JPQL query. | ||
* When using a merge/persist the updated/inserted itself is returned. | ||
*/ | ||
public Object executeOutboundJpaOperation(Message<?> message) { | ||
public @Nullable Object executeOutboundJpaOperation(Message<?> message) { | ||
ParameterSource paramSource = null; | ||
if (this.jpaQuery != null || this.nativeQuery != null || this.namedQuery != null) { | ||
paramSource = determineParameterSource(message); | ||
|
@@ -433,7 +436,7 @@ else if (this.namedQuery != null) { | |
} | ||
} | ||
|
||
private Object executeOutboundJpaOperationOnPersistentMode(Message<?> message) { | ||
private @Nullable Object executeOutboundJpaOperationOnPersistentMode(Message<?> message) { | ||
Object payload = message.getPayload(); | ||
switch (this.persistMode) { | ||
case PERSIST -> { | ||
|
@@ -511,8 +514,9 @@ public Object poll(@Nullable final Message<?> requestMessage) { | |
payload = result.iterator().next(); | ||
} | ||
else { | ||
throw new MessagingException(requestMessage, // NOSONAR | ||
"The Jpa operation returned more than 1 result for expectSingleResult mode."); | ||
String description = "The Jpa operation returned more than 1 result for expectSingleResult mode."; | ||
throw requestMessage == null ? new MessagingException(description) | ||
: new MessagingException(requestMessage, description); | ||
} | ||
} | ||
else { | ||
|
@@ -546,7 +550,7 @@ private void checkDelete(@Nullable Object payload) { | |
} | ||
} | ||
|
||
protected List<?> doPoll(ParameterSource jpaQLParameterSource, int firstResult, int maxNumberOfResults) { | ||
protected List<?> doPoll(@Nullable ParameterSource jpaQLParameterSource, int firstResult, int maxNumberOfResults) { | ||
List<?> payload; | ||
if (this.jpaQuery != null) { | ||
payload = | ||
|
@@ -609,6 +613,8 @@ else if (evaluationResult instanceof String) { | |
} | ||
|
||
private ParameterSource determineParameterSource(final Message<?> requestMessage) { | ||
Assert.state(this.usePayloadAsParameterSource != null, "'usePayloadAsParameterSource' must not be null"); | ||
Assert.state(this.parameterSourceFactory != null, "'parameterSourceFactory' must not be null"); | ||
artembilan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (this.usePayloadAsParameterSource) { | ||
return this.parameterSourceFactory.createParameterSource(requestMessage.getPayload()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* Provides core classes of the JPA module. | ||
*/ | ||
@org.springframework.lang.NonNullApi | ||
@org.jspecify.annotations.NullMarked | ||
package org.springframework.integration.jpa.core; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/** | ||
* Provides JPA Components support for Java DSL. | ||
*/ | ||
@org.springframework.lang.NonNullApi | ||
@org.springframework.lang.NonNullFields | ||
@org.jspecify.annotations.NullMarked | ||
package org.springframework.integration.jpa.dsl; |
Uh oh!
There was an error while loading. Please reload this page.