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

"rowsExpected" of SqlQuery is not actually used #34512

Open
quaff opened this issue Feb 28, 2025 · 2 comments
Open

"rowsExpected" of SqlQuery is not actually used #34512

quaff opened this issue Feb 28, 2025 · 2 comments
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@quaff
Copy link
Contributor

quaff commented Feb 28, 2025

SqlQuery::setRowsExpected is invoked somewhere, but it make no sense since SqlQuery::getRowsExpected is never invoked anywhere.

We have two options:

  1. use it for query.
  2. deprecate it for removal.

See GH-34502

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 28, 2025
@bclozel
Copy link
Member

bclozel commented Feb 28, 2025

I still don't get it. This is a java-bean style property on this class. While it's not being used in Spring Framework I think it's meant to be used by applications. Do you have any replacement for this to suggest for people using this?

This is not my area of expertise so I'll leave it to other team members to decide on this.

@quaff
Copy link
Contributor Author

quaff commented Feb 28, 2025

Do you have any replacement for this to suggest for people using this?

I believe it's misused here, the intention of rowsExpected is for performance consideration of creating ArrayList, shouldn't rely on it.
If we decide to keep it, then we should use it for initialCapacity of ArrayList.

public List<T> extractData(ResultSet rs) throws SQLException {
List<T> results = (this.rowsExpected > 0 ? new ArrayList<>(this.rowsExpected) : new ArrayList<>());
int rowNum = 0;
while (rs.next()) {
results.add(this.rowMapper.mapRow(rs, rowNum++));
}
return results;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

3 participants