001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jdbc.core.metadata; 018 019import java.sql.DatabaseMetaData; 020import java.sql.SQLException; 021import java.util.List; 022 023import org.springframework.lang.Nullable; 024 025/** 026 * Interface specifying the API to be implemented by a class providing table meta-data. 027 * This is intended for internal use by the Simple JDBC classes. 028 * 029 * @author Thomas Risberg 030 * @since 2.5 031 */ 032public interface TableMetaDataProvider { 033 034 /** 035 * Initialize using the database meta-data provided. 036 * @param databaseMetaData used to retrieve database specific information 037 * @throws SQLException in case of initialization failure 038 */ 039 void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException; 040 041 /** 042 * Initialize using provided database meta-data, table and column information. 043 * This initialization can be turned off by specifying that column meta-data should not be used. 044 * @param databaseMetaData used to retrieve database specific information 045 * @param catalogName name of catalog to use (or {@code null} if none) 046 * @param schemaName name of schema name to use (or {@code null} if none) 047 * @param tableName name of the table 048 * @throws SQLException in case of initialization failure 049 */ 050 void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, @Nullable String catalogName, 051 @Nullable String schemaName, @Nullable String tableName) throws SQLException; 052 053 /** 054 * Get the table name formatted based on meta-data information. 055 * This could include altering the case. 056 */ 057 @Nullable 058 String tableNameToUse(@Nullable String tableName); 059 060 /** 061 * Get the catalog name formatted based on meta-data information. 062 * This could include altering the case. 063 */ 064 @Nullable 065 String catalogNameToUse(@Nullable String catalogName); 066 067 /** 068 * Get the schema name formatted based on meta-data information. 069 * This could include altering the case. 070 */ 071 @Nullable 072 String schemaNameToUse(@Nullable String schemaName); 073 074 /** 075 * Provide any modification of the catalog name passed in to match the meta-data currently used. 076 * The returned value will be used for meta-data lookups. 077 * This could include altering the case used or providing a base catalog if none is provided. 078 */ 079 @Nullable 080 String metaDataCatalogNameToUse(@Nullable String catalogName) ; 081 082 /** 083 * Provide any modification of the schema name passed in to match the meta-data currently used. 084 * The returned value will be used for meta-data lookups. 085 * This could include altering the case used or providing a base schema if none is provided. 086 */ 087 @Nullable 088 String metaDataSchemaNameToUse(@Nullable String schemaName) ; 089 090 /** 091 * Are we using the meta-data for the table columns? 092 */ 093 boolean isTableColumnMetaDataUsed(); 094 095 /** 096 * Does this database support the JDBC 3.0 feature of retrieving generated keys: 097 * {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}? 098 */ 099 boolean isGetGeneratedKeysSupported(); 100 101 /** 102 * Does this database support a simple query to retrieve the generated key when 103 * the JDBC 3.0 feature of retrieving generated keys is not supported? 104 * @see #isGetGeneratedKeysSupported() 105 */ 106 boolean isGetGeneratedKeysSimulated(); 107 108 /** 109 * Get the simple query to retrieve a generated key. 110 */ 111 @Nullable 112 String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName); 113 114 /** 115 * Does this database support a column name String array for retrieving generated keys: 116 * {@link java.sql.Connection#createStruct(String, Object[])}? 117 */ 118 boolean isGeneratedKeysColumnNameArraySupported(); 119 120 /** 121 * Get the table parameter meta-data that is currently used. 122 * @return a List of {@link TableParameterMetaData} 123 */ 124 List<TableParameterMetaData> getTableParameterMetaData(); 125 126}