From f55cf7ffd6542bcf13c585083798d0692bc475c6 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Thu, 27 Feb 2025 11:02:59 +0800 Subject: [PATCH] Deprecate unused "rowsExpected" of SqlQuery for removal Fix GH-34512 Signed-off-by: Yanming Zhou --- .../java/org/springframework/jdbc/object/SqlFunction.java | 6 +----- .../main/java/org/springframework/jdbc/object/SqlQuery.java | 4 ++++ .../java/org/springframework/jdbc/object/SqlQueryTests.java | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java index c9be8bd09e75..97bc6df719f5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,7 +65,6 @@ public class SqlFunction extends MappingSqlQuery { * @see #compile */ public SqlFunction() { - setRowsExpected(1); } /** @@ -75,7 +74,6 @@ public SqlFunction() { * @param sql the SQL to execute */ public SqlFunction(DataSource ds, String sql) { - setRowsExpected(1); setDataSource(ds); setSql(sql); } @@ -89,7 +87,6 @@ public SqlFunction(DataSource ds, String sql) { * @see java.sql.Types */ public SqlFunction(DataSource ds, String sql, int[] types) { - setRowsExpected(1); setDataSource(ds); setSql(sql); setTypes(types); @@ -106,7 +103,6 @@ public SqlFunction(DataSource ds, String sql, int[] types) { * @see java.sql.Types */ public SqlFunction(DataSource ds, String sql, int[] types, Class resultType) { - setRowsExpected(1); setDataSource(ds); setSql(sql); setTypes(types); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlQuery.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlQuery.java index 88084cc62d4a..ef39a4bff5c5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlQuery.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlQuery.java @@ -85,14 +85,18 @@ public SqlQuery(DataSource ds, String sql) { * Set the number of rows expected. *

This can be used to ensure efficient storage of results. The * default behavior is not to expect any specific number of rows. + * @deprecated since 6.2.4 with no replacement; it's for internal use only */ + @Deprecated(since = "6.2.4", forRemoval = true) public void setRowsExpected(int rowsExpected) { this.rowsExpected = rowsExpected; } /** * Get the number of rows expected. + * @deprecated since 6.2.4 with no replacement; it's for internal use only */ + @Deprecated(since = "6.2.4", forRemoval = true) public int getRowsExpected() { return this.rowsExpected; } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java index 2af6f993223a..6cb33c25738c 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -168,7 +168,6 @@ void testStringQueryWithResults() throws Exception { given(resultSet.next()).willReturn(true, true, true, false); given(resultSet.getString(1)).willReturn(dbResults[0], dbResults[1], dbResults[2]); StringQuery query = new StringQuery(dataSource, SELECT_FORENAME); - query.setRowsExpected(3); String[] results = query.run(); assertThat(results).isEqualTo(dbResults); verify(connection).prepareStatement(SELECT_FORENAME);