001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 * http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014
015package de.softwareforge.testing.postgres.embedded;
016
017import jakarta.annotation.Nonnull;
018import java.io.IOException;
019import java.sql.SQLException;
020
021/**
022 * Prepare a specific object instance. This allows user interaction to modify or tweak an instance before it is used.
023 * <p>
024 * Allows e.g. for preparation of data sources, postgres instances and other places where additional degrees of customization are needed.
025 *
026 * @param <T> The object type to be prepared.
027 * @since 3.0
028 */
029@FunctionalInterface
030public interface EmbeddedPostgresPreparer<T> {
031
032    /**
033     * Returns a typed instance of a no-op (do nothing) preparer.
034     *
035     * @param <U> The type to use.
036     * @return a Do-nothing preparer.
037     */
038    static <U> EmbeddedPostgresPreparer<U> noOp() {
039        return element -> {};
040    }
041
042    /**
043     * Callback to customize a given object instance.
044     *
045     * @param element The instance. Must never be null. Any method on the builder can be called.
046     * @throws SQLException For any SQL related problems.
047     * @throws IOException  For any IO related problem.
048     */
049    void prepare(@Nonnull T element) throws IOException, SQLException;
050}