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.sqlbuilder.dialect;
19  
20  import org.apache.shardingsphere.data.pipeline.core.ingest.record.DataRecord;
21  import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPI;
22  
23  import javax.sql.DataSource;
24  import java.sql.SQLException;
25  import java.util.Collection;
26  import java.util.Optional;
27  
28  /**
29   * Dialect pipeline SQL builder.
30   */
31  public interface DialectPipelineSQLBuilder extends DatabaseTypedSPI {
32      
33      /**
34       * Build create schema SQL.
35       *
36       * @param schemaName schema name
37       * @return built SQL
38       */
39      default Optional<String> buildCreateSchemaSQL(final String schemaName) {
40          return Optional.empty();
41      }
42      
43      /**
44       * Build on duplicate clause of insert SQL.
45       *
46       * @param dataRecord data record
47       * @return built SQL clause
48       */
49      default Optional<String> buildInsertOnDuplicateClause(final DataRecord dataRecord) {
50          return Optional.empty();
51      }
52      
53      /**
54       * Build check empty table SQL.
55       *
56       * @param qualifiedTableName qualified table name
57       * @return built SQL
58       */
59      String buildCheckEmptyTableSQL(String qualifiedTableName);
60      
61      /**
62       * Build estimated count SQL.
63       *
64       * @param qualifiedTableName qualified table name
65       * @return built SQL
66       */
67      default Optional<String> buildEstimatedCountSQL(final String qualifiedTableName) {
68          return Optional.empty();
69      }
70      
71      /**
72       * Build CRC32 SQL.
73       *
74       * @param qualifiedTableName qualified table name
75       * @param columnName column name
76       * @return built SQL
77       */
78      default Optional<String> buildCRC32SQL(final String qualifiedTableName, final String columnName) {
79          return Optional.empty();
80      }
81      
82      /**
83       * Build create table SQLs.
84       *
85       * @param dataSource dataSource
86       * @param schemaName schema name
87       * @param tableName table name
88       * @return built SQLs
89       * @throws SQLException SQL exception
90       */
91      Collection<String> buildCreateTableSQLs(DataSource dataSource, String schemaName, String tableName) throws SQLException;
92      
93      /**
94       * Build query current position SQL.
95       *
96       * @return built SQL
97       */
98      default Optional<String> buildQueryCurrentPositionSQL() {
99          return Optional.empty();
100     }
101 }