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