com.landoop.jdbc4.LsqlPreparedSelectStatement.kt Maven / Gradle / Ivy
package com.landoop.jdbc4
import com.landoop.jdbc4.client.RestClient
import com.landoop.jdbc4.client.domain.StreamingSelectResult
import java.io.InputStream
import java.io.Reader
import java.math.BigDecimal
import java.net.URL
import java.sql.Blob
import java.sql.Clob
import java.sql.Connection
import java.sql.Date
import java.sql.NClob
import java.sql.ParameterMetaData
import java.sql.PreparedStatement
import java.sql.Ref
import java.sql.ResultSet
import java.sql.ResultSetMetaData
import java.sql.RowId
import java.sql.SQLFeatureNotSupportedException
import java.sql.SQLXML
import java.sql.Time
import java.sql.Timestamp
import java.util.*
import java.util.concurrent.TimeUnit
class LsqlPreparedSelectStatement(conn: Connection,
private val client: RestClient,
private val sql: String) : LsqlStatement(conn, client), PreparedStatement, Logging {
// the last resultset generated by this statement
private var rs: ResultSet = RowResultSet.empty()
/**
* Clears the current parameter values immediately.
* That is, the current record that is being "built" will be reset to empty.
*/
override fun clearParameters() = throw SQLFeatureNotSupportedException()
override fun execute(): Boolean {
// in this execute method we must block until we are completed
// or we receive a record, otherwise we don't know if we can return true or false
val result = select(sql)
rs = StreamingRowResultSet(this, result)
return result.hasData(1, TimeUnit.DAYS)
}
private fun select(sql: String): StreamingSelectResult {
val result = client.select(sql)
rs = StreamingRowResultSet(this, result)
return result
}
override fun executeQuery(): ResultSet {
select(sql)
return rs
}
// -- meta data methods
/**
* @return an empty result set because we do not yet support prepared statements for queries
*/
override fun getMetaData(): ResultSetMetaData = EmptyResultSetMetaData
override fun getParameterMetaData(): ParameterMetaData = throw SQLFeatureNotSupportedException()
// adds the current record to the batch
override fun addBatch() = throw SQLFeatureNotSupportedException()
override fun clearBatch() = throw SQLFeatureNotSupportedException()
override fun executeBatch(): IntArray = throw SQLFeatureNotSupportedException()
// -- methods which set values on the current record
override fun setCharacterStream(parameterIndex: Int, reader: Reader?, length: Int) = throw SQLFeatureNotSupportedException()
override fun setCharacterStream(parameterIndex: Int, reader: Reader?, length: Long) = throw SQLFeatureNotSupportedException()
override fun setCharacterStream(parameterIndex: Int, reader: Reader?) = throw SQLFeatureNotSupportedException()
override fun setDate(parameterIndex: Int, d: Date?) = throw SQLFeatureNotSupportedException()
override fun setDate(parameterIndex: Int, d: Date?, cal: Calendar?) = throw SQLFeatureNotSupportedException()
override fun setObject(parameterIndex: Int, x: Any?) = throw SQLFeatureNotSupportedException()
override fun setLong(parameterIndex: Int, x: Long) = throw SQLFeatureNotSupportedException()
override fun setNString(parameterIndex: Int, x: String?) = throw SQLFeatureNotSupportedException()
override fun setURL(parameterIndex: Int, u: URL?) = throw SQLFeatureNotSupportedException()
override fun setFloat(parameterIndex: Int, f: Float) = throw SQLFeatureNotSupportedException()
override fun setTime(parameterIndex: Int, t: Time?) = throw SQLFeatureNotSupportedException()
override fun setTime(parameterIndex: Int, x: Time?, cal: Calendar?) = throw SQLFeatureNotSupportedException()
override fun setNCharacterStream(parameterIndex: Int, value: Reader?, length: Long) = throw SQLFeatureNotSupportedException()
override fun setNCharacterStream(parameterIndex: Int, value: Reader?) = throw SQLFeatureNotSupportedException()
override fun setInt(parameterIndex: Int, x: Int) = throw SQLFeatureNotSupportedException()
override fun setDouble(parameterIndex: Int, x: Double) = throw SQLFeatureNotSupportedException()
override fun setBigDecimal(parameterIndex: Int, x: BigDecimal?) = throw SQLFeatureNotSupportedException()
override fun setObject(parameterIndex: Int, x: Any?, targetSqlType: Int) = throw SQLFeatureNotSupportedException()
override fun setString(parameterIndex: Int, x: String?) = throw SQLFeatureNotSupportedException()
override fun setNull(parameterIndex: Int, sqlType: Int) = throw SQLFeatureNotSupportedException()
override fun setNull(parameterIndex: Int, sqlType: Int, typeName: String?) = throw SQLFeatureNotSupportedException()
override fun setTimestamp(parameterIndex: Int, ts: Timestamp?) = throw SQLFeatureNotSupportedException()
override fun setTimestamp(parameterIndex: Int, ts: Timestamp?, cal: Calendar?) = throw SQLFeatureNotSupportedException()
override fun setShort(parameterIndex: Int, s: Short) = throw SQLFeatureNotSupportedException()
override fun setBoolean(parameterIndex: Int, b: Boolean) = throw SQLFeatureNotSupportedException()
override fun setByte(parameterIndex: Int, b: Byte) = throw SQLFeatureNotSupportedException()
// -- unsupported types
override fun setBinaryStream(parameterIndex: Int, x: InputStream?, length: Int) = throw SQLFeatureNotSupportedException()
override fun setBinaryStream(parameterIndex: Int, x: InputStream?, length: Long) = throw SQLFeatureNotSupportedException()
override fun setBinaryStream(parameterIndex: Int, x: InputStream?) = throw SQLFeatureNotSupportedException()
override fun setClob(parameterIndex: Int, x: Clob?) = throw SQLFeatureNotSupportedException()
override fun setClob(parameterIndex: Int, reader: Reader?, length: Long) = throw SQLFeatureNotSupportedException()
override fun setClob(parameterIndex: Int, reader: Reader?) = throw SQLFeatureNotSupportedException()
override fun setUnicodeStream(parameterIndex: Int, x: InputStream?, length: Int) = throw SQLFeatureNotSupportedException()
override fun setObject(parameterIndex: Int, x: Any?, targetSqlType: Int, scaleOrLength: Int) = throw SQLFeatureNotSupportedException()
override fun setBytes(parameterIndex: Int, x: ByteArray?) = throw SQLFeatureNotSupportedException()
override fun setSQLXML(parameterIndex: Int, xmlObject: SQLXML?) = throw SQLFeatureNotSupportedException()
override fun setRef(parameterIndex: Int, x: Ref?) = throw SQLFeatureNotSupportedException()
override fun setBlob(parameterIndex: Int, x: Blob?) = throw SQLFeatureNotSupportedException()
override fun setBlob(parameterIndex: Int, inputStream: InputStream?, length: Long) = throw SQLFeatureNotSupportedException()
override fun setBlob(parameterIndex: Int, inputStream: InputStream?) = throw SQLFeatureNotSupportedException()
override fun setArray(parameterIndex: Int, x: java.sql.Array?) = throw SQLFeatureNotSupportedException()
override fun setRowId(parameterIndex: Int, x: RowId?) = throw SQLFeatureNotSupportedException()
override fun setAsciiStream(parameterIndex: Int, x: InputStream?, length: Int) = throw SQLFeatureNotSupportedException()
override fun setAsciiStream(parameterIndex: Int, x: InputStream?, length: Long) = throw SQLFeatureNotSupportedException()
override fun setAsciiStream(parameterIndex: Int, x: InputStream?) = throw SQLFeatureNotSupportedException()
override fun setNClob(parameterIndex: Int, value: NClob?) = throw SQLFeatureNotSupportedException()
override fun setNClob(parameterIndex: Int, reader: Reader?, length: Long) = throw SQLFeatureNotSupportedException()
override fun setNClob(parameterIndex: Int, reader: Reader?) = throw SQLFeatureNotSupportedException()
// -- execute methods that accept SQL are not used by prepared statements
override fun execute(sql: String): Boolean = throw SQLFeatureNotSupportedException("This method cannot be called on a prepared statement")
override fun addBatch(sql: String?) = throw SQLFeatureNotSupportedException("This method cannot be called on a prepared statement")
override fun executeQuery(sql: String): ResultSet = throw SQLFeatureNotSupportedException("This method cannot be called on a prepared statement")
override fun execute(sql: String?, autoGeneratedKeys: Int): Boolean = throw SQLFeatureNotSupportedException("This method cannot be called on a prepared statement")
override fun execute(sql: String?, columnIndexes: IntArray?): Boolean = throw SQLFeatureNotSupportedException("This method cannot be called on a prepared statement")
override fun execute(sql: String?, columnNames: Array?): Boolean = throw SQLFeatureNotSupportedException("This method cannot be called on a prepared statement")
override fun executeUpdate(): Int = throw SQLFeatureNotSupportedException()
// == auto generated keys are not supported by kafka/lenses ==
override fun getGeneratedKeys(): ResultSet = throw SQLFeatureNotSupportedException("Auto generated keys are not supported by Lenses")
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy