|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.seatunnel.connectors.cdc.base.config; |
| 19 | + |
| 20 | +import org.seatunnel.connectors.cdc.base.option.JdbcSourceOptions; |
| 21 | +import org.seatunnel.connectors.cdc.base.option.SourceOptions; |
| 22 | + |
| 23 | +import java.time.Duration; |
| 24 | +import java.util.Arrays; |
| 25 | +import java.util.List; |
| 26 | +import java.util.Properties; |
| 27 | + |
| 28 | +/** A {@link SourceConfig.Factory} to provide {@link SourceConfig} of JDBC data source. */ |
| 29 | +@SuppressWarnings("checkstyle:MagicNumber") |
| 30 | +public abstract class JdbcSourceConfigFactory implements SourceConfig.Factory<JdbcSourceConfig> { |
| 31 | + |
| 32 | + private static final long serialVersionUID = 1L; |
| 33 | + |
| 34 | + protected int port; |
| 35 | + protected String hostname; |
| 36 | + protected String username; |
| 37 | + protected String password; |
| 38 | + protected List<String> databaseList; |
| 39 | + protected List<String> tableList; |
| 40 | + protected StartupConfig startupConfig; |
| 41 | + protected StopConfig stopConfig; |
| 42 | + protected boolean includeSchemaChanges = false; |
| 43 | + protected double distributionFactorUpper = 1000.0d; |
| 44 | + protected double distributionFactorLower = 0.05d; |
| 45 | + protected int splitSize = SourceOptions.SNAPSHOT_SPLIT_SIZE.defaultValue(); |
| 46 | + protected int fetchSize = SourceOptions.SNAPSHOT_FETCH_SIZE.defaultValue(); |
| 47 | + protected String serverTimeZone = JdbcSourceOptions.SERVER_TIME_ZONE.defaultValue(); |
| 48 | + protected Duration connectTimeout = JdbcSourceOptions.CONNECT_TIMEOUT.defaultValue(); |
| 49 | + protected int connectMaxRetries = JdbcSourceOptions.CONNECT_MAX_RETRIES.defaultValue(); |
| 50 | + protected int connectionPoolSize = JdbcSourceOptions.CONNECTION_POOL_SIZE.defaultValue(); |
| 51 | + protected Properties dbzProperties; |
| 52 | + |
| 53 | + /** Integer port number of the database server. */ |
| 54 | + public JdbcSourceConfigFactory hostname(String hostname) { |
| 55 | + this.hostname = hostname; |
| 56 | + return this; |
| 57 | + } |
| 58 | + |
| 59 | + /** Integer port number of the database server. */ |
| 60 | + public JdbcSourceConfigFactory port(int port) { |
| 61 | + this.port = port; |
| 62 | + return this; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * An optional list of regular expressions that match database names to be monitored; any |
| 67 | + * database name not included in the whitelist will be excluded from monitoring. By default all |
| 68 | + * databases will be monitored. |
| 69 | + */ |
| 70 | + public JdbcSourceConfigFactory databaseList(String... databaseList) { |
| 71 | + this.databaseList = Arrays.asList(databaseList); |
| 72 | + return this; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * An optional list of regular expressions that match fully-qualified table identifiers for |
| 77 | + * tables to be monitored; any table not included in the list will be excluded from monitoring. |
| 78 | + * Each identifier is of the form databaseName.tableName. by default the connector will monitor |
| 79 | + * every non-system table in each monitored database. |
| 80 | + */ |
| 81 | + public JdbcSourceConfigFactory tableList(String... tableList) { |
| 82 | + this.tableList = Arrays.asList(tableList); |
| 83 | + return this; |
| 84 | + } |
| 85 | + |
| 86 | + /** Name of the user to use when connecting to the database server. */ |
| 87 | + public JdbcSourceConfigFactory username(String username) { |
| 88 | + this.username = username; |
| 89 | + return this; |
| 90 | + } |
| 91 | + |
| 92 | + /** Password to use when connecting to the database server. */ |
| 93 | + public JdbcSourceConfigFactory password(String password) { |
| 94 | + this.password = password; |
| 95 | + return this; |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * The session time zone in database server, e.g. "America/Los_Angeles". It controls how the |
| 100 | + * TIMESTAMP type converted to STRING. See more |
| 101 | + * https://debezium.io/documentation/reference/1.5/connectors/mysql.html#mysql-temporal-types |
| 102 | + */ |
| 103 | + public JdbcSourceConfigFactory serverTimeZone(String timeZone) { |
| 104 | + this.serverTimeZone = timeZone; |
| 105 | + return this; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * The split size (number of rows) of table snapshot, captured tables are split into multiple |
| 110 | + * splits when read the snapshot of table. |
| 111 | + */ |
| 112 | + public JdbcSourceConfigFactory splitSize(int splitSize) { |
| 113 | + this.splitSize = splitSize; |
| 114 | + return this; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * The upper bound of split key evenly distribution factor, the factor is used to determine |
| 119 | + * whether the table is evenly distribution or not. |
| 120 | + */ |
| 121 | + public JdbcSourceConfigFactory distributionFactorUpper(double distributionFactorUpper) { |
| 122 | + this.distributionFactorUpper = distributionFactorUpper; |
| 123 | + return this; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * The lower bound of split key evenly distribution factor, the factor is used to determine |
| 128 | + * whether the table is evenly distribution or not. |
| 129 | + */ |
| 130 | + public JdbcSourceConfigFactory distributionFactorLower(double distributionFactorLower) { |
| 131 | + this.distributionFactorLower = distributionFactorLower; |
| 132 | + return this; |
| 133 | + } |
| 134 | + |
| 135 | + /** The maximum fetch size for per poll when read table snapshot. */ |
| 136 | + public JdbcSourceConfigFactory fetchSize(int fetchSize) { |
| 137 | + this.fetchSize = fetchSize; |
| 138 | + return this; |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * The maximum time that the connector should wait after trying to connect to the database |
| 143 | + * server before timing out. |
| 144 | + */ |
| 145 | + public JdbcSourceConfigFactory connectTimeout(Duration connectTimeout) { |
| 146 | + this.connectTimeout = connectTimeout; |
| 147 | + return this; |
| 148 | + } |
| 149 | + |
| 150 | + /** The connection pool size. */ |
| 151 | + public JdbcSourceConfigFactory connectionPoolSize(int connectionPoolSize) { |
| 152 | + this.connectionPoolSize = connectionPoolSize; |
| 153 | + return this; |
| 154 | + } |
| 155 | + |
| 156 | + /** The max retry times to get connection. */ |
| 157 | + public JdbcSourceConfigFactory connectMaxRetries(int connectMaxRetries) { |
| 158 | + this.connectMaxRetries = connectMaxRetries; |
| 159 | + return this; |
| 160 | + } |
| 161 | + |
| 162 | + /** Whether the {@link SourceConfig} should output the schema changes or not. */ |
| 163 | + public JdbcSourceConfigFactory includeSchemaChanges(boolean includeSchemaChanges) { |
| 164 | + this.includeSchemaChanges = includeSchemaChanges; |
| 165 | + return this; |
| 166 | + } |
| 167 | + |
| 168 | + /** The Debezium connector properties. For example, "snapshot.mode". */ |
| 169 | + public JdbcSourceConfigFactory debeziumProperties(Properties properties) { |
| 170 | + this.dbzProperties = properties; |
| 171 | + return this; |
| 172 | + } |
| 173 | + |
| 174 | + /** Specifies the startup options. */ |
| 175 | + public JdbcSourceConfigFactory startupOptions(StartupConfig startupConfig) { |
| 176 | + this.startupConfig = startupConfig; |
| 177 | + return this; |
| 178 | + } |
| 179 | + |
| 180 | + @Override |
| 181 | + public abstract JdbcSourceConfig create(int subtask); |
| 182 | +} |
0 commit comments