Skip to content

ContextConfiguration class is package-private in SimpleElasticsearchPersistentEntity #2114

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

Closed
mlyczek opened this issue Mar 18, 2022 · 3 comments · Fixed by #2116
Closed
Labels
type: bug A general bug

Comments

@mlyczek
Copy link

mlyczek commented Mar 18, 2022

In our project we are extending SimpleElasticsearchPersistentEntity to slightly modify the result of getIndexCoordinates() method to add our custom logic for automatically assigning prefix to index name. That's the only modification, we want to use the rest of SimpleElasticsearchPersistentEntity as it is.

But in #1788 a new inner class ContextConfiguration was added to SimpleElasticsearchPersistentEntity with package-private access, which was also added as a parameter to constructor. This means that SimpleElasticsearchPersistentEntity can't be extended outside of org.springframework.data.elasticsearch.core.mapping package despite the fact that SimpleElasticsearchPersistentEntity itself is public. That difference in access modifiers for class and its constructor parameter is a little bit misleading (and also broke our sub-class ;) )

I would like to ask if ContextConfiguration could be made also public? Looking into the code it holds only FieldNamingStrategy which is public and a boolean whether to save type hints into documents. Those are things that are set on mapping context and could be customised there anyway, so I think that it could be made public to allow extending and instantiation of SimpleElasticsearchPersistentEntity possible again outside of its package. Or were there some important reasons for ContextConfiguration being package-private?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 18, 2022
sothawo added a commit that referenced this issue Mar 20, 2022
@sothawo sothawo added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 20, 2022
@sothawo sothawo added this to the 4.4 M4 (2021.2.0) milestone Mar 20, 2022
@sothawo
Copy link
Collaborator

sothawo commented Mar 20, 2022

Basically I consider SimpleElasticsearchPersistentEntity to be an implementation detail of Spring Data Elasticsearch which should be not used directly by an user of the library. But because of the package structure this need to be public.

The problem with having this many public classes in a library is, that when users miss some functionality, they tend to derive from and extend these classes, which in the long run makes it for the maintainers of a library harder to refactor, improve and add functionality to these classes without breaking things for people who derived from these classes.

I'd prefer if there is a problem or a missing functionality to have an issue opened where this problem can be discussed, and instead of having a local workaround it would be preferable to add missing functionality by contributing to Spring Data Elasticsearch .

sothawo added a commit that referenced this issue Mar 21, 2022
…on to public.

Original Pull Request #2116
Closes #2114

(cherry picked from commit 709b4c6)
@sothawo sothawo added type: bug A general bug and removed type: enhancement A general enhancement labels Mar 21, 2022
@sothawo
Copy link
Collaborator

sothawo commented Mar 21, 2022

fixed and backported to 4.3.x branch

@mlyczek
Copy link
Author

mlyczek commented Mar 21, 2022

Thank you @sothawo for the fix.

I totally agree with you that encapsulation is better for libraries and gives maintainers more freedom with future refactorings. Also each public class - as you wrote - could be used by someone (like we used SimpleElasticsearchPersistentEntity in our application) and then every change could brake such usage. It would be huge effort for the team maintaining Spring Data Elasticsearch to think about each and every such class while doing changes and adding new features. And I agree too, that our approach with deriving from SimpleElasticsearchPersistentEntity is not ideal. We will rethink it to make future upgrades of Spring Data Elasticsearch easier for us. Your fix will help us at the moment. As you suggested, I will open a new issue about the prefixing functionality to discuss with you what do you think about such feature in Spring Data Elasticsearch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
3 participants