View Javadoc
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.core.SqlParameter;
24  
25  /**
26   * Interface specifying the API to be implemented by a class providing call metadata.
27   *
28   * <p>This is intended for internal use by Spring's
29   * {@link org.springframework.jdbc.core.simple.SimpleJdbcCall}.
30   *
31   * @author Thomas Risberg
32   * @since 2.5
33   */
34  public interface CallMetaDataProvider {
35  
36  	/**
37  	 * Initialize using the provided DatabaseMetData.
38  	 * @param databaseMetaData used to retrieve database specific information
39  	 * @throws SQLException in case of initialization failure
40  	 */
41  	void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException;
42  
43  	/**
44  	 * Initialize the database specific management of procedure column meta data.
45  	 * This is only called for databases that are supported. This initialization
46  	 * can be turned off by specifying that column meta data should not be used.
47  	 * @param databaseMetaData used to retrieve database specific information
48  	 * @param catalogName name of catalog to use or null
49  	 * @param schemaName name of schema name to use or null
50  	 * @param procedureName name of the stored procedure
51  	 * @throws SQLException in case of initialization failure
52  	 * @see	org.springframework.jdbc.core.simple.SimpleJdbcCall#withoutProcedureColumnMetaDataAccess()
53  	 */
54  	void initializeWithProcedureColumnMetaData(
55  			DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String procedureName)
56  			throws SQLException;
57  
58  	/**
59  	 * Provide any modification of the procedure name passed in to match the meta data currently used.
60  	 * This could include altering the case.
61  	 */
62  	String procedureNameToUse(String procedureName);
63  
64  	/**
65  	 * Provide any modification of the catalog name passed in to match the meta data currently used.
66  	 * This could include altering the case.
67  	 */
68  	String catalogNameToUse(String catalogName);
69  
70  	/**
71  	 * Provide any modification of the schema name passed in to match the meta data currently used.
72  	 * This could include altering the case.
73  	 */
74  	String schemaNameToUse(String schemaName);
75  
76  	/**
77  	 * Provide any modification of the catalog name passed in to match the meta data currently used.
78  	 * The returned value will be used for meta data lookups. This could include altering the case
79  	 * used or providing a base catalog if none is provided.
80  	 */
81  	String metaDataCatalogNameToUse(String catalogName) ;
82  
83  	/**
84  	 * Provide any modification of the schema name passed in to match the meta data currently used.
85  	 * The returned value will be used for meta data lookups. This could include altering the case
86  	 * used or providing a base schema if none is provided.
87  	 */
88  	String metaDataSchemaNameToUse(String schemaName) ;
89  
90  	/**
91  	 * Provide any modification of the column name passed in to match the meta data currently used.
92  	 * This could include altering the case.
93  	 * @param parameterName name of the parameter of column
94  	 */
95  	String parameterNameToUse(String parameterName);
96  
97  	/**
98  	 * Create a default out parameter based on the provided meta data.
99  	 * This is used when no explicit parameter declaration has been made.
100 	 * @param parameterName the name of the parameter
101 	 * @param meta meta data used for this call
102 	 * @return the configured SqlOutParameter
103 	 */
104 	SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta);
105 
106 	/**
107 	 * Create a default inout parameter based on the provided meta data.
108 	 * This is used when no explicit parameter declaration has been made.
109 	 * @param parameterName the name of the parameter
110 	 * @param meta meta data used for this call
111 	 * @return the configured SqlInOutParameter
112 	 */
113 	SqlParameter createDefaultInOutParameter(String parameterName, CallParameterMetaData meta);
114 
115 	/**
116 	 * Create a default in parameter based on the provided meta data.
117 	 * This is used when no explicit parameter declaration has been made.
118 	 * @param parameterName the name of the parameter
119 	 * @param meta meta data used for this call
120 	 * @return the configured SqlParameter
121 	 */
122 	SqlParameter createDefaultInParameter(String parameterName, CallParameterMetaData meta);
123 
124 	/**
125 	 * Get the name of the current user. Useful for meta data lookups etc.
126 	 * @return current user name from database connection
127 	 */
128 	String getUserName();
129 
130 	/**
131 	 * Does this database support returning ResultSets that should be retrieved with the JDBC call.
132 	 * {@link java.sql.Statement#getResultSet()}
133 	 */
134 	boolean isReturnResultSetSupported();
135 
136 	/**
137 	 * Does this database support returning ResultSets as ref cursors to be retrieved with
138 	 * {@link java.sql.CallableStatement#getObject(int)} for the specified column.
139 	 */
140 	boolean isRefCursorSupported();
141 
142 	/**
143 	 * Get the {@link java.sql.Types} type for columns that return ResultSets as ref cursors
144 	 * if this feature is supported.
145 	 */
146 	int getRefCursorSqlType();
147 
148 	/**
149 	 * Are we using the meta data for the procedure columns?
150 	 */
151 	boolean isProcedureColumnMetaDataUsed();
152 
153 	/**
154 	 * Should we bypass the return parameter with the specified name.
155 	 * This allows the database specific implementation to skip the processing
156 	 * for specific results returned by the database call.
157 	 */
158 	boolean byPassReturnParameter(String parameterName);
159 
160 	/**
161 	 * Get the call parameter metadata that is currently used.
162 	 * @return List of {@link CallParameterMetaData}
163 	 */
164 	List<CallParameterMetaData> getCallParameterMetaData();
165 
166 	/**
167 	 * Does the database support the use of catalog name in procedure calls
168 	 */
169 	boolean isSupportsCatalogsInProcedureCalls();
170 
171 	/**
172 	 * Does the database support the use of schema name in procedure calls
173 	 */
174 	boolean isSupportsSchemasInProcedureCalls();
175 
176 }