001/* 002 * Copyright 2002-2017 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.jdbc.support.nativejdbc.NativeJdbcExtractor; 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, String catalogName, 051 String schemaName, 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 String tableNameToUse(String tableName); 058 059 /** 060 * Get the catalog name formatted based on meta-data information. 061 * This could include altering the case. 062 */ 063 String catalogNameToUse(String catalogName); 064 065 /** 066 * Get the schema name formatted based on meta-data information. 067 * This could include altering the case. 068 */ 069 String schemaNameToUse(String schemaName); 070 071 /** 072 * Provide any modification of the catalog name passed in to match the meta-data currently used. 073 * The returned value will be used for meta-data lookups. 074 * This could include altering the case used or providing a base catalog if none is provided. 075 */ 076 String metaDataCatalogNameToUse(String catalogName) ; 077 078 /** 079 * Provide any modification of the schema name passed in to match the meta-data currently used. 080 * The returned value will be used for meta-data lookups. 081 * This could include altering the case used or providing a base schema if none is provided. 082 */ 083 String metaDataSchemaNameToUse(String schemaName) ; 084 085 /** 086 * Are we using the meta-data for the table columns? 087 */ 088 boolean isTableColumnMetaDataUsed(); 089 090 /** 091 * Does this database support the JDBC 3.0 feature of retrieving generated keys: 092 * {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}? 093 */ 094 boolean isGetGeneratedKeysSupported(); 095 096 /** 097 * Does this database support a simple query to retrieve the generated key when 098 * the JDBC 3.0 feature of retrieving generated keys is not supported? 099 * @see #isGetGeneratedKeysSupported() 100 */ 101 boolean isGetGeneratedKeysSimulated(); 102 103 /** 104 * Get the simple query to retrieve a generated key. 105 */ 106 String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName); 107 108 /** 109 * Does this database support a column name String array for retrieving generated keys: 110 * {@link java.sql.Connection#createStruct(String, Object[])}? 111 */ 112 boolean isGeneratedKeysColumnNameArraySupported(); 113 114 /** 115 * Get the table parameter meta-data that is currently used. 116 * @return List of {@link TableParameterMetaData} 117 */ 118 List<TableParameterMetaData> getTableParameterMetaData(); 119 120 /** 121 * Set the {@link NativeJdbcExtractor} to use to retrieve the native connection if necessary 122 */ 123 void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor); 124 125}