001/* 002 * Copyright 2002-2020 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; 018 019import java.sql.CallableStatement; 020import java.sql.SQLException; 021 022import org.springframework.lang.Nullable; 023 024/** 025 * Interface to be implemented for retrieving values for more complex database-specific 026 * types not supported by the standard {@code CallableStatement.getObject} method. 027 * 028 * <p>Implementations perform the actual work of getting the actual values. They must 029 * implement the callback method {@code getTypeValue} which can throw SQLExceptions 030 * that will be caught and translated by the calling code. This callback method has 031 * access to the underlying Connection via the given CallableStatement object, if that 032 * should be needed to create any database-specific objects. 033 * 034 * @author Thomas Risberg 035 * @since 1.1 036 * @see java.sql.Types 037 * @see java.sql.CallableStatement#getObject 038 * @see org.springframework.jdbc.object.StoredProcedure#execute(java.util.Map) 039 */ 040public interface SqlReturnType { 041 042 /** 043 * Constant that indicates an unknown (or unspecified) SQL type. 044 * Passed into setTypeValue if the original operation method does 045 * not specify an SQL type. 046 * @see java.sql.Types 047 * @see JdbcOperations#update(String, Object[]) 048 */ 049 int TYPE_UNKNOWN = Integer.MIN_VALUE; 050 051 052 /** 053 * Get the type value from the specific object. 054 * @param cs the CallableStatement to operate on 055 * @param paramIndex the index of the parameter for which we need to set the value 056 * @param sqlType the SQL type of the parameter we are setting 057 * @param typeName the type name of the parameter (optional) 058 * @return the target value 059 * @throws SQLException if an SQLException is encountered setting parameter values 060 * (that is, there's no need to catch SQLException) 061 * @see java.sql.Types 062 * @see java.sql.CallableStatement#getObject 063 */ 064 Object getTypeValue(CallableStatement cs, int paramIndex, int sqlType, @Nullable String typeName) 065 throws SQLException; 066 067}