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.metadata;
018
019import java.sql.DatabaseMetaData;
020
021import org.springframework.lang.Nullable;
022
023/**
024 * Holder of meta-data for a specific parameter that is used for call processing.
025 *
026 * @author Thomas Risberg
027 * @author Juergen Hoeller
028 * @since 2.5
029 * @see GenericCallMetaDataProvider
030 */
031public class CallParameterMetaData {
032
033        private final boolean function;
034
035        @Nullable
036        private final String parameterName;
037
038        private final int parameterType;
039
040        private final int sqlType;
041
042        @Nullable
043        private final String typeName;
044
045        private final boolean nullable;
046
047
048        /**
049         * Constructor taking all the properties except the function marker.
050         */
051        @Deprecated
052        public CallParameterMetaData(
053                        @Nullable String columnName, int columnType, int sqlType, @Nullable String typeName, boolean nullable) {
054
055                this(false, columnName, columnType, sqlType, typeName, nullable);
056        }
057
058        /**
059         * Constructor taking all the properties including the function marker.
060         * @since 5.2.9
061         */
062        public CallParameterMetaData(boolean function, @Nullable String columnName, int columnType,
063                        int sqlType, @Nullable String typeName, boolean nullable) {
064
065                this.function = function;
066                this.parameterName = columnName;
067                this.parameterType = columnType;
068                this.sqlType = sqlType;
069                this.typeName = typeName;
070                this.nullable = nullable;
071        }
072
073
074        /**
075         * Return whether this parameter is declared in a function.
076         * @since 5.2.9
077         */
078        public boolean isFunction() {
079                return this.function;
080        }
081
082        /**
083         * Return the parameter name.
084         */
085        @Nullable
086        public String getParameterName() {
087                return this.parameterName;
088        }
089
090        /**
091         * Return the parameter type.
092         */
093        public int getParameterType() {
094                return this.parameterType;
095        }
096
097        /**
098         * Determine whether the declared parameter qualifies as a 'return' parameter
099         * for our purposes: type {@link DatabaseMetaData#procedureColumnReturn} or
100         * {@link DatabaseMetaData#procedureColumnResult}, or in case of a function,
101         * {@link DatabaseMetaData#functionReturn}.
102         * @since 4.3.15
103         */
104        public boolean isReturnParameter() {
105                return (this.function ? this.parameterType == DatabaseMetaData.functionReturn :
106                                (this.parameterType == DatabaseMetaData.procedureColumnReturn ||
107                                                this.parameterType == DatabaseMetaData.procedureColumnResult));
108        }
109
110        /**
111         * Return the parameter SQL type.
112         */
113        public int getSqlType() {
114                return this.sqlType;
115        }
116
117        /**
118         * Return the parameter type name.
119         */
120        @Nullable
121        public String getTypeName() {
122                return this.typeName;
123        }
124
125        /**
126         * Return whether the parameter is nullable.
127         */
128        public boolean isNullable() {
129                return this.nullable;
130        }
131
132}