View Javadoc
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.apache.shardingsphere.data.pipeline.core.importer;
19  
20  import lombok.AccessLevel;
21  import lombok.Getter;
22  import lombok.RequiredArgsConstructor;
23  import lombok.ToString;
24  import org.apache.shardingsphere.data.pipeline.api.PipelineDataSourceConfiguration;
25  import org.apache.shardingsphere.data.pipeline.core.ingest.dumper.mapper.TableAndSchemaNameMapper;
26  import org.apache.shardingsphere.data.pipeline.core.ratelimit.JobRateLimitAlgorithm;
27  import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.DialectDatabaseMetaData;
28  import org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry;
29  import org.apache.shardingsphere.infra.metadata.identifier.ShardingSphereIdentifier;
30  
31  import java.util.Collection;
32  import java.util.Collections;
33  import java.util.Map;
34  import java.util.Optional;
35  
36  /**
37   * Importer configuration.
38   */
39  @RequiredArgsConstructor
40  @Getter
41  @ToString(exclude = {"dataSourceConfig", "tableAndSchemaNameMapper"})
42  public final class ImporterConfiguration {
43      
44      private final PipelineDataSourceConfiguration dataSourceConfig;
45      
46      @Getter(AccessLevel.NONE)
47      private final Map<ShardingSphereIdentifier, Collection<String>> tableAndRequiredColumnsMap;
48      
49      private final TableAndSchemaNameMapper tableAndSchemaNameMapper;
50      
51      private final int batchSize;
52      
53      private final JobRateLimitAlgorithm rateLimitAlgorithm;
54      
55      private final int retryTimes;
56      
57      private final int concurrency;
58      
59      /**
60       * Get sharding columns.
61       *
62       * @param logicTableName logic table name
63       * @return sharding columns
64       */
65      public Collection<String> getShardingColumns(final String logicTableName) {
66          return tableAndRequiredColumnsMap.getOrDefault(new ShardingSphereIdentifier(logicTableName), Collections.emptyList());
67      }
68      
69      /**
70       * Find schema name.
71       *
72       * @param logicTableName logic table name
73       * @return schema name
74       */
75      public Optional<String> findSchemaName(final String logicTableName) {
76          DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(dataSourceConfig.getDatabaseType()).getDialectDatabaseMetaData();
77          return dialectDatabaseMetaData.getSchemaOption().isSchemaAvailable() ? Optional.ofNullable(tableAndSchemaNameMapper.getSchemaName(logicTableName)) : Optional.empty();
78      }
79  }