All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jdbc.connector.StatementImpl.scala Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2023-2024 by Takahiko Tominaga
 * This software is licensed under the MIT License (MIT).
 * For more information see LICENSE or https://opensource.org/licenses/MIT
 */

package jdbc.connector

import cats.syntax.all.*

import cats.effect.Sync

import ldbc.sql.{ Statement, ResultSet }

private[jdbc] case class StatementImpl[F[_]: Sync](statement: java.sql.Statement) extends Statement[F]:

  override def executeQuery(sql: String): F[ResultSet] =
    Sync[F].blocking(statement.executeQuery(sql)).map(ResultSetImpl.apply)

  override def executeUpdate(sql: String): F[Int] = Sync[F].blocking(statement.executeUpdate(sql))

  override def close(): F[Unit] = Sync[F].blocking(statement.close())

  override def execute(sql: String): F[Boolean] = Sync[F].blocking(statement.execute(sql))

  override def getResultSet(): F[Option[ResultSet]] =
    Sync[F].blocking(Option(statement.getResultSet)).map(_.map(ResultSetImpl.apply))

  override def getUpdateCount(): F[Int] = Sync[F].blocking(statement.getUpdateCount)

  override def getMoreResults(): F[Boolean] = Sync[F].blocking(statement.getMoreResults)

  override def addBatch(sql: String): F[Unit] = Sync[F].blocking(statement.addBatch(sql))

  override def clearBatch(): F[Unit] = Sync[F].blocking(statement.clearBatch())

  override def executeBatch(): F[Array[Int]] = Sync[F].blocking(statement.executeBatch())

  override def getGeneratedKeys(): F[ResultSet] =
    Sync[F].blocking(statement.getGeneratedKeys).map(ResultSetImpl.apply)

  override def executeUpdate(sql: String, autoGeneratedKeys: Int): F[Int] =
    Sync[F].blocking(statement.executeUpdate(sql, autoGeneratedKeys))

  override def execute(sql: String, autoGeneratedKeys: Int): F[Boolean] =
    Sync[F].blocking(statement.execute(sql, autoGeneratedKeys))

  override def isClosed(): F[Boolean] = Sync[F].blocking(statement.isClosed)

  override def getLargeUpdateCount(): F[Long] = Sync[F].blocking(statement.getLargeUpdateCount)

  override def executeLargeUpdate(sql: String): F[Long] =
    Sync[F].blocking(statement.executeLargeUpdate(sql))

  override def executeLargeUpdate(sql: String, autoGeneratedKeys: Int): F[Long] =
    Sync[F].blocking(statement.executeLargeUpdate(sql, autoGeneratedKeys))

  override def executeLargeBatch(): F[Array[Long]] =
    Sync[F].blocking(statement.executeLargeBatch())




© 2015 - 2024 Weber Informatics LLC | Privacy Policy