This is an automated email from the ASF dual-hosted git repository.
shunping pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new 55febcbf6fc Add javadoc to JdbcIO.PreparedStatementSetter (#35796)
55febcbf6fc is described below
commit 55febcbf6fc142d373ff97a29466856ca4f7e26a
Author: Yi Hu <[email protected]>
AuthorDate: Fri Aug 8 16:44:49 2025 -0400
Add javadoc to JdbcIO.PreparedStatementSetter (#35796)
* Add comments to JdbcIO.PreparedStatementSetter
* Fix javadoc to include ReadAll scenario
* Add javadoc for ReadAll.withParameterSetter
* Clarify JdbcIO.readAll do not support reading from multiple tables
* Apply suggestions from code review
Co-authored-by: gemini-code-assist[bot]
<176961590+gemini-code-assist[bot]@users.noreply.github.com>
---------
Co-authored-by: gemini-code-assist[bot]
<176961590+gemini-code-assist[bot]@users.noreply.github.com>
---
.../java/org/apache/beam/sdk/io/jdbc/JdbcIO.java | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git
a/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
b/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
index 113d14dd238..f143e43d2b5 100644
--- a/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
+++ b/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
@@ -355,6 +355,10 @@ public class JdbcIO {
* Like {@link #read}, but executes multiple instances of the query
substituting each element of a
* {@link PCollection} as query parameters.
*
+ * <p>The substitution is configured via {@link
ReadAll#withParameterSetter}. Substitutions
+ * allowed by the JDBC API's {@link PreparedStatement} are supported. In
particular, this does not
+ * support parameterizing the table name to read from a different table for
each input element.
+ *
* @param <ParameterT> Type of the data representing query parameters.
* @param <OutputT> Type of the data to be read.
*/
@@ -1175,6 +1179,18 @@ public class JdbcIO {
return toBuilder().setQuery(query).build();
}
+ /**
+ * Sets the {@link PreparedStatementSetter} to set the parameters of the
query for each input
+ * element.
+ *
+ * <p>For example,
+ *
+ * <pre>{@code
+ * JdbcIO.<String, Row>readAll()
+ * .withQuery("select * from table where field = ?")
+ * .withParameterSetter((element, preparedStatement) ->
preparedStatement.setString(1, element))
+ * }</pre>
+ */
public ReadAll<ParameterT, OutputT> withParameterSetter(
PreparedStatementSetter<ParameterT> parameterSetter) {
checkArgumentNotNull(
@@ -1830,8 +1846,8 @@ public class JdbcIO {
}
/**
- * An interface used by the JdbcIO Write to set the parameters of the {@link
PreparedStatement}
- * used to setParameters into the database.
+ * An interface used by the JdbcIO {@link ReadAll} and {@link Write} to set
the parameters of the
+ * {@link PreparedStatement} used to setParameters into the database.
*/
@FunctionalInterface
public interface PreparedStatementSetter<T> extends Serializable {