001/* 002 * Copyright 2015-2022 Transmogrify LLC, 2022-2026 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 org.jspecify.annotations.NonNull; 020 021import javax.annotation.concurrent.ThreadSafe; 022import java.util.List; 023import java.util.Optional; 024 025/** 026 * Encapsulates {@link java.sql.PreparedStatement} parameter data meant to be bound to a formal <a href="https://docs.oracle.com/en/java/javase/26/docs/api/java.sql/java/sql/Array.html" target="_blank">{@code java.sql.Array}</a> type by {@link PreparedStatementBinder}. 027 * <p> 028 * The {@code baseTypeName} corresponds to the value of <a href="https://docs.oracle.com/en/java/javase/26/docs/api/java.sql/java/sql/Array.html#getBaseTypeName()" target="_blank">{@code java.sql.Array#getBaseTypeName()}</a> 029 * and is database-specific. 030 * <p> 031 * You may determine available {@code baseTypeName} values for your database by examining metadata exposed via {@link Database#readDatabaseMetaData(DatabaseMetaDataReader)}. 032 * <p> 033 * Standard instances may be constructed via {@link Parameters#sqlArrayOf(String, Object[])} and {@link Parameters#sqlArrayOf(String, List)}. 034 * A null element container represents SQL NULL, distinct from an empty array. On PostgreSQL the default binder 035 * asks the driver to resolve the element's actual array type, preserving typed nulls without column context. 036 * Type-name syntax remains driver-specific; for PostgreSQL typed nulls supply the element name, such as 037 * {@code "text"}, rather than constructing an array name such as {@code "text[]"}. 038 * <p> 039 * Elements may themselves be {@code SqlArrayParameter}s. Pyranid materializes nested arrays recursively, but 040 * multidimensional support and type-name syntax remain driver-specific; this shape is integration-verified on 041 * DuckDB. Each containing array's {@code baseTypeName} must name its element type. 042 * <p> 043 * DuckDB elements that represent an instant require an explicit {@code TIMESTAMP} or {@code TIMESTAMPTZ} 044 * base type. A named type alias does not expose its underlying timestamp semantics through this binding path, 045 * so binding an instant-bearing value through one fails fast rather than guessing. 046 * <p> 047 * Implementations should be threadsafe. 048 * 049 * @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}. 050 * @author <a href="https://www.revetkn.com">Mark Allen</a> 051 * @since 3.0.0 052 */ 053@ThreadSafe 054public interface SqlArrayParameter<E> { 055 /** 056 * Gets the element type of this SQL ARRAY, which corresponds to the value of <a href="https://docs.oracle.com/en/java/javase/26/docs/api/java.sql/java/sql/Array.html#getBaseTypeName()" target="_blank">{@code java.sql.Array#getBaseTypeName()}</a> 057 * and is database-specific. 058 * 059 * @return the element type of this SQL ARRAY 060 */ 061 @NonNull 062 String getBaseTypeName(); 063 064 /** 065 * Gets the elements of this SQL ARRAY. 066 * 067 * @return the elements of this SQL ARRAY 068 */ 069 @NonNull 070 Optional<E[]> getElements(); 071}