snuyanzin commented on code in PR #78: URL: https://github.com/apache/flink-connector-jdbc/pull/78#discussion_r1535498978
########## flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/source/JdbcSourceBuilder.java: ########## @@ -0,0 +1,253 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.connector.jdbc.source; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.connector.base.DeliveryGuarantee; +import org.apache.flink.connector.jdbc.JdbcConnectionOptions; +import org.apache.flink.connector.jdbc.internal.connection.JdbcConnectionProvider; +import org.apache.flink.connector.jdbc.internal.connection.SimpleJdbcConnectionProvider; +import org.apache.flink.connector.jdbc.source.enumerator.SqlTemplateSplitEnumerator; +import org.apache.flink.connector.jdbc.source.reader.extractor.ResultExtractor; +import org.apache.flink.connector.jdbc.split.JdbcParameterValuesProvider; +import org.apache.flink.types.Row; +import org.apache.flink.util.Preconditions; +import org.apache.flink.util.StringUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nonnull; + +import java.sql.DriverManager; +import java.sql.PreparedStatement; + +import static org.apache.flink.connector.jdbc.source.JdbcSourceOptions.AUTO_COMMIT; +import static org.apache.flink.connector.jdbc.source.JdbcSourceOptions.READER_FETCH_BATCH_SIZE; +import static org.apache.flink.connector.jdbc.source.JdbcSourceOptions.RESULTSET_CONCURRENCY; +import static org.apache.flink.connector.jdbc.source.JdbcSourceOptions.RESULTSET_FETCH_SIZE; +import static org.apache.flink.connector.jdbc.source.JdbcSourceOptions.RESULTSET_TYPE; + +/** + * A tool is used to build {@link JdbcSource} quickly. + * + * <pre><code> + * JdbcSource<Row> source = JdbcSource.<Row>builder() + * .setSql(validSql) + * .setResultExtractor(new RowResultExtractor()) + * .setDBUrl(dbUrl) + * .setDriverName(driverName) + * .setTypeInformation(new TypeHint<Row>() {}.getTypeInfo()) + * .setPassword(password) + * .setUsername(username) + * .build(); + * </code></pre> + * + * <p>In order to query the JDBC source in parallel, you need to provide a parameterized query + * template (i.e. a valid {@link PreparedStatement}) and a {@link JdbcParameterValuesProvider} which + * provides binding values for the query parameters. E.g.: + * + * <pre><code> + * + * Serializable[][] queryParameters = new String[2][1]; + * queryParameters[0] = new String[]{"Kumar"}; + * queryParameters[1] = new String[]{"Tan Ah Teck"}; + * + * JdbcSource<Row> jdbcSource = JdbcSource.<Row>builder() + * .setResultExtractor(new RowResultExtractor()) + * .setTypeInformation(new TypeHint<Row>() {}.getTypeInfo()) + * .setPassword(password) + * .setUsername(username) + * .setDriverName("org.apache.derby.jdbc.EmbeddedDriver") + * .setDBUrl("jdbc:derby:memory:ebookshop") + * .setSql("select * from books WHERE author = ?") + * .setJdbcParameterValuesProvider(new JdbcGenericParameterValuesProvider(queryParameters)) + * .build(); + * </code></pre> + * + * @see Row + * @see JdbcParameterValuesProvider + * @see PreparedStatement + * @see DriverManager + * @see JdbcSource + */ +@PublicEvolving +public class JdbcSourceBuilder<OUT> { + + public static final Logger LOG = LoggerFactory.getLogger(JdbcSourceBuilder.class); + + private final Configuration configuration; + + private int splitReaderFetchBatchSize; + private int resultSetType; + private int resultSetConcurrency; + private int resultSetFetchSize; + // Boolean to distinguish between default value and explicitly set autoCommit mode. + private Boolean autoCommit; + + // TODO It would need a builder method to render after introducing streaming semantic. Review Comment: should we fix this TODO first? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
