Skip to content

Code Clean-Up and Refactoring Suggestions in JpaMetamodel #3555

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
arefbehboudi opened this issue Aug 4, 2024 · 4 comments
Closed

Code Clean-Up and Refactoring Suggestions in JpaMetamodel #3555

arefbehboudi opened this issue Aug 4, 2024 · 4 comments
Assignees
Labels
status: feedback-provided Feedback has been provided type: task A general task

Comments

@arefbehboudi
Copy link
Contributor

arefbehboudi commented Aug 4, 2024

I have been reviewing the code and noticed some areas in JpaMetamodel where small improvements can be made to enhance code readability and maintainability. Here are my suggestions:

  1. These fields can be defined as final fields:
               private Lazy<Collection<Class<?>>> managedTypes;
	       private Lazy<Collection<Class<?>>> jpaEmbeddables;
  1. In some code, lambda expressions can be replaced with method references, for example:
		this.managedTypes = Lazy.of(() -> metamodel.getManagedTypes().stream()
				.map(ManagedType::getJavaType) 
				.filter(it -> it != null)  // It can be repalced with lambda expressions
				.collect(StreamUtils.toUnmodifiableSet()));

		this.jpaEmbeddables = Lazy.of(() -> metamodel.getEmbeddables().stream()
				.map(ManagedType::getJavaType)
				.filter(it -> it != null)  // It can be repalced with lambda expressions
				.filter(it -> AnnotatedElementUtils.isAnnotated(it, Embeddable.class))
				.collect(StreamUtils.toUnmodifiableSet()));

		return metamodel.getEntities().stream()
				.filter(it -> entity.equals(it.getJavaType()))
				.findFirst()
				.flatMap(it -> getSingularIdAttribute(it)) // It can be repalced with lambda expressions
				.filter(it -> it.getJavaType().equals(attributeType))
				.map(it -> it.getName().equals(name))
				.orElse(false);
@christophstrobl
Copy link
Member

Thank you @arefbehboudi for bringing this up. Do you want to submit a PR for this change?

@christophstrobl christophstrobl added type: task A general task status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 5, 2024
@arefbehboudi
Copy link
Contributor Author

Yes, I'd be happy to submit a PR for this change. I'll start working on it and will notify you once it's ready.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 5, 2024
@arefbehboudi
Copy link
Contributor Author

Hi @christophstrobl,
I created a pull request; I would appreciate it if you could take a look at it.

@christophstrobl
Copy link
Member

thank you @arefbehboudi - it's on the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided type: task A general task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants