001/*
002 * Copyright 2015-2022 Transmogrify LLC, 2022-2025 Revetware LLC.
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 * http://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 com.pyranid;
018
019import javax.annotation.Nonnull;
020import javax.annotation.concurrent.ThreadSafe;
021import java.util.List;
022import java.util.Optional;
023
024/**
025 * Encapsulates {@link java.sql.PreparedStatement} parameter data meant to be bound to a formal <a href="https://docs.oracle.com/en/java/javase/24/docs/api/java.sql/java/sql/Array.html" target="_blank">{@code java.sql.Array}</a> type by {@link PreparedStatementBinder}.
026 * <p>
027 * The {@code baseTypeName} corresponds to the value of <a href="https://docs.oracle.com/en/java/javase/24/docs/api/java.sql/java/sql/Array.html#getBaseTypeName()" target="_blank">{@code java.sql.Array#getBaseTypeName()}</a>
028 * and is database-specific.
029 * <p>
030 * You may determine available {@code baseTypeName} values for your database by examining metadata exposed via {@link Database#readDatabaseMetaData(DatabaseMetaDataReader)}.
031 * <p>
032 * Stardard instances may be constructed via {@link Parameters#arrayOf(String, Object[])} and {@link Parameters#arrayOf(String, List)}.
033 * <p>
034 * Implementations should be threadsafe.
035 *
036 * @param <E> the Java element type of the array; each element must be bindable to the SQL element type named by {@link #getBaseTypeName()} by the active {@link PreparedStatementBinder}.
037 * @author <a href="https://www.revetkn.com">Mark Allen</a>
038 * @since 3.0.0
039 */
040@ThreadSafe
041public interface ArrayParameter<E> {
042        /**
043         * Gets the element type of this SQL ARRAY, which corresponds to the value of <a href="https://docs.oracle.com/en/java/javase/24/docs/api/java.sql/java/sql/Array.html#getBaseTypeName()" target="_blank">{@code java.sql.Array#getBaseTypeName()}</a>
044         * and is database-specific.
045         *
046         * @return the element type of this SQL ARRAY
047         */
048        @Nonnull
049        String getBaseTypeName();
050
051        /**
052         * Gets the elements of this SQL ARRAY.
053         *
054         * @return the elements of this SQL ARRAY
055         */
056        @Nonnull
057        Optional<E[]> getElements();
058}