Skip to content

#421 - Handle modifying query methods returning kotlin.Unit. #422

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

Conversation

ada-waffles
Copy link
Contributor

@ada-waffles ada-waffles commented Jul 30, 2020

Added check for kotlin.Unit to AbstractR2dbcQuery#getExecutionToWrap. This case is essentially equivalent to a return type of Void, but the singleton Unit instance needs to be returned instead of discarding the result entirely.

It was also necessary to add a check to R2dbcQueryMethod#getEntityInformation, as otherwise a PersistentEntity is created for Unit, which leads to a new instance being created via reflection down the pipeline (which is probably not a thing that should happen).

Added AbstractR2dbcQueryUnitTests to test the functionality surrounding the main change. Also added integration tests surrounding modifying query return types.

A couple notes:

  • While I do believe the check added to R2dbcQueryMethod#getEntityInformation is sufficient to prevent a PersistentEntity or new instance of Unit from being created for this particular case, I feel like it might be a good idea to add an additional check for Unit to SimpleTypeHolder, alongside the one for java.lang.*. I'm not sure whether there's a need for a broader kotlin.* check, though.
  • I'm not exactly thrilled about the idea of peppering KotlinDetector.isKotlinPresent() && Unit.class.isAssignableFrom(someClass) all over the place. I don't think a check for Unit belongs in ClassUtils.isPrimitiveOrWrapper as, strictly speaking, Unit is neither of those, but perhaps an isKotlinUnit(Class) method could be added to KotlinDetector.

(I decided to submit this PR without either of those improvements since those are both in other repos and the solution works as-is for now. I'd like to know your thoughts on this PR and those/any other potential improvements before I go submitting any additional PRs elsewhere.)

….Unit.

Added check for kotlin.Unit to AbstractR2dbcQuery#getExecutionToWrap. This case is essentially equivalent to a return type of Void, but the singleton Unit instance needs to be returned instead of discarding the result entirely.

It was also necessary to add a check to R2dbcQueryMethod#getEntityInformation, as otherwise a PersistentEntity is created for Unit, which leads to a new instance being created via reflection down the pipeline (which is probably not a thing that should happen).

Added AbstractR2dbcQueryUnitTests to test the functionality surrounding the main change. Also added integration tests surrounding modifying query return types.
@mp911de
Copy link
Member

mp911de commented Jul 31, 2020

Thanks for submitting a pull request. We had a look and indeed checking for kotlin.Unit to be a simple type (in SimpleTypeHolder in combination with a isVoid(…) method hosted in commons we can really simplify the amount of changes that is needed to make a store module discard results for Flow<Unit> (that is how Kotlin compiles coroutine methods). It's not required to emit Unit.INSTANCE, instead completion without a value leads to the same behavior (at least what we've observed in the tests).

I'm going to merge test and documentation changes from this pull request.

mp911de added a commit that referenced this pull request Jul 31, 2020
…Unit.

We now discard results for suspended query methods if the return type is kotlin.Unit.

Related ticket: DATACMNS-1779

Original pull request: #422.
mp911de pushed a commit that referenced this pull request Jul 31, 2020
Added check for kotlin.Unit to AbstractR2dbcQuery#getExecutionToWrap. This case is essentially equivalent to a return type of Void, but the singleton Unit instance needs to be returned instead of discarding the result entirely.

It was also necessary to add a check to R2dbcQueryMethod#getEntityInformation, as otherwise a PersistentEntity is created for Unit, which leads to a new instance being created via reflection down the pipeline (which is probably not a thing that should happen).

Original pull request: #422.
mp911de added a commit that referenced this pull request Jul 31, 2020
Simplify tests. Use ReflectionUtils.isVoid(…) where possible and simplify isVoid(…) flows.

Original pull request: #422.
mp911de added a commit that referenced this pull request Jul 31, 2020
…Unit.

We now discard results for suspended query methods if the return type is kotlin.Unit.

Related ticket: DATACMNS-1779

Original pull request: #422.
mp911de pushed a commit that referenced this pull request Jul 31, 2020
Added check for kotlin.Unit to AbstractR2dbcQuery#getExecutionToWrap. This case is essentially equivalent to a return type of Void, but the singleton Unit instance needs to be returned instead of discarding the result entirely.

It was also necessary to add a check to R2dbcQueryMethod#getEntityInformation, as otherwise a PersistentEntity is created for Unit, which leads to a new instance being created via reflection down the pipeline (which is probably not a thing that should happen).

Original pull request: #422.
mp911de added a commit that referenced this pull request Jul 31, 2020
Simplify tests. Use ReflectionUtils.isVoid(…) where possible and simplify isVoid(…) flows.

Original pull request: #422.
@mp911de
Copy link
Member

mp911de commented Jul 31, 2020

Thank you for your contribution. That's merged, polished, and backported now.

@mp911de mp911de closed this Jul 31, 2020
@ada-waffles ada-waffles deleted the modifying-queries-returning-unit branch July 31, 2020 12:52
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