All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.descoped.rawdata.provider.postgres.tx.Transaction Maven / Gradle / Ivy

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();
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy