Allow to override the default mappings provided by DsColumnMapping
#187
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.
This PR is a port of #186 to
master.Here is its full description, for convenience.
This PR reproduces and addresses core-java#1536.
Previously, it was not possible to clear columns of some Proto types, since it was not possible to distinguish between meaningful "default values" set to columns on purpose, and those "default values" which in fact signalized of "no value set".
Changing the API of
DsColumnMapping❗ This is a breaking change.
Previously, SPI users could only extend
DsColumnMapping's behavior by overriding this method:It was good enough if one wanted to append their mapping rules. But such an approach did not allow to re-define the existing (framework-default) mapping — since a builder of
ImmutableMapwas passed, preventing from having duplicate keys.Now, the API for SPI users implies overriding another method:
This one allows to return an immutable map of mappings, combining them into the final result, giving priority to those values which were provided by SPI users.
Please see the documentation for
DsColumnMappingfor more details.How to use it
Referring to the original issue, end-users may configure how
Timestamp.getDefaultValue()is stored for some column. In the example below, a Datastore-specificnullis written for such values to the corresponding property of respective DatastoreEntity:Updates to
TestDatastoreStorageFactoryAdditionally, this changeset updates the API of
TestDatastoreStorageFactoryutility to allow access to two features:DatastoreWrappervia public API, which is useful to verify the actual content of Datastore entities written.See
TestDatastoreStorageFactoryfor detail, and have a look at the usage example inDsEntityColumnsTest.The library version is set to
2.0.0-SNAPSHOT.158.