Skip to content

Add TarantoolTupleResultMapper factory #322

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

Merged
merged 1 commit into from
Dec 23, 2022
Merged

Conversation

ArtDu
Copy link
Contributor

@ArtDu ArtDu commented Dec 12, 2022

We need it to create universal mapper that can parse crud and box responses.
Also with this factory we can't see inherited methods.

I haven't forgotten about:

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

Related issues:
Closes #321

@ArtDu ArtDu requested a review from akudiyar December 12, 2022 16:57
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.

Looks OK, but Javadocs are missing

@ArtDu ArtDu force-pushed the refactor/new/factories branch 4 times, most recently from 69533da to 4ce4c42 Compare December 15, 2022 16:00
@ArtDu ArtDu requested a review from akudiyar December 15, 2022 16:10
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.

One important test kind that is missing - we need to test that several consequent and concurrent invocations of TarantoolTupleResultMapperFactory methods do not cause any problems with wrong mapper stacks. That means (until we haven't implemented any smart caching) a new isolated mapping stack should be created for each request. Otherwise, we immediately will have serious problems that are hard to debug

@@ -111,6 +115,7 @@ public AbstractTarantoolClient(TarantoolClientConfig config, TarantoolConnection

this.config = config;
this.mapperFactoryFactory = new ResultMapperFactoryFactoryImpl();
this.resultMapperFactory = TarantoolTupleResultMapperFactoryImpl.getInstance();
Copy link
Collaborator

Choose a reason for hiding this comment

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

It does not look right to put a concrete tuple factory implementation in the abstract client, given that the Tarantool tuple class is a generic parameter. I believe it should be instantiated in the corresponding final class or some intermediate one. In the root abstract class, we may put an abstract method for it with a generic type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved factory to ResultMapperFactoryFactory

@@ -491,4 +492,6 @@ <T, R extends List<T>> CompletableFuture<R> callForMultiResult(
* @return result mapper factory instances factory instance
*/
ResultMapperFactoryFactory getResultMapperFactoryFactory();

TarantoolTupleResultMapperFactory getTarantoolTupleResultMapperFactory();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Javadoc is missing

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at this again, I strongly believe that we need to have this factory method in the ResultMapperFactoryFactory. Otherwise it looks like an orphan

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at this again, I strongly believe that we need to have this factory method in the ResultMapperFactoryFactory. Otherwise it looks like an orphan

I don't want to see this, it's awful

client.getResultMapperFactoryFactory().getTarantoolTupleResultMapperFactory()
            .withSingleValueRowsMetadataToTarantoolTupleResultMapper

Copy link
Collaborator

@akudiyar akudiyar Dec 19, 2022

Choose a reason for hiding this comment

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

C'est la vie \o/

It's not used everyday, so an orphan method in API will confuse the users more. It's a classical leaking abstraction.

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's not used everyday, so an orphan method in API will confuse the users more

It's just a shortcut for main mappers. But I'll move if you don't change your mind about using it here where is it now. I need it to futher autoTupleConverter

In my opinion, it's hard to use from client.getResultMapperFactoryFactory().* cause there are so many methods. It's so difficult for people that I suggeseted to use these methods. Every time I started to think how does these ugly structures. And the sum thing that these structure don't give a perfomance in comparing to http because we have a lot of problems with those.

@Elishtar What do you think about it? I think we need third opinion

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are leaking a concrete TarantoolTuple implementation to the TarantoolClient interface which has this type as a generic type. We should not do this by any chance. It harms more than the "economy" of symbols in one place or the "ugliness" of this factory name, That's the complexity of the source object that we are modeling and we need to get it away from the users by providing non-confusing and clear structures to them.

Copy link
Collaborator

@akudiyar akudiyar Dec 21, 2022

Choose a reason for hiding this comment

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

It's better to remove the method getTarantoolTupleResultMapperFactory() itself and use this factory as a singleton than to add a new method that is necessary only for internal purposes. So I'd rather vote for removing getTarantoolTupleResultMapperFactory() from the TarantoolClient interface instead

Copy link
Contributor

Choose a reason for hiding this comment

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

@akudiyar for me ResultMapperFactoryFactory looks very strange and over complexity, maybe better use few different factories?

Copy link
Collaborator

@akudiyar akudiyar Dec 22, 2022

Choose a reason for hiding this comment

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

@Elishtar the initial goal of this factory was to provide helper factory methods for the common cases like this one (a concrete tuple implementation + a concrete result type). Eventually these factory methods were intended to return singleton references. Changing this to individual factory/singleton variable instantiations may work, but to me looks like less readable and harder for tracking and altering the places of factories usages.

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 discussed that we move this factory to ResultMapperFactoryFactory now and that we should discuss API in more detailed later

@ArtDu ArtDu requested a review from Elishtar December 20, 2022 15:15
@ArtDu ArtDu force-pushed the refactor/new/factories branch from 4ce4c42 to 405e91e Compare December 23, 2022 10:42
@ArtDu ArtDu requested a review from akudiyar December 23, 2022 10:46
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

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.

Add simple to use TarantoolTupleMapper factory
3 participants