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.consistencycheck.table.calculator;
19  
20  import lombok.Getter;
21  import lombok.RequiredArgsConstructor;
22  import org.apache.shardingsphere.infra.metadata.caseinsensitive.CaseInsensitiveQualifiedTable;
23  import org.apache.shardingsphere.data.pipeline.core.metadata.model.PipelineColumnMetaData;
24  import org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceWrapper;
25  import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
26  
27  import java.util.List;
28  import java.util.concurrent.atomic.AtomicReference;
29  
30  /**
31   * Single table inventory calculate parameter.
32   */
33  @RequiredArgsConstructor
34  @Getter
35  public final class SingleTableInventoryCalculateParameter {
36      
37      /**
38       * Data source of source side or target side.
39       * Do not close it, it will be reused later.
40       */
41      private final PipelineDataSourceWrapper dataSource;
42      
43      private final CaseInsensitiveQualifiedTable table;
44      
45      private final List<String> columnNames;
46      
47      /**
48       * It could be primary key.
49       * It could be used in order by clause.
50       */
51      private final List<PipelineColumnMetaData> uniqueKeys;
52      
53      private final Object tableCheckPosition;
54      
55      private final AtomicReference<AutoCloseable> calculationContext = new AtomicReference<>();
56      
57      /**
58       * Get database type.
59       *
60       * @return database type
61       */
62      public DatabaseType getDatabaseType() {
63          return dataSource.getDatabaseType();
64      }
65      
66      /**
67       * Get schema name.
68       *
69       * @return schema name
70       */
71      public String getSchemaName() {
72          return table.getSchemaName().toString();
73      }
74      
75      /**
76       * Get logic table name.
77       *
78       * @return logic table name
79       */
80      public String getLogicTableName() {
81          return table.getTableName().toString();
82      }
83      
84      /**
85       * Get first unique key.
86       *
87       * @return first unique key
88       */
89      public PipelineColumnMetaData getFirstUniqueKey() {
90          return uniqueKeys.get(0);
91      }
92      
93      /**
94       * Get calculation context.
95       *
96       * @return calculation context
97       */
98      public AutoCloseable getCalculationContext() {
99          return calculationContext.get();
100     }
101     
102     /**
103      * Set calculation context.
104      *
105      * @param calculationContext calculation context
106      */
107     public void setCalculationContext(final AutoCloseable calculationContext) {
108         this.calculationContext.set(calculationContext);
109     }
110 }