001/* 002 * Copyright 2002-2012 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.PreparedStatement; 020import java.sql.SQLException; 021 022import org.springframework.jdbc.support.JdbcUtils; 023 024/** 025 * Interface to be implemented for setting values for more complex database-specific 026 * types not supported by the standard {@code setObject} method. This is 027 * effectively an extended variant of {@link org.springframework.jdbc.support.SqlValue}. 028 * 029 * <p>Implementations perform the actual work of setting the actual values. They must 030 * implement the callback method {@code setTypeValue} which can throw SQLExceptions 031 * that will be caught and translated by the calling code. This callback method has 032 * access to the underlying Connection via the given PreparedStatement object, if that 033 * should be needed to create any database-specific objects. 034 * 035 * @author Thomas Risberg 036 * @author Juergen Hoeller 037 * @since 1.1 038 * @see java.sql.Types 039 * @see java.sql.PreparedStatement#setObject 040 * @see JdbcOperations#update(String, Object[], int[]) 041 * @see org.springframework.jdbc.support.SqlValue 042 */ 043public interface SqlTypeValue { 044 045 /** 046 * Constant that indicates an unknown (or unspecified) SQL type. 047 * Passed into {@code setTypeValue} if the original operation method 048 * does not specify a SQL type. 049 * @see java.sql.Types 050 * @see JdbcOperations#update(String, Object[]) 051 */ 052 int TYPE_UNKNOWN = JdbcUtils.TYPE_UNKNOWN; 053 054 055 /** 056 * Set the type value on the given PreparedStatement. 057 * @param ps the PreparedStatement to work on 058 * @param paramIndex the index of the parameter for which we need to set the value 059 * @param sqlType SQL type of the parameter we are setting 060 * @param typeName the type name of the parameter (optional) 061 * @throws SQLException if a SQLException is encountered while setting parameter values 062 * @see java.sql.Types 063 * @see java.sql.PreparedStatement#setObject 064 */ 065 void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException; 066 067}