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 * Subclass of {@link SqlParameter} to represent an output parameter.
025 * No additional properties: instanceof will be used to check for such types.
026 *
027 * <p>Output parameters - like all stored procedure parameters - must have names.
028 *
029 * @author Rod Johnson
030 * @author Thomas Risberg
031 * @author Juergen Hoeller
032 * @see SqlReturnResultSet
033 * @see SqlInOutParameter
034 */
035public class SqlOutParameter extends ResultSetSupportingSqlParameter {
036
037        @Nullable
038        private SqlReturnType sqlReturnType;
039
040
041        /**
042         * Create a new SqlOutParameter.
043         * @param name the name of the parameter, as used in input and output maps
044         * @param sqlType the parameter SQL type according to {@code java.sql.Types}
045         */
046        public SqlOutParameter(String name, int sqlType) {
047                super(name, sqlType);
048        }
049
050        /**
051         * Create a new SqlOutParameter.
052         * @param name the name of the parameter, as used in input and output maps
053         * @param sqlType the parameter SQL type according to {@code java.sql.Types}
054         * @param scale the number of digits after the decimal point
055         * (for DECIMAL and NUMERIC types)
056         */
057        public SqlOutParameter(String name, int sqlType, int scale) {
058                super(name, sqlType, scale);
059        }
060
061        /**
062         * Create a new SqlOutParameter.
063         * @param name the name of the parameter, as used in input and output maps
064         * @param sqlType the parameter SQL type according to {@code java.sql.Types}
065         * @param typeName the type name of the parameter (optional)
066         */
067        public SqlOutParameter(String name, int sqlType, @Nullable String typeName) {
068                super(name, sqlType, typeName);
069        }
070
071        /**
072         * Create a new SqlOutParameter.
073         * @param name the name of the parameter, as used in input and output maps
074         * @param sqlType the parameter SQL type according to {@code java.sql.Types}
075         * @param typeName the type name of the parameter (optional)
076         * @param sqlReturnType custom value handler for complex type (optional)
077         */
078        public SqlOutParameter(String name, int sqlType, @Nullable String typeName, @Nullable SqlReturnType sqlReturnType) {
079                super(name, sqlType, typeName);
080                this.sqlReturnType = sqlReturnType;
081        }
082
083        /**
084         * Create a new SqlOutParameter.
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 rse the {@link ResultSetExtractor} to use for parsing the {@link ResultSet}
088         */
089        public SqlOutParameter(String name, int sqlType, ResultSetExtractor<?> rse) {
090                super(name, sqlType, rse);
091        }
092
093        /**
094         * Create a new SqlOutParameter.
095         * @param name the name of the parameter, as used in input and output maps
096         * @param sqlType the parameter SQL type according to {@code java.sql.Types}
097         * @param rch the {@link RowCallbackHandler} to use for parsing the {@link ResultSet}
098         */
099        public SqlOutParameter(String name, int sqlType, RowCallbackHandler rch) {
100                super(name, sqlType, rch);
101        }
102
103        /**
104         * Create a new SqlOutParameter.
105         * @param name the name of the parameter, as used in input and output maps
106         * @param sqlType the parameter SQL type according to {@code java.sql.Types}
107         * @param rm the {@link RowMapper} to use for parsing the {@link ResultSet}
108         */
109        public SqlOutParameter(String name, int sqlType, RowMapper<?> rm) {
110                super(name, sqlType, rm);
111        }
112
113
114        /**
115         * Return the custom return type, if any.
116         */
117        @Nullable
118        public SqlReturnType getSqlReturnType() {
119                return this.sqlReturnType;
120        }
121
122        /**
123         * Return whether this parameter holds a custom return type.
124         */
125        public boolean isReturnTypeSupported() {
126                return (this.sqlReturnType != null);
127        }
128
129}