transaction<T> method
Future<T>
transaction<T>(
- ManagedContext transactionContext,
- Future<
T> transactionBlock(- ManagedContext transaction
override
Implementation
@override
Future<T> transaction<T>(ManagedContext transactionContext,
Future<T> transactionBlock(ManagedContext transaction)) async {
final dbConnection = await getDatabaseConnection();
T? output;
Rollback? rollback;
try {
await dbConnection.transaction((dbTransactionContext) async {
transactionContext.persistentStore =
PostgreSQLPersistentStore._transactionProxy(
this, dbTransactionContext);
try {
output = await transactionBlock(transactionContext);
} on Rollback catch (e) {
rollback = e;
dbTransactionContext.cancelTransaction(reason: rollback!.reason);
}
});
} on PostgreSQLException catch (e) {
final QueryException<PostgreSQLException>? interpreted =
_interpretException(e);
if (interpreted != null) {
throw interpreted;
}
rethrow;
}
if (rollback != null) {
throw rollback as Object;
}
return output!;
}