001/* 002 * Copyright 2002-2018 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.ResultSet; 020 021import org.springframework.lang.Nullable; 022 023/** 024 * Common base class for ResultSet-supporting SqlParameters like 025 * {@link SqlOutParameter} and {@link SqlReturnResultSet}. 026 * 027 * @author Juergen Hoeller 028 * @since 1.0.2 029 */ 030public class ResultSetSupportingSqlParameter extends SqlParameter { 031 032 @Nullable 033 private ResultSetExtractor<?> resultSetExtractor; 034 035 @Nullable 036 private RowCallbackHandler rowCallbackHandler; 037 038 @Nullable 039 private RowMapper<?> rowMapper; 040 041 042 /** 043 * Create a new ResultSetSupportingSqlParameter. 044 * @param name the name of the parameter, as used in input and output maps 045 * @param sqlType the parameter SQL type according to {@code java.sql.Types} 046 */ 047 public ResultSetSupportingSqlParameter(String name, int sqlType) { 048 super(name, sqlType); 049 } 050 051 /** 052 * Create a new ResultSetSupportingSqlParameter. 053 * @param name the name of the parameter, as used in input and output maps 054 * @param sqlType the parameter SQL type according to {@code java.sql.Types} 055 * @param scale the number of digits after the decimal point 056 * (for DECIMAL and NUMERIC types) 057 */ 058 public ResultSetSupportingSqlParameter(String name, int sqlType, int scale) { 059 super(name, sqlType, scale); 060 } 061 062 /** 063 * Create a new ResultSetSupportingSqlParameter. 064 * @param name the name of the parameter, as used in input and output maps 065 * @param sqlType the parameter SQL type according to {@code java.sql.Types} 066 * @param typeName the type name of the parameter (optional) 067 */ 068 public ResultSetSupportingSqlParameter(String name, int sqlType, @Nullable String typeName) { 069 super(name, sqlType, typeName); 070 } 071 072 /** 073 * Create a new ResultSetSupportingSqlParameter. 074 * @param name the name of the parameter, as used in input and output maps 075 * @param sqlType the parameter SQL type according to {@code java.sql.Types} 076 * @param rse the {@link ResultSetExtractor} to use for parsing the {@link ResultSet} 077 */ 078 public ResultSetSupportingSqlParameter(String name, int sqlType, ResultSetExtractor<?> rse) { 079 super(name, sqlType); 080 this.resultSetExtractor = rse; 081 } 082 083 /** 084 * Create a new ResultSetSupportingSqlParameter. 085 * @param name the name of the parameter, as used in input and output maps 086 * @param sqlType the parameter SQL type according to {@code java.sql.Types} 087 * @param rch the {@link RowCallbackHandler} to use for parsing the {@link ResultSet} 088 */ 089 public ResultSetSupportingSqlParameter(String name, int sqlType, RowCallbackHandler rch) { 090 super(name, sqlType); 091 this.rowCallbackHandler = rch; 092 } 093 094 /** 095 * Create a new ResultSetSupportingSqlParameter. 096 * @param name the name of the parameter, as used in input and output maps 097 * @param sqlType the parameter SQL type according to {@code java.sql.Types} 098 * @param rm the {@link RowMapper} to use for parsing the {@link ResultSet} 099 */ 100 public ResultSetSupportingSqlParameter(String name, int sqlType, RowMapper<?> rm) { 101 super(name, sqlType); 102 this.rowMapper = rm; 103 } 104 105 106 /** 107 * Does this parameter support a ResultSet, i.e. does it hold a 108 * ResultSetExtractor, RowCallbackHandler or RowMapper? 109 */ 110 public boolean isResultSetSupported() { 111 return (this.resultSetExtractor != null || this.rowCallbackHandler != null || this.rowMapper != null); 112 } 113 114 /** 115 * Return the ResultSetExtractor held by this parameter, if any. 116 */ 117 @Nullable 118 public ResultSetExtractor<?> getResultSetExtractor() { 119 return this.resultSetExtractor; 120 } 121 122 /** 123 * Return the RowCallbackHandler held by this parameter, if any. 124 */ 125 @Nullable 126 public RowCallbackHandler getRowCallbackHandler() { 127 return this.rowCallbackHandler; 128 } 129 130 /** 131 * Return the RowMapper held by this parameter, if any. 132 */ 133 @Nullable 134 public RowMapper<?> getRowMapper() { 135 return this.rowMapper; 136 } 137 138 139 /** 140 * This implementation always returns {@code false}. 141 */ 142 @Override 143 public boolean isInputValueProvided() { 144 return false; 145 } 146 147}