Skip to content

Commit 55febcb

Browse files
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>
1 parent f30aa96 commit 55febcb

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

  • sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc

sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ public static ReadRows readRows() {
355355
* Like {@link #read}, but executes multiple instances of the query substituting each element of a
356356
* {@link PCollection} as query parameters.
357357
*
358+
* <p>The substitution is configured via {@link ReadAll#withParameterSetter}. Substitutions
359+
* allowed by the JDBC API's {@link PreparedStatement} are supported. In particular, this does not
360+
* support parameterizing the table name to read from a different table for each input element.
361+
*
358362
* @param <ParameterT> Type of the data representing query parameters.
359363
* @param <OutputT> Type of the data to be read.
360364
*/
@@ -1175,6 +1179,18 @@ public ReadAll<ParameterT, OutputT> withQuery(ValueProvider<String> query) {
11751179
return toBuilder().setQuery(query).build();
11761180
}
11771181

1182+
/**
1183+
* Sets the {@link PreparedStatementSetter} to set the parameters of the query for each input
1184+
* element.
1185+
*
1186+
* <p>For example,
1187+
*
1188+
* <pre>{@code
1189+
* JdbcIO.<String, Row>readAll()
1190+
* .withQuery("select * from table where field = ?")
1191+
* .withParameterSetter((element, preparedStatement) -> preparedStatement.setString(1, element))
1192+
* }</pre>
1193+
*/
11781194
public ReadAll<ParameterT, OutputT> withParameterSetter(
11791195
PreparedStatementSetter<ParameterT> parameterSetter) {
11801196
checkArgumentNotNull(
@@ -1830,8 +1846,8 @@ public static RetryConfiguration create(
18301846
}
18311847

18321848
/**
1833-
* An interface used by the JdbcIO Write to set the parameters of the {@link PreparedStatement}
1834-
* used to setParameters into the database.
1849+
* An interface used by the JdbcIO {@link ReadAll} and {@link Write} to set the parameters of the
1850+
* {@link PreparedStatement} used to setParameters into the database.
18351851
*/
18361852
@FunctionalInterface
18371853
public interface PreparedStatementSetter<T> extends Serializable {

0 commit comments

Comments
 (0)