Skip to content

Conversation

@ArtDu
Copy link
Contributor

@ArtDu ArtDu commented Apr 3, 2023

I haven't forgotten about:

  • Tests
  • Changelog
  • Documentation
  • Commit messages comply with the guideline
  • Cleanup the code for review. See checklist

Related issues:
Closes #123

Comment on lines +193 to +200
metadata = {
{name='testId', type=''},
{name='testBoolean', type=''},
{name='testString', type=''},
{name='testInteger', type=''},
{name='testDouble', type=''}
},
rows = { { nil, true, "abc", 123, 1.23 } }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We expect that crud response either contains metadata or it's not a crud response

@ArtDu ArtDu marked this pull request as ready for review April 13, 2023 12:55
vasilevichra
vasilevichra previously approved these changes Apr 14, 2023

private <T> CallResultMapper<T, SingleValueCallResult<T>>
withDefaultSingleValueMapper(MessagePackMapper customMapper,
Class<T> entityClass) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems that entityClass is now missing. Aren't there any compiler warnings visible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't used properly in the cartridge-java part, we never get real entityClass. It was used as a stub for the target class which isn't used anywhere except tuple value mapping. This is what I was talking about implying that the mapping functionality is overloaded

Copy link
Collaborator

@akudiyar akudiyar Apr 28, 2023

Choose a reason for hiding this comment

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

No, its purpose is broader. It allows the Java compiler to have a certain assumption about the expression type at compile time. That's the limitation of Java, but it helps t avoid some runtime errors earlier, or you will get a clearer error message. Also it saves you from further spurious unchecked casts at different places that just make the readability worse.

Copy link
Contributor Author

@ArtDu ArtDu May 2, 2023

Choose a reason for hiding this comment

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

You're right. It's w/a to get all types by one Mapper

<T> CompletableFuture<T> callForSingleResult(
        String functionName,
        List<?> arguments,
        CallResultMapper<T, SingleValueCallResult<T>> resultMapper)
        throws TarantoolClientException;

We have a generic T in all methods with callForSingleResult in the result mapper. It forces us to make a specific class that we should obtain, only this one. That obliges us to have a container for results like TarantoolResult. And I just used Object as a generic type for further values except for the first layer which is SingleValueCallResult

I agree that it's not good way. Maybe we can use MessagePackValueMapper as a mapper for generic calls, but with MessagePackValueMapper you should parse singleValue result every time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created PR about changing this clunky problem tarantool/cartridge-java#391

With this one you can use methods with CallResultMapper<T, SingleValueCallResult<T>> resultMapper in a method signature and so you'll get the result, not SingleValueResult class

CallResultMapper<Object, SingleValueCallResult<Object>> callReturnMapper = factory.createMapper(valueMapper)
            .buildSingleValueResultMapper(
                factory.createMapper(valueMapper)
                    .withArrayValueToTarantoolTupleResultConverter()
                    .withRowsMetadataToTarantoolTupleResultConverter()
                    .buildCallResultMapper()
            );

With this one you'll get a SingleValueResult as return of methods

MessagePackValueMapper returnMapper = factory.createMapper(valueMapper)
           .withSingleValueConverter(
               factory.createMapper(valueMapper)
                   .withArrayValueToTarantoolTupleResultConverter()
                   .withRowsMetadataToTarantoolTupleResultConverter()
                   .buildCallResultMapper()
           ).buildCallResultMapper();

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like that we have raw Objects here. One of the targets of our driver API is to avoid any casts and raw Object usage whenever possible. And we shouldn't try to minimize the conversion code here in the SpringData module, if that worsens the user-facing API.

@ArtDu ArtDu requested a review from akudiyar April 24, 2023 20:54

private <T> CallResultMapper<T, SingleValueCallResult<T>>
withDefaultSingleValueMapper(MessagePackMapper customMapper,
Class<T> entityClass) {
Copy link
Collaborator

@akudiyar akudiyar Apr 28, 2023

Choose a reason for hiding this comment

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

No, its purpose is broader. It allows the Java compiler to have a certain assumption about the expression type at compile time. That's the limitation of Java, but it helps t avoid some runtime errors earlier, or you will get a clearer error message. Also it saves you from further spurious unchecked casts at different places that just make the readability worse.

.withRowsMetadataToTarantoolTupleResultConverter()
.buildCallResultMapper(
DefaultMessagePackMapperFactory.getInstance().emptyMapper()))
.buildCallResultMapper(DefaultMessagePackMapperFactory.getInstance().emptyMapper());
Copy link
Collaborator

Choose a reason for hiding this comment

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

That empty mapper here looks a bit confusing. Seems that it should be either a default mapper, or no mapper parameter at all (the empty mapper as a default value in the method).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is confusing logic. I suggest fixing it after #124 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a ticket to the driver at least?

MessagePackMapper customMapper = getDefaultComplexTypesMapper();
registerTupleResultMapper(customMapper, spaceMetadata);
return withDefaultSingleValueMapper(customMapper, entityClass);
getAutoResultMapper(Optional<TarantoolSpaceMetadata> spaceMetadata) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like that we could combine this builder sequence with the same one above and make a factory method that accepts a single mapper (that's the only difference it seems).

…MappingTarantoolReadConverter.java

Co-authored-by: Alexey Kuzin <[email protected]>
Copy link
Collaborator

@akudiyar akudiyar left a comment

Choose a reason for hiding this comment

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

I have a question about the used concrete type

@ArtDu ArtDu requested a review from akudiyar June 1, 2023 22:48
Copy link
Collaborator

@akudiyar akudiyar left a comment

Choose a reason for hiding this comment

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

The blocker PR tarantool/cartridge-java#391 is merged now, let's make a new release and update this PR

Copy link
Collaborator

@akudiyar akudiyar left a comment

Choose a reason for hiding this comment

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

LGTM

@akudiyar akudiyar merged commit b462c98 into master Jun 13, 2023
@akudiyar akudiyar deleted the sync branch June 13, 2023 21:30
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.

Synchronise cartridge-java and actual code

3 participants