1 /*******************************************************************************
2 * Copyright (c) 2016 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.function;
14 import java.util.Objects;
15 import java.util.function.Consumer;
17 import org.simantics.db.exception.DatabaseException;
20 * Represents a database operation that accepts a single input argument and
21 * returns no result and can throw database exceptions. Unlike most other
22 * functional interfaces, {@code DbConsumer} is expected to operate via
26 * This is a functional interface whose functional method is
27 * {@link #accept(Object)}. The only difference to {@link Consumer} is that this
28 * allows throwing DatabaseException.
31 * the type of the input to the operation
33 * @author Tuukka Lehtonen
37 public interface DbConsumer<T> {
40 * Performs this operation on the given argument.
42 * @param t the input argument
44 void accept(T t) throws DatabaseException;
47 * Returns a composed {@code Consumer} that performs, in sequence, this
48 * operation followed by the {@code after} operation. If performing either
49 * operation throws an exception, it is relayed to the caller of the
50 * composed operation. If performing this operation throws an exception,
51 * the {@code after} operation will not be performed.
53 * @param after the operation to perform after this operation
54 * @return a composed {@code Consumer} that performs in sequence this
55 * operation followed by the {@code after} operation
56 * @throws NullPointerException if {@code after} is null
58 default DbConsumer<T> andThen(DbConsumer<? super T> after) {
59 Objects.requireNonNull(after);
60 return (T t) -> { accept(t); after.accept(t); };