no.ssb.lds.api.persistence.Transaction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of linked-data-store-persistence-provider-api Show documentation
Show all versions of linked-data-store-persistence-provider-api Show documentation
LinkedDataStore Persistence Provider API
package no.ssb.lds.api.persistence;
import java.util.concurrent.CompletableFuture;
public interface Transaction extends AutoCloseable {
CompletableFuture commit();
CompletableFuture cancel();
@Override
default void close() {
boolean committed = false;
try {
commit().join();
committed = true;
} catch (Throwable t) {
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
if (t instanceof Error) {
throw (Error) t;
}
throw new RuntimeException(t);
} finally {
if (!committed) {
cancel().join();
}
}
}
}