io.descoped.rawdata.provider.postgres.tx.Transaction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rawdata-client-provider-postgres Show documentation
Show all versions of rawdata-client-provider-postgres Show documentation
Rawdata Client Provider PostgreSQL Database
The newest version!
package io.descoped.rawdata.provider.postgres.tx;
import java.sql.Connection;
import java.util.concurrent.CompletableFuture;
public interface Transaction extends AutoCloseable {
Connection connection();
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();
}
}
}
}