001/*
002 * ============================================================================
003 *  Copyright © 2002-2023 by Thomas Thrien.
004 *  All Rights Reserved.
005 * ============================================================================
006 *  Licensed to the public under the agreements of the GNU Lesser General Public
007 *  License, version 3.0 (the "License"). You may obtain a copy of the License at
008 *
009 *       http://www.gnu.org/licenses/lgpl.html
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 *  License for the specific language governing permissions and limitations
015 *  under the License.
016 */
017
018package org.tquadrat.foundation.sql;
019
020import static org.apiguardian.api.API.Status.STABLE;
021
022import java.sql.SQLException;
023import java.sql.SQLType;
024import java.util.Collection;
025
026import org.apiguardian.api.API;
027import org.tquadrat.foundation.annotation.ClassVersion;
028
029/**
030 *  <p>{@summary An instance of an implementation of this interface can be used
031 *  to get information about the types and properties for each named parameter
032 *  in an
033 *  {@link EnhancedPreparedStatement}
034 *  instance.} For some queries and driver implementations, the data that would
035 *  be returned by a
036 *  {@link ParameterMetaData}
037 *  object may not be available until the {@code EnhancedPreparedStatement} has
038 *  been executed.</p>
039 *  <p>Each named parameter for an {@code EnhancedPreparedStatement} can be
040 *  applied to the underlying
041 *  {@link java.sql.PreparedStatement}
042 *  multiple times, for multiple parameter markers. The assumption is that the
043 *  features are the same for all occurrences. Only for the nullability, all
044 *  occurrences
045 *  {@linkplain #isNullable(String) will be checked}.</p>
046 *
047 *  @version $Id: ParameterMetaData.java 1075 2023-10-02 12:37:07Z tquadrat $
048 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
049 *  @UMLGraph.link
050 *  @since 0.1.0
051 *
052 *  @see java.sql.ParameterMetaData
053 */
054@ClassVersion( sourceVersion = "$Id: ParameterMetaData.java 1075 2023-10-02 12:37:07Z tquadrat $" )
055@API( status = STABLE, since = "0.1.0" )
056public sealed interface ParameterMetaData
057    permits org.tquadrat.foundation.sql.internal.ParameterMetaDataBase
058{
059        /*---------*\
060    ====** Methods **==========================================================
061        \*---------*/
062    /**
063     *  Retrieves the fully-qualified name of the Java class whose instances
064     *  should be passed to the method
065     *  {@link EnhancedPreparedStatement#setObject(String, Object)}.
066     *
067     *  @param  parameterName   The name of the parameter, prefixed by a colon.
068     *  @return The fully-qualified name of the class in the Java programming
069     *      language that would be used by the method
070     *      {@code EnhancedPreparedStatement.setObject()} to set the value in
071     *      the specified parameter. This is the class name used for custom
072     *      mapping.
073     *  @throws SQLException    A database access error occurred.
074     */
075    public String getParameterClassName( final String parameterName ) throws SQLException;
076
077    /**
078     *  Retrieves the number of parameters in the
079     *  {@link EnhancedPreparedStatement}
080     *  object for which this {@code ParameterMetaData} object contains
081     *  information.
082     *
083     *  @return The number of parameters.
084     *  @throws SQLException    A database access error occurred.
085     */
086    public int getParameterCount() throws SQLException;
087
088    /**
089     *  Retrieves the parameter indexes for the given parameter name.
090     *
091     *  @param  parameterName   The name of the parameter, prefixed by a colon.
092     *  @return The parameter indexes for this parameter name.
093     *  @throws SQLException    The given parameter name is not defined.
094     */
095    public int [] getParameterIndexes( final String parameterName ) throws SQLException;
096
097    /**
098     *  Retrieves the names of the parameters in the
099     *  {@link EnhancedPreparedStatement}
100     *  object for which this {@code ParameterMetaData} object contains
101     *  information.
102     *
103     *  @return The names of the parameters.
104     */
105    public Collection<String> getParameterNames();
106
107    /**
108     *  <p>{@summary Retrieves the designated parameter's SQL type.}</p>
109     *  <p>Different from
110     *  {@link java.sql.ParameterMetaData#getParameterType(int)}
111     *  will this method return an instance of
112     *  {@link java.sql.SQLType}
113     *  for the type, and not an integer.</p>
114     *  <p>If the numerical value (as defined in
115     *  {@link java.sql.Types})
116     *  is required, it can be obtained like this:</p>
117     *  <pre><code>  …
118     *  int sqlType = getParameterType( param ).getVendorTypeNumber().intValue();
119     *  …</code></pre>
120     *
121     *  @param  parameterName   The name of the parameter, prefixed by a colon.
122     *  @return The SQL type.
123     *  @throws SQLException    A database access error occurred.
124     *
125     *  @see    java.sql.JDBCType
126     */
127    public SQLType getParameterType( final String parameterName ) throws SQLException;
128
129    /**
130     *  Retrieves the designated parameter's database-specific type name.
131     *
132     *  @param  parameterName   The name of the parameter, prefixed by a colon.
133     *  @return The name of the type used by the database. If the parameter
134     *      type is a user-defined type, then a fully-qualified type name is
135     *      returned.
136     *  @throws SQLException    A database access error occurred.
137     */
138    public String getParameterTypeName( final String parameterName ) throws SQLException;
139
140    /**
141     *  <p>{@summary Retrieves the designated parameter's specified column
142     *  size.}</p>
143     *  <p>The returned value represents the maximum column size for the given
144     *  parameter. For numeric data, this is the maximum precision. For
145     *  character data, this is the length in characters. For datetime
146     *  data types, this is the length in characters of the String
147     *  representation (assuming the maximum allowed precision of the
148     *  fractional seconds component). For binary data, this is the length in
149     *  bytes. For the ROWID datatype, this is the length in bytes. 0 is
150     *  returned for data types where the column size is not applicable.</p>
151     *
152     *  @param  parameterName   The name of the parameter, prefixed by a colon.
153     *  @return The precision.
154     *  @throws SQLException    A database access error occurred.
155     */
156    public int getPrecision( final String parameterName ) throws SQLException;
157
158    /**
159     *  <p>{@summary Retrieves the designated parameter's number of digits to
160     *  right of the decimal point.}</p>
161     *  <p>0 is returned for data types where the scale is not applicable.</p>
162     *
163     *  @param  parameterName   The name of the parameter, prefixed by a colon.
164     *  @return The scale.
165     *  @throws SQLException    A database access error occurred.
166     */
167    public int getScale( final String parameterName ) throws SQLException;
168
169    /**
170     *  <p>{@summary Retrieves whether {@code NULL} values are allowed in the designated
171     *  parameter.}</p>
172     *  <p>If the parameter with the the given name is used multiple times in
173     *  the underlying
174     *  {@link java.sql.PreparedStatement},
175     *  this method returns
176     *  {@value java.sql.ParameterMetaData#parameterNullableUnknown}
177     *  when the nullability status is not the same for all uses.</p>
178     *
179     *  @param  parameterName   The name of the parameter, prefixed by a colon.
180     *  @return The nullability status of the given parameter; one of
181     *      {@link java.sql.ParameterMetaData#parameterNoNulls},
182     *      {@link java.sql.ParameterMetaData#parameterNullable},
183     *      or
184     *      {@link java.sql.ParameterMetaData#parameterNullableUnknown}.
185     *  @throws SQLException    A database access error occurs
186     */
187    @SuppressWarnings( "NonBooleanMethodNameMayNotStartWithQuestion" )
188    public int isNullable( final String parameterName ) throws SQLException;
189
190    /**
191     *  Retrieves whether values for the designated parameter can be signed
192     *  numbers.
193     *
194     *  @param  parameterName   The name of the parameter, prefixed by a colon.
195     *  @return {@code true} if a value can be a signed number, {@code false}
196     *      otherwise.
197     *  @throws SQLException    A database access error occurred.
198     */
199    public boolean isSigned( final String parameterName ) throws SQLException;
200}
201//  interface ParameterMetaData
202
203/*
204 *  End of File
205 */