Skip to content

Commit

Permalink
Action sbt scalafmtAll
Browse files Browse the repository at this point in the history
  • Loading branch information
takapi327 committed Jan 2, 2025
1 parent a96c09d commit 772cef5
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions module/ldbc-dsl/src/main/scala/ldbc/dsl/DBIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object DBIO:
private[ldbc] case class Impl[F[_]: Temporal, T](
statement: String,
params: List[Parameter],
func: Connection[F] => F[T]
func: Connection[F] => F[T]
) extends DBIO[F, T]:

override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[T] =
Expand All @@ -78,16 +78,17 @@ object DBIO:
connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection)

override def rollback(connection: Connection[F])(using LogHandler[F]): F[T] =
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true)
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection
.rollback() <* connection.setAutoCommit(true)

override def transaction(connection: Connection[F])(using LogHandler[F]): F[T] =
val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection)

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

Resource
Expand All @@ -96,39 +97,41 @@ object DBIO:

def pure[F[_]: Monad, A](value: A): DBIO[F, A] =
new DBIO[F, A]:
override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = Monad[F].pure(value)
override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value)
override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value)
override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value)
override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value)
override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = Monad[F].pure(value)
override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value)
override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value)
override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value)
override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value)

def raiseError[F[_], A](e: Throwable)(using ev: MonadThrow[F]): DBIO[F, A] =
new DBIO[F, A]:
override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = ev.raiseError(e)
override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e)
override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e)
override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e)
override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e)
override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = ev.raiseError(e)
override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e)
override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e)
override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e)
override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e)

given [F[_]: Temporal]: MonadError[[T] =>> DBIO[F, T], Throwable] with
override def pure[A](x: A): DBIO[F, A] = DBIO.pure(x)

override def flatMap[A, B](fa: DBIO[F, A])(f: A => DBIO[F, B]): DBIO[F, B] =
new DBIO[F, B]:
override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[B] = fa.run(connection).flatMap(a => f(a).run(connection))
override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[B] =
fa.run(connection).flatMap(a => f(a).run(connection))
override def readOnly(connection: Connection[F])(using LogHandler[F]): F[B] =
connection.setReadOnly(true) *> run(connection) <* connection.setReadOnly(false)
override def commit(connection: Connection[F])(using LogHandler[F]): F[B] =
connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection)
override def rollback(connection: Connection[F])(using LogHandler[F]): F[B] =
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true)
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection
.rollback() <* connection.setAutoCommit(true)
override def transaction(connection: Connection[F])(using LogHandler[F]): F[B] =
val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection)
val release = (connection: Connection[F], exitCase: ExitCase) =>
(exitCase match
case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback()
case _ => connection.commit()
)
case _ => connection.commit()
)
*> connection.setAutoCommit(true)
Resource
.makeCase(acquire)(release)
Expand All @@ -146,16 +149,17 @@ object DBIO:
connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection)

override def rollback(connection: Connection[F])(using LogHandler[F]): F[B] =
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true)
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection
.rollback() <* connection.setAutoCommit(true)

override def transaction(connection: Connection[F])(using LogHandler[F]): F[B] =
val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection)

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

Resource
Expand All @@ -174,16 +178,17 @@ object DBIO:
connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection)

override def rollback(connection: Connection[F])(using LogHandler[F]): F[B] =
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true)
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection
.rollback() <* connection.setAutoCommit(true)

override def transaction(connection: Connection[F])(using LogHandler[F]): F[B] =
val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection)

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

Resource
Expand All @@ -205,16 +210,17 @@ object DBIO:
connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection)

override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] =
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true)
connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection
.rollback() <* connection.setAutoCommit(true)

override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] =
val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection)

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

Resource
Expand Down

0 comments on commit 772cef5

Please sign in to comment.