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
16 import java.io.IOException;
17 import java.sql.SQLException;
18
19 import edu.umd.cs.findbugs.annotations.NonNull;
20
21 /**
22 * Prepare a specific object instance. This allows user interaction to modify or tweak an instance before it is used.
23 * <p>
24 * Allows e.g. for preparation of data sources, postgres instances and other places where additional degrees of customization are needed.
25 *
26 * @param <T> The object type to be prepared.
27 */
28 @FunctionalInterface
29 public interface EmbeddedPostgresPreparer<T> {
30
31 /**
32 * Returns a typed instance of a no-op (do nothing) preparer.
33 *
34 * @param <U> The type to use.
35 * @return a Do-nothing preparer.
36 */
37 static <U> EmbeddedPostgresPreparer<U> noOp() {
38 return element -> {};
39 }
40
41 /**
42 * Callback to customize a given object instance.
43 *
44 * @param element The instance. Must never be null. Any method on the builder can be called.
45 * @throws SQLException For any SQL related problems.
46 * @throws IOException For any IO related problem.
47 */
48 void prepare(@NonNull T element) throws IOException, SQLException;
49 }