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