Skip to content
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

Data Model: Review equals and hashCode methods for persistent objects #162

Closed
tangobravo62 opened this issue Jun 30, 2022 · 2 comments
Closed
Labels
invalid This doesn't seem right

Comments

@tangobravo62
Copy link
Collaborator

For persistent objects the equals method may not work as expected. Most of the classes (with the notable exception of the recently corrected Product and ProcessingFacility) contain the code:

		if (!super.equals(obj))
			return false;

Probably this should read:

		// Same database object
		if (super.equals(obj))
			return true;

The first variant effectively makes comparing loaded objects and transient objects impossible (because the database IDs differ), and if the IDs match, the subsequent attribute-based check is more or less redundant. Presumably a logic like the general if (this == obj) return true; (as in the second variant) is more appropriate.

Since the code worked up to now, a careful review and test is required before performing a general change of the equals methods.

@tangobravo62 tangobravo62 added the invalid This doesn't seem right label Jun 30, 2022
@tangobravo62
Copy link
Collaborator Author

tangobravo62 commented Jul 8, 2022

Extended to cover hashCode, which needs reviewing, too, for two reasons:

  • equals and hashCode should be aligned semantically,
  • The current hashCode implementations seem to be inefficient for the handling of sets, i. e. they do not guarantee a good distribution of objects over hash buckets in the set. This may be a cause for the performance problems in ProductQueryService::executeQuery(), where towards the end of the method a ProductQuery is added to a set of ProductQueries in a product. Some auxiliary products are needed for each and every job step resulting in large sets of ProductQueries, and adding to these sets may take minutes!

@tangobravo62 tangobravo62 changed the title Data Model: Review "equals" methods for persistent objects Data Model: Review equals and hashCode methods for persistent objects Jul 8, 2022
@tangobravo62
Copy link
Collaborator Author

Fixed with commits 263e292, e28079f, 5776763, aa41d31, all included in prosEO 0.9.3.

Has been run successfully since the deployment of prosEO 0.9.3 in November 2022.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant