Skip to content

Commit

Permalink
Merge pull request #225 from takapi327/bug/2024-06-Fix-transaction
Browse files Browse the repository at this point in the history
Bug/2024 06 fix transaction
  • Loading branch information
takapi327 authored Jun 3, 2024
2 parents 0e1ecc7 + c434f0d commit 11d8dce
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 11d8dce

Please sign in to comment.