eskabetxe commented on code in PR #209: URL: https://github.com/apache/flink-connector-jdbc/pull/209#discussion_r4106466194
########## flink-connector-jdbc-postgres/src/main/java/org/apache/flink/connector/jdbc/postgres/datastream/connection/PostgresConnectionProvider.java: ########## @@ -0,0 +1,307 @@ +/* + * 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.postgres.datastream.connection; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.connector.jdbc.core.datastream.connection.AbstractConnectionProvider; +import org.apache.flink.connector.jdbc.core.datastream.connection.ConnectionException; +import org.apache.flink.connector.jdbc.core.datastream.connection.ConnectionOptions; +import org.apache.flink.connector.jdbc.core.datastream.connection.ConnectionProvider; +import org.apache.flink.connector.jdbc.core.datastream.source.enumerator.splitter.snapshot.domain.Table; +import org.apache.flink.connector.jdbc.core.datastream.source.enumerator.splitter.snapshot.domain.TableBounds; +import org.apache.flink.connector.jdbc.core.datastream.source.enumerator.splitter.snapshot.domain.TableColumn; +import org.apache.flink.connector.jdbc.core.datastream.source.enumerator.splitter.snapshot.domain.TableId; + +import com.zaxxer.hikari.HikariDataSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Postgres {@link ConnectionProvider} implementation backed by a pooled JDBC connection. Only the + * Postgres-specific table/partition discovery and bound-query building live here; the connection + * lifecycle, pooling, and statement plumbing are inherited from {@link AbstractConnectionProvider}. + */ +@PublicEvolving +public class PostgresConnectionProvider extends AbstractConnectionProvider { + + private static final Logger LOG = LoggerFactory.getLogger(PostgresConnectionProvider.class); + + private static final String TABLE_PARTITIONED_TYPE = "PARTITIONED TABLE"; + private static final Set<String> TABLE_TYPES = + new HashSet<>(Arrays.asList("TABLE", TABLE_PARTITIONED_TYPE)); + private static final Set<String> VIEW_TYPES = + new HashSet<>(Arrays.asList("VIEW", "MATERIALIZED VIEW")); + private static final String[] SUPPORTED_TYPES = + Stream.concat(TABLE_TYPES.stream(), VIEW_TYPES.stream()).toArray(String[]::new); + + private static final int POOL_SIZE = 4; + + private String snapshotId; + private String snapshotTxId; + + public PostgresConnectionProvider(ConnectionOptions jdbcOptions) { + super(jdbcOptions); + } + + private PostgresConnectionProvider(ConnectionOptions jdbcOptions, HikariDataSource pool) { + super(jdbcOptions, pool); + } + + @Override + public ConnectionProvider newInstance() { + return new PostgresConnectionProvider(jdbcOptions, getOrCreatePool()); + } + + @Override + protected int maxPoolSize() { + return POOL_SIZE; + } + + @Override + protected String poolName() { + return "postgres-splitter-pool"; + } + + @Override + protected void onConnectionEstablished() { Review Comment: Fixed -- 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]
