Skip to content

DATAJDBC-166 - Allow registration of RowMappers based on result type. #33

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 3 commits into from

Conversation

schauder
Copy link
Contributor

@schauder schauder commented Jan 18, 2018

RowMapper can be configured either via the @query(rowMapperClass = …​.) or by registerign a RowMapperMap bean and register RowMapper per method return type.

            @Bean
            RowMapperMap rowMappers() {
                    return new ConfigurableRowMapperMap() //
                                    .register(Person.class, new PersonRowMapper()) //
                                    .register(Address.class, new AddressRowMapper());
            }

When determining the RowMapper to use for a method the following steps are followed based on the return type of the method:

  1. If the type is a simple type no RowMapper is used. Instead the query is expected to return a single row with a single column and a conversion to the return type is applied to that value.

  2. The entity classes in the RowMapperMap are iterated until one is found that is a superclass or interface of the return type in question. The RowMapper registered for that class is used. Iterating happens in the order of registration, so make sure to register more general types after specific ones.

If applicable wrapper type like collections or Optional are unwrapped. So a return type of Optional will use the type Person in the steps above.

RowMapper can be configured either via the @query(rowMapperClass = …​.) or by registerign a RowMapperMap bean and register RowMapper per method return type.

                @bean
                RowMapperMap rowMappers() {
                        return new ConfigurableRowMapperMap() //
                                        .register(Person.class, new PersonRowMapper()) //
                                        .register(Address.class, new AddressRowMapper());
                }

When determining the RowMapper to use for a method the following steps are followed based on the return type of the method:

1. If the type is a simple type no RowMapper is used. Instead the query is expected to return a single row with a single column and a conversion to the return type is applied to that value.

2. The entity classes in the RowMapperMap are iterated until one is found that is a superclass or interface of the return type in question. The RowMapper registered for that class is used. Iterating happens in the order of registration, so make sure to register more general types after specific ones.

If applicable wrapper type like collections or Optional are unwrapped. So a return type of Optional<Person> will use the type Person in the steps above.
Formatting.
Import order.
Use of AssertJ.
@schauder schauder force-pushed the issue/DATAJDBC-166 branch from 7ba4d16 to 49b99c2 Compare March 19, 2018 11:30
@gregturn
Copy link
Contributor

Resolved via a2b7699

@gregturn gregturn closed this Mar 21, 2018
@gregturn gregturn deleted the issue/DATAJDBC-166 branch March 21, 2018 16:47
mp911de added a commit that referenced this pull request Feb 21, 2022
DatabaseClient now no longer exposes the exchange() method but rather provides map(…) and then(…) methods.
Calling map(…) extracts values from tabular results by propagating the mapping function to Result.map(…).
then() allows statement execution without returning the result propagating only completion and error signals.

Original pull request: #33.
mp911de pushed a commit that referenced this pull request Feb 21, 2022
Formatting, JavaDoc, issue comments on `@Test` annotations.
Removed some dead code.

Original pull request: #33.
mp911de added a commit that referenced this pull request Feb 21, 2022
Remove unused code from AbstractDatabaseClientIntegrationTests.
Use literal null instead of code null for consistency.

Original pull request: #33.
mp911de added a commit that referenced this pull request Feb 21, 2022
Move retrieval methods from FetchSpec into RowsFetchSpec and UpdatedRowsFetchSpec.

map(…) now returns RowsFetchSpec to not expose updated rows count as mapped results are consumed as objects.

Original pull request: #33.
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