io.descoped.rawdata.provider.postgres.PostgresTransaction 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;
import io.descoped.rawdata.provider.postgres.tx.Transaction;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.concurrent.CompletableFuture;
class PostgresTransaction implements Transaction {
final Connection connection;
public PostgresTransaction(Connection connection) throws SQLException {
this.connection = connection;
connection.beginRequest();
}
@Override
public Connection connection() {
return connection;
}
@Override
public CompletableFuture commit() throws PersistenceException {
try {
return CompletableFuture.completedFuture(null);
} finally {
try {
connection.commit();
connection.endRequest();
} catch (SQLException e) {
throw new PersistenceException(e);
} finally {
try {
connection.close();
} catch (SQLException e) {
throw new PersistenceException(e);
}
}
}
}
@Override
public CompletableFuture cancel() {
try {
return CompletableFuture.completedFuture(null);
} finally {
try {
connection.rollback();
connection.endRequest();
} catch (SQLException e) {
throw new PersistenceException(e);
} finally {
try {
connection.close();
} catch (SQLException e) {
throw new PersistenceException(e);
}
}
}
}
}