EmbeddedPostgresPreparer.java

  1. /*
  2.  * Licensed under the Apache License, Version 2.0 (the "License");
  3.  * you may not use this file except in compliance with the License.
  4.  * You may obtain a copy of the License at
  5.  *
  6.  * http://www.apache.org/licenses/LICENSE-2.0
  7.  *
  8.  * Unless required by applicable law or agreed to in writing, software
  9.  * distributed under the License is distributed on an "AS IS" BASIS,
  10.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11.  * See the License for the specific language governing permissions and
  12.  * limitations under the License.
  13.  */

  14. package de.softwareforge.testing.postgres.embedded;

  15. import jakarta.annotation.Nonnull;
  16. import java.io.IOException;
  17. import java.sql.SQLException;

  18. /**
  19.  * Prepare a specific object instance. This allows user interaction to modify or tweak an instance before it is used.
  20.  * <p>
  21.  * Allows e.g. for preparation of data sources, postgres instances and other places where additional degrees of customization are needed.
  22.  *
  23.  * @param <T> The object type to be prepared.
  24.  * @since 3.0
  25.  */
  26. @FunctionalInterface
  27. public interface EmbeddedPostgresPreparer<T> {

  28.     /**
  29.      * Returns a typed instance of a no-op (do nothing) preparer.
  30.      *
  31.      * @param <U> The type to use.
  32.      * @return a Do-nothing preparer.
  33.      */
  34.     static <U> EmbeddedPostgresPreparer<U> noOp() {
  35.         return element -> {};
  36.     }

  37.     /**
  38.      * Callback to customize a given object instance.
  39.      *
  40.      * @param element The instance. Must never be null. Any method on the builder can be called.
  41.      * @throws SQLException For any SQL related problems.
  42.      * @throws IOException  For any IO related problem.
  43.      */
  44.     void prepare(@Nonnull T element) throws IOException, SQLException;
  45. }