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

Refactoring: use NamingHelper inside of Constraint #2992

Open
wants to merge 13 commits into
base: master
from

Conversation

@stokito
Copy link
Contributor

stokito commented Aug 17, 2019

Here is a small refactoring that can improve speed a little bit and removes duplicated code.
There is a lot of code duplication between Constraint and NamingHelper related to generation of constraint name.
I did step by step refactoring and it turned out that Constraint can just reuse the NamingHelper.
I kept an API and all tests passed.
There is a tricky part in #23833fd because the Column class doesn't have an Identifier (IMHO it worth to create one) so we'll create them manually.
Also I worried that the Table.name and Column.name fields can be in uppercase while the NamingHelper always lowercase them before hashing. This may change the generated hash.
But I checked and it turned out that the Table.name and Column.name fields are always in lowercase.

So this PR should be safe to merge.

BTW: the Identifier.compareTo() method compares by getCanonicalName which looks like

public String getCanonicalName() {
	return isQuoted ? text : text.toLowerCase( Locale.ENGLISH );
}

It looks like for columns the text will be always in lowercase so maybe this can be simplified

// they were bound.
Arrays.stream( columnNames )
.sorted()
.forEachOrdered( columnName -> sb.append( "column`" ).append( columnName ).append( '`' ) );

This comment has been minimized.

@NathanQingyangXu

NathanQingyangXu Sep 2, 2020 Contributor

The above code snippet might be slower than traditional approach. It would be great to conduct some JMH benchmark to justify the stream usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.