Skip to content

Fix ambiguity in the JpaExecutor #2640

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

Merged

Conversation

artembilan
Copy link
Member

Since we can't mutate a provided ParameterSourceFactory with the
provided jpaParameters, we have to reject such a combined
configuration in favor of the advice to configure params on the
provided ParameterSourceFactory

  • Throw IllegalStateException when ParameterSourceFactory and
    jpaParameters are configured together on the JpaExecutor
  • Some refactoring for JpaExecutor to have a consistent code style
  • Fix tests according new logic
  • Document such an ambiguity configuration to avoid confusion

Cherry-pick to 5.0.x

Since we can't mutate a provided `ParameterSourceFactory` with the
provided `jpaParameters`, we have to reject such a combined
configuration in favor of the advice to configure params on the
provided `ParameterSourceFactory`

* Throw `IllegalStateException` when `ParameterSourceFactory` and
`jpaParameters` are configured together on the `JpaExecutor`
* Some refactoring for `JpaExecutor` to have a consistent code style
* Fix tests according new logic
* Document such an ambiguity configuration to avoid confusion

**Cherry-pick to 5.0.x**
}
return parameterSource;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some refactoring for JpaExecutor to have a consistent code style

Major reorganization changes like this should be done in a separate commit - it is virtually impossible to tell what code (if any) has changed). I assume the only difference is the new IllegalStateException. Has anything else changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh... Sorry, I missed the fact that it is going to be hard to review.
The other major change is switch for the enum instead of if...else.

Also I changed the logic in the poll() to this:

else if (requestMessage != null) {
	throw new MessagingException(requestMessage,
					"The Jpa operation returned more than 1 result for expectSingleResult mode.");
}
else {
	throw new MessagingException(
					"The Jpa operation returned more than 1 result for expectSingleResult mode.");
}

Since my IDEA complains that requestMessage may be null. I believe SonarQube has the same concern in code smell section.

Other refactoring was about moving setters before afterPropertiesSet(), reordering methods which use each other, removing this. from methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add @Nullable to that parameter - even if we haven't yet enabled NonNullApi for this package.

assertThat(e.getMessage(),
startsWith("The 'jpaParameters' and 'parameterSourceFactory' are mutually exclusive."));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using assertJ's assertThatThrownBy(() -> executor.afterPropertiesSet()).... for this kind of test.

Otherwise it needs a fail("Expected exception).

* Fix "No BeanFactory" warning in the `JpaExecutorTests`
Object id = this.idExpression.getValue(this.evaluationContext, requestMessage);
Class<?> entityClass = this.entityClass;
if (entityClass == null) {
entityClass = requestMessage.getPayload().getClass();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get an NPE here too.

@garyrussell garyrussell merged commit d981171 into spring-projects:master Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants