-
Notifications
You must be signed in to change notification settings - Fork 0
FINC-1118 Support jOOQ sort Field<?> mappings
#55
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
Open
ThoSap
wants to merge
5
commits into
main
Choose a base branch
from
finc-1118-toolbox-jooq-sort-mappings-field-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
76c6b9b
put `@NullMarked` closest to the target
ThoSap cecc45e
add jOOQ dependency and support jOOQ Field in SortMappings
ThoSap fd061b6
add jOOQ as an optional dependency and support jOOQ Field in SortMapp…
ThoSap c0c6481
add jOOQ as an optional dependency and support jOOQ Field in SortMapp…
ThoSap 55596f8
accidentally committed local version 2.2.1-SNAPSHOT
ThoSap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/it/aboutbits/springboot/toolbox/persistence/SortMappingsForJooq.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package it.aboutbits.springboot.toolbox.persistence; | ||
|
|
||
| import it.aboutbits.springboot.toolbox.parameter.SortParameter; | ||
| import org.jooq.Field; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| @NullMarked | ||
| public final class SortMappingsForJooq<T extends Enum<?> & SortParameter.Definition> extends SortMappings<T> { | ||
| private SortMappingsForJooq() { | ||
| super(); | ||
| } | ||
|
|
||
| public static <T extends Enum<?> & SortParameter.Definition> Mapping<T> map( | ||
| T property, | ||
| Field<?> column | ||
| ) { | ||
| return new Mapping<>(property, column); | ||
| } | ||
|
|
||
| @SafeVarargs | ||
| public static <T extends Enum<?> & SortParameter.Definition> SortMappingsForJooq<T> of( | ||
| Mapping<T>... mappings | ||
| ) { | ||
| var sortMappings = new SortMappingsForJooq<T>(); | ||
|
|
||
| for (var mapping : mappings) { | ||
| sortMappings.put(mapping.property(), mapping.column()); | ||
| } | ||
|
|
||
| return sortMappings; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/it/aboutbits/springboot/toolbox/persistence/SortMappingsForJooqTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package it.aboutbits.springboot.toolbox.persistence; | ||
|
|
||
| import it.aboutbits.springboot.toolbox.parameter.SortParameter; | ||
| import org.jooq.impl.DSL; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.data.domain.Sort; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @NullMarked | ||
| class SortMappingsForJooqTest { | ||
| private enum ESort implements SortParameter.Definition { | ||
| Property1, | ||
| Property2 | ||
| } | ||
|
|
||
| @Test | ||
| void map_shouldReturnMappingWithFieldObject() { | ||
| var field = DSL.field("my_column"); | ||
| var mapping = SortMappingsForJooq.map(ESort.Property1, field); | ||
|
|
||
| assertThat(mapping.property()).isEqualTo(ESort.Property1); | ||
| assertThat(mapping.column()).isEqualTo(field); | ||
| } | ||
|
|
||
| @Test | ||
| void of_shouldCreateSortMappingsForJooq() { | ||
| var field1 = DSL.field("col1"); | ||
| var mappings = SortMappingsForJooq.of( | ||
| SortMappingsForJooq.map(ESort.Property1, field1) | ||
| ); | ||
|
|
||
| assertThat(mappings).isInstanceOf(SortMappingsForJooq.class); | ||
| assertThat(mappings.get(ESort.Property1)).isEqualTo(field1); | ||
| } | ||
|
|
||
| @Test | ||
| void buildSpringSortWithJooqFields() { | ||
| var mappings = SortMappingsForJooq.of( | ||
| SortMappingsForJooq.map(ESort.Property1, DSL.field("my_col")) | ||
| ); | ||
| var sortParameter = SortParameter.by(ESort.Property1, Sort.Direction.DESC); | ||
|
|
||
| var result = sortParameter.buildSort(mappings); | ||
|
|
||
| var order = result.getOrderFor("my_col"); | ||
| assertThat(order).isNotNull(); | ||
| assertThat(Objects.requireNonNull(order).getDirection()).isEqualTo(Sort.Direction.DESC); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this class is not used in a non jOOQ BE project, the project will just compile fine.