Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/2024 06 fix transaction #225

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions module/ldbc-dsl/src/main/scala/ldbc/dsl/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ trait Executor[F[_]: Temporal, T]:
* Functions for managing the processing of connections in a read-only manner.
*/
def readOnly(connection: Connection[F])(using LogHandler[F]): F[T] =
connection.setReadOnly(true) *> execute(connection)
connection.setReadOnly(true) *> execute(connection) <* connection.setReadOnly(false)

/**
* Functions to manage the processing of connections for writing.
Expand All @@ -44,7 +44,8 @@ trait Executor[F[_]: Temporal, T]:
* Functions to manage the processing of connections, always rolling back.
*/
def rollback(connection: Connection[F])(using LogHandler[F]): F[T] =
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> execute(connection) <* connection.rollback()
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> execute(connection) <* connection
.rollback() <* connection.setAutoCommit(true)

/**
* Functions to manage the processing of connections in a transaction.
Expand All @@ -53,9 +54,11 @@ trait Executor[F[_]: Temporal, T]:
val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection)

val release = (connection: Connection[F], exitCase: ExitCase) =>
exitCase match
(exitCase match
case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback()
case _ => connection.commit()
)
*> connection.setAutoCommit(true)

Resource
.makeCase(acquire)(release)
Expand Down