1 /* 2 * Copyright 2002-2013 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.jdbc.core.metadata; 18 19 import java.sql.DatabaseMetaData; 20 import java.sql.SQLException; 21 import java.util.List; 22 23 import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor; 24 25 /** 26 * Interface specifying the API to be implemented by a class providing table metedata. This is intended for internal use 27 * by the Simple JDBC classes. 28 * 29 * @author Thomas Risberg 30 * @since 2.5 31 */ 32 public interface TableMetaDataProvider { 33 34 /** 35 * Initialize using the database metedata provided 36 * @param databaseMetaData 37 * @throws SQLException 38 */ 39 void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException; 40 41 /** 42 * Initialize using provided database metadata, table and column information. This initalization can be 43 * turned off by specifying that column meta data should not be used. 44 * @param databaseMetaData used to retrieve database specific information 45 * @param catalogName name of catalog to use or null 46 * @param schemaName name of schema name to use or null 47 * @param tableName name of the table 48 * @throws SQLException 49 */ 50 void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName) 51 throws SQLException; 52 53 /** 54 * Get the table name formatted based on metadata information. This could include altering the case. 55 * 56 * @param tableName 57 * @return table name formatted 58 */ 59 String tableNameToUse(String tableName); 60 61 /** 62 * Get the catalog name formatted based on metadata information. This could include altering the case. 63 * 64 * @param catalogName 65 * @return catalog name formatted 66 */ 67 String catalogNameToUse(String catalogName); 68 69 /** 70 * Get the schema name formatted based on metadata information. This could include altering the case. 71 * 72 * @param schemaName 73 * @return schema name formatted 74 */ 75 String schemaNameToUse(String schemaName); 76 77 /** 78 * Provide any modification of the catalog name passed in to match the meta data currently used. 79 * The returned value will be used for meta data lookups. This could include altering the case used or 80 * providing a base catalog if none is provided. 81 * 82 * @param catalogName 83 * @return catalog name to use 84 */ 85 String metaDataCatalogNameToUse(String catalogName) ; 86 87 /** 88 * Provide any modification of the schema name passed in to match the meta data currently used. 89 * The returned value will be used for meta data lookups. This could include altering the case used or 90 * providing a base schema if none is provided. 91 * 92 * @param schemaName 93 * @return schema name to use 94 */ 95 String metaDataSchemaNameToUse(String schemaName) ; 96 97 /** 98 * Are we using the meta data for the table columns? 99 */ 100 boolean isTableColumnMetaDataUsed(); 101 102 /** 103 * Does this database support the JDBC 3.0 feature of retreiving generated keys 104 * {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()} 105 */ 106 boolean isGetGeneratedKeysSupported(); 107 108 /** 109 * Does this database support a simple quey to retrieve the generated key whe the JDBC 3.0 feature 110 * of retreiving generated keys is not supported 111 * {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()} 112 */ 113 boolean isGetGeneratedKeysSimulated(); 114 115 /** 116 * Get the simple query to retrieve a generated key 117 */ 118 String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName); 119 120 /** 121 * Does this database support a column name String array for retreiving generated keys 122 * {@link java.sql.Connection#createStruct(String, Object[])} 123 */ 124 boolean isGeneratedKeysColumnNameArraySupported(); 125 126 /** 127 * Get the table parameter metadata that is currently used. 128 * @return List of {@link TableParameterMetaData} 129 */ 130 List<TableParameterMetaData> getTableParameterMetaData(); 131 132 /** 133 * Set the {@link NativeJdbcExtractor} to use to retrieve the native connection if necessary 134 */ 135 void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor); 136 }