Skip to content

DATACMNS-1762 - Support Optional wrapping for projection getters #459

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

Closed
wants to merge 7 commits into from

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Jul 16, 2020

We now support nullable wrappers for projection interfaces. Getters are inspected whether their return type is a supported nullable wrapper. If so, then the value can be wrapped into that type. Null values default in that case to their corresponding empty wrapper representation.

class Customer {

	Long id;
	String firstname, lastname;
	Address address;
}

interface CustomerProjection {

	Optional<String> getFirstname();

	Optional<AddressExcerpt> getAddress();
}


Customer customer = new Customer();
customer.firstname = "Walter";

CustomerProjection projection = …;

assertThat(projection.getFirstname()).hasValue("Walter");


customer.firstname = null;
assertThat(projection.getFirstname()).isEmpty();

Also, extracted NullableWrapperConverters from QueryExecutionConverters and removed ReactiveWrappers from QueryExecutionConverters .


We should reconsider the package for NullableWrapperConverters as further extensions (Iterable -> Streamable) might be future enhancements.

Related ticket: DATACMNS-1762
Previous pull request: #457.

mp911de and others added 6 commits July 16, 2020 10:30
…ionConverters.

ReactiveWrappers doesn't belong in there in the first place so we're removing ReactiveWrappers support from QueryExecutionConverters so ReactiveWrappers is used from parts that need to be reactive-aware.
…Converters.

Nullable wrappers such as Java 8 Optional, Guava Optional, Scala Option and Vavr Option are now handled in NullableWrapperConverters and are no longer coupled to QueryExecutionConverters so that this functionality can be reused.
We now support nullable wrappers for projection interfaces. Getters are inspected whether their return type is a supported nullable wrapper. If so, then the value can be wrapped into that type. Null values default in that case to their corresponding empty wrapper representation.
}

@Test // DATACMNS-1762
void supportsOptionalBackedByOptional() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting test! Did not think about this use case 👍

}
}

public static final class WrapperType {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably an exact copy of QueryExecutionConverters.WrapperType. Shouldn't this be refactored to use the same class? Or is that not possible for backwards-compatibility reasons?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't really want to expose this type so it makes sense to make it package-private. We'd rather go for a duplication really as nullable wrappers and result wrappers (Page, Seq, CompletableFuture) touch different concepts which follow a similar structure but they aren't the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, clear! Looking forward to using this in a future release :-)

@wimdeblauwe
Copy link
Contributor

Thanks for this @mp911de ! I have added 2 remarks above from having a look at what you have done. I could not have done it myself, so I'm very grateful for this 🙇

christophstrobl pushed a commit that referenced this pull request Sep 25, 2020
…ionConverters.

ReactiveWrappers doesn't belong in there in the first place so we're removing ReactiveWrappers support from QueryExecutionConverters so ReactiveWrappers is used from parts that need to be reactive-aware.

Original Pull Request: #459
christophstrobl pushed a commit that referenced this pull request Sep 25, 2020
…Converters.

Nullable wrappers such as Java 8 Optional, Guava Optional, Scala Option and Vavr Option are now handled in NullableWrapperConverters and are no longer coupled to QueryExecutionConverters so that this functionality can be reused.

Original Pull Request: #459
christophstrobl pushed a commit that referenced this pull request Sep 25, 2020
We now support nullable wrappers for projection interfaces. Getters are inspected whether their return type is a supported nullable wrapper. If so, then the value can be wrapped into that type. Null values default in that case to their corresponding empty wrapper representation.

Original Pull Request: #459
christophstrobl pushed a commit that referenced this pull request Sep 25, 2020
christophstrobl added a commit that referenced this pull request Sep 25, 2020
Update JavaDoc, remove unused imports and reduce method visibility.

Original Pull Request: #459
@christophstrobl christophstrobl deleted the issue/DATACMNS-1762 branch September 25, 2020 06:18
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.

3 participants