forked from spring-attic/spring-data-aerospike
-
Notifications
You must be signed in to change notification settings - Fork 29
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
FMWK-443 Add configuration flag writeSortedMaps #745
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
945377d
add flag to control writing Maps as TreeMaps
agrgr 681a02d
add flag to control writing Maps as TreeMaps
agrgr 0c57e1e
code format
agrgr d578919
Merge branch 'main' into FMWK-443-flag-writeTreeMaps
agrgr 91875bc
code format, allow null key when writeTreeMaps == false
agrgr d859c63
allow null key when writeTreeMaps == false
agrgr 605e0a1
code format
agrgr e3a7d20
Merge branch 'main' into FMWK-443-flag-writeTreeMaps
agrgr 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 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 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 |
---|---|---|
|
@@ -37,10 +37,12 @@ | |
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.TreeMap; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.aerospike.client.ResultCode.OP_NOT_APPLICABLE; | ||
|
@@ -157,7 +159,12 @@ private void convertToAerospikeWriteData(Object source, AerospikeWriteData data) | |
|
||
private Map<String, Object> convertProperties(TypeInformation<?> type, AerospikePersistentEntity<?> entity, | ||
ConvertingPropertyAccessor<?> accessor, boolean isCustomType) { | ||
Map<String, Object> target = new TreeMap<>(); | ||
Map<String, Object> target; | ||
if (settings.isWriteTreeMaps()) { | ||
target = new TreeMap<>(); | ||
} else { | ||
target = new HashMap<>(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using the ternary operator. |
||
typeMapper.writeType(type, target); | ||
entity.doWithProperties((PropertyHandler<AerospikePersistentProperty>) property -> { | ||
|
||
|
@@ -234,10 +241,16 @@ protected Map<Object, Object> convertMap(final Map<Object, Object> source, final | |
Assert.notNull(source, "Given map must not be null!"); | ||
Assert.notNull(type, "Given type must not be null!"); | ||
|
||
return source.entrySet().stream().collect(TreeMap::new, (m, e) -> { | ||
Supplier<Map<Object, Object>> mapSupplier; | ||
if (settings.isWriteTreeMaps()) { | ||
mapSupplier = TreeMap::new; | ||
} else { | ||
mapSupplier = HashMap::new; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using the ternary operator. |
||
return source.entrySet().stream().collect(mapSupplier, (m, e) -> { | ||
Object key = e.getKey(); | ||
Object value = e.getValue(); | ||
if (key == null) { | ||
if (key == null && settings.isWriteTreeMaps()) { | ||
throw new UnsupportedOperationException("Key of a map cannot be null"); | ||
} | ||
|
||
|
@@ -261,7 +274,7 @@ protected Map<Object, Object> convertMap(final Map<Object, Object> source, final | |
Object convertedValue = getValueToWrite(value, type.getMapValueType()); | ||
if (simpleKey instanceof byte[]) simpleKey = ByteBuffer.wrap((byte[]) simpleKey); | ||
m.put(simpleKey, convertedValue); | ||
}, TreeMap::putAll); | ||
}, Map::putAll); | ||
} | ||
|
||
private Map<String, Object> convertCustomType(Object source, TypeInformation<?> type) { | ||
|
Oops, something went wrong.
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.
Consider renaming to
useSortedMap
.