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

org.yupana.jdbc.YupanaStatement.scala Maven / Gradle / Ivy

There is a newer version: 0.19.0
Show newest version
/*
 * Copyright 2019 Rusexpertiza LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.yupana.jdbc

import java.sql.{ Array => _, _ }

class YupanaStatement(val connection: YupanaConnection) extends Statement {
  private var maxRows = 0
  private var fetchDirection = 0
  private var fetchSize = 0
  protected var lastResultSet: YupanaResultSet = _

  @throws[SQLException]
  override def executeQuery(sql: String): ResultSet = {
    execute(sql)
    lastResultSet
  }

  @throws[SQLException]
  override def execute(sql: String): Boolean = {
    val result = connection.runQuery(sql, Map.empty)
    lastResultSet = new YupanaResultSet(this, result, "TABLE")
    true
  }

  @throws[SQLException]
  override def executeUpdate(s: String): Int =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.executeUpdate(String,int)")

  @throws[SQLException]
  override def close(): Unit = {
    connection.close()
  }

  @throws[SQLException]
  override def getMaxFieldSize: Int =
    throw new SQLFeatureNotSupportedException("Method not supported: getMaxFieldSize()")

  @throws[SQLException]
  override def setMaxFieldSize(i: Int): Unit =
    throw new SQLFeatureNotSupportedException("Method not supported: setMaxFieldSize(int)")

  @throws[SQLException]
  override def getMaxRows: Int = maxRows

  @throws[SQLException]
  override def setMaxRows(maxRows: Int): Unit = this.maxRows = maxRows

  @throws[SQLException]
  override def setEscapeProcessing(b: Boolean): Unit =
    throw new SQLFeatureNotSupportedException("Method not supported: setEscapeProcessing(boolean)")

  @throws[SQLException]
  override def getQueryTimeout: Int = 0

  @throws[SQLException]
  override def setQueryTimeout(i: Int): Unit =
    throw new SQLFeatureNotSupportedException("Method not supported: setQueryTimeout(int)")

  @throws[SQLException]
  override def cancel(): Unit = {
    close()
  }

  @throws[SQLException]
  override def getWarnings: SQLWarning = null

  @throws[SQLException]
  override def clearWarnings(): Unit = {}

  @throws[SQLException]
  override def setCursorName(s: String): Unit =
    throw new SQLFeatureNotSupportedException("Method not supported: setCursorName(String)")

  @throws[SQLException]
  override def getResultSet: ResultSet = lastResultSet

  @throws[SQLException]
  override def getUpdateCount: Int = -1

  @throws[SQLException]
  override def getMoreResults: Boolean = false

  @throws[SQLException]
  override def setFetchDirection(fetchDirection: Int): Unit = this.fetchDirection = fetchDirection

  @throws[SQLException]
  override def getFetchDirection: Int = fetchDirection

  @throws[SQLException]
  override def setFetchSize(fetchSize: Int): Unit = this.fetchSize = fetchSize

  @throws[SQLException]
  override def getFetchSize: Int = fetchSize

  @throws[SQLException]
  override def getResultSetConcurrency: Int = ResultSet.CONCUR_READ_ONLY

  @throws[SQLException]
  override def getResultSetType: Int = ResultSet.TYPE_FORWARD_ONLY

  @throws[SQLException]
  override def addBatch(s: String): Unit =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.addBatch(String)")

  @throws[SQLException]
  override def clearBatch(): Unit =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.clearBatch()")

  @throws[SQLException]
  override def executeBatch: Array[Int] =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.executeBatch()")

  @throws[SQLException]
  override def getConnection: Connection = this.connection

  @throws[SQLException]
  override def getMoreResults(current: Int): Boolean =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.getMoreResults(int)")

  @throws[SQLException]
  override def getGeneratedKeys: ResultSet =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.getGeneratedKeys()")

  @throws[SQLException]
  override def executeUpdate(sql: String, autoGeneratedKeys: Int): Int =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.executeUpdate(String,int)")

  @throws[SQLException]
  override def executeUpdate(sql: String, columnIndexes: Array[Int]): Int =
    throw new SQLFeatureNotSupportedException("Method not supported: : Statement.executeUpdate(String,int[])")

  @throws[SQLException]
  override def executeUpdate(sql: String, columnNames: Array[String]): Int =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.executeUpdate(String,String[])")

  @throws[SQLException]
  override def execute(sql: String, autoGeneratedKeys: Int): Boolean =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.execute(String,int)")

  @throws[SQLException]
  override def execute(sql: String, columnIndexes: Array[Int]): Boolean =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.execute(String,int[])")

  @throws[SQLException]
  override def execute(sql: String, columnNames: Array[String]): Boolean =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.execute(String,String[])")

  @throws[SQLException]
  override def getResultSetHoldability: Int = ResultSet.CLOSE_CURSORS_AT_COMMIT

  @throws[SQLException]
  override def isClosed: Boolean = connection.isClosed

  @throws[SQLException]
  override def setPoolable(b: Boolean): Unit = {}

  @throws[SQLException]
  override def isPoolable: Boolean = false

  @throws[SQLException]
  override def closeOnCompletion(): Unit =
    throw new SQLFeatureNotSupportedException("Method not supported: Statement.closeOnCompletion()")

  @throws[SQLException]
  override def isCloseOnCompletion: Boolean = false

  @throws[SQLException]
  override def unwrap[T](aClass: Class[T]): T = {
    if (!aClass.isAssignableFrom(getClass)) {
      throw new SQLException(s"Cannot unwrap to ${aClass.getName}")
    }

    aClass.cast(this)
  }

  @throws[SQLException]
  override def isWrapperFor(aClass: Class[_]): Boolean = aClass.isAssignableFrom(getClass)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy