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.lang.reflect.Type;
023import java.util.List;
024import java.util.Map;
025import java.util.Optional;
026import java.util.Set;
027
028/**
029 * Special "type carrier" which avoids generic type erasure at runtime when {@link PreparedStatementBinder} binds parameters to {@link java.sql.PreparedStatement}.
030 * <p>
031 * Examples of where this is used:
032 * <ul>
033 *   <li>{@link Parameters#listOf(Class, List)}</li>
034 *   <li>{@link Parameters#setOf(Class, Set)}</li>
035 *   <li>{@link Parameters#mapOf(Class, Class, Map)}</li>
036 *   <li>{@link Parameters#arrayOf(Class, Object)}</li>
037 * </ul>
038 * Implementations should be threadsafe.
039 *
040 * @author <a href="https://www.revetkn.com">Mark Allen</a>
041 * @since 3.0.0
042 */
043@ThreadSafe
044public interface TypedParameter {
045        /**
046         * Gets the full type information for this parameter, including how it's parameterized.
047         *
048         * @return the full type information for this parameter
049         */
050        @NonNull
051        Type getExplicitType();
052
053        /**
054         * Gets the value of this parameter.
055         *
056         * @return the value of this parameter, or {@link Optional#empty()} if none
057         */
058        @NonNull
059        Optional<Object> getValue();
060}