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 */
014package de.softwareforge.testing.postgres.embedded;
015
016import java.io.IOException;
017import java.sql.SQLException;
018
019import edu.umd.cs.findbugs.annotations.NonNull;
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 */
028@FunctionalInterface
029public interface EmbeddedPostgresPreparer<T> {
030
031    /**
032     * Returns a typed instance of a no-op (do nothing) preparer.
033     *
034     * @param <U> The type to use.
035     * @return a Do-nothing preparer.
036     */
037    static <U> EmbeddedPostgresPreparer<U> noOp() {
038        return element -> {};
039    }
040
041    /**
042     * Callback to customize a given object instance.
043     *
044     * @param element The instance. Must never be null. Any method on the builder can be called.
045     * @throws SQLException For any SQL related problems.
046     * @throws IOException  For any IO related problem.
047     */
048    void prepare(@NonNull T element) throws IOException, SQLException;
049}