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.infra.database.core.metadata.database;
19  
20  import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType;
21  import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
22  import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPI;
23  import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
24  
25  import java.sql.Connection;
26  import java.sql.SQLException;
27  import java.util.Collections;
28  import java.util.Map;
29  import java.util.Optional;
30  
31  /**
32   * Dialect database meta data.
33   */
34  @SingletonSPI
35  public interface DialectDatabaseMetaData extends DatabaseTypedSPI {
36      
37      /**
38       * Get quote character.
39       *
40       * @return quote character
41       */
42      QuoteCharacter getQuoteCharacter();
43      
44      /**
45       * Get extra data types.
46       *
47       * @return extra data type map
48       */
49      default Map<String, Integer> getExtraDataTypes() {
50          return Collections.emptyMap();
51      }
52      
53      /**
54       * Get default nulls order type.
55       * 
56       * @return default nulls order type
57       */
58      // TODO Reuse java.sql.DatabaseMetaData.nullsAreSortedHigh and java.sql.DatabaseMetaData.nullsAreSortedLow
59      NullsOrderType getDefaultNullsOrderType();
60      
61      /**
62       * Judge whether identifier is reserved word.
63       *
64       * @param identifier identifier to be judged
65       * @return is reserved word or not
66       */
67      // TODO Reuse java.sql.DatabaseMetaData.getSQLKeywords
68      default boolean isReservedWord(final String identifier) {
69          return false;
70      }
71      
72      /**
73       * Is schema feature available.
74       *
75       * @return true or false
76       */
77      default boolean isSchemaAvailable() {
78          return false;
79      }
80      
81      /**
82       * Get schema.
83       *
84       * @param connection connection
85       * @return schema
86       */
87      @SuppressWarnings("ReturnOfNull")
88      default String getSchema(final Connection connection) {
89          try {
90              return connection.getSchema();
91          } catch (final SQLException ignored) {
92              return null;
93          }
94      }
95      
96      /**
97       * Get default schema name.
98       *
99       * @return default schema name
100      */
101     default Optional<String> getDefaultSchema() {
102         return Optional.empty();
103     }
104     
105     /**
106      * Format table name pattern.
107      *
108      * @param tableNamePattern table name pattern
109      * @return formatted table name pattern
110      */
111     default String formatTableNamePattern(final String tableNamePattern) {
112         return tableNamePattern;
113     }
114     
115     /**
116      * Is instance connection available.
117      *
118      * @return available or not
119      */
120     default boolean isInstanceConnectionAvailable() {
121         return false;
122     }
123     
124     /**
125      * Is support three tier storage structure.
126      * 
127      * @return support or not
128      */
129     default boolean isSupportThreeTierStorageStructure() {
130         return false;
131     }
132     
133     /**
134      * Is support global CSN.
135      * 
136      * @return support or not
137      */
138     default boolean isSupportGlobalCSN() {
139         return false;
140     }
141 }