Skip to content

Commit 4cb9918

Browse files
committed
More JDBC spec supported
1 parent d2f75a9 commit 4cb9918

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

src/main/scala/com/github/mmolimar/ksql/jdbc/KsqlConnection.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ class KsqlConnection(private[jdbc] val values: KsqlConnectionValues, properties:
234234

235235
override def getAutoCommit: Boolean = false
236236

237+
override def getSchema: String = None.orNull
238+
237239
override def isValid(timeout: Int): Boolean = ksqlClient.makeStatusRequest.isSuccessful
238240

239241
override def isClosed: Boolean = !connected.getOrElse(throw NotConnected(values.jdbcUrl))

src/main/scala/com/github/mmolimar/ksql/jdbc/KsqlDatabaseMetaData.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,11 @@ class KsqlDatabaseMetaData(private val ksqlConnection: KsqlConnection) extends D
430430

431431
override def getDatabaseProductVersion: String = KsqlDriver.ksqlVersion
432432

433-
override def getDatabaseMajorVersion: Int = KsqlDriver.driverMajorVersion
433+
override def getDatabaseMajorVersion: Int = KsqlDriver.ksqlMajorVersion
434434

435-
override def getDatabaseMinorVersion: Int = KsqlDriver.driverMinorVersion
435+
override def getDatabaseMinorVersion: Int = KsqlDriver.ksqlMinorVersion
436+
437+
override def getRowIdLifetime: RowIdLifetime = RowIdLifetime.ROWID_VALID_OTHER
436438

437439
override def getCatalogTerm: String = "TOPIC"
438440

@@ -470,12 +472,18 @@ class KsqlDatabaseMetaData(private val ksqlConnection: KsqlConnection) extends D
470472

471473
override def getConnection: Connection = ksqlConnection
472474

475+
override def getMaxIndexLength: Int = 0
476+
477+
override def getMaxSchemaNameLength: Int = 0
478+
473479
override def getMaxTableNameLength: Int = 0
474480

475481
override def getMaxTablesInSelect: Int = 0
476482

477483
override def getMaxUserNameLength: Int = 0
478484

485+
override def supportsResultSetType(`type`: Int): Boolean = `type` == ResultSet.TYPE_FORWARD_ONLY
486+
479487
override def getDefaultTransactionIsolation: Int = Connection.TRANSACTION_NONE
480488

481489
override def getSuperTables(catalog: String, schemaPattern: String,
@@ -744,7 +752,7 @@ class KsqlDatabaseMetaData(private val ksqlConnection: KsqlConnection) extends D
744752

745753
override def getNumericFunctions: String = availableFunctions(
746754
author = None,
747-
types = Set("INT", "BIGINT", "DOUBLE", "DECIMAL")
755+
types = Set("INT", "INTEGER", "BIGINT", "DOUBLE", "DECIMAL")
748756
).mkString(",")
749757

750758
override def getStringFunctions: String = availableFunctions(
@@ -868,6 +876,10 @@ class KsqlDatabaseMetaData(private val ksqlConnection: KsqlConnection) extends D
868876

869877
override def supportsTransactions: Boolean = false
870878

879+
override def supportsPositionedUpdate: Boolean = false
880+
881+
override def supportsPositionedDelete: Boolean = false
882+
871883
private def availableFunctions(author: Option[String] = None, names: Set[String] = Set.empty,
872884
types: Set[String] = Set(".*")): Set[String] = {
873885
var functions = mutable.Set.empty[String]

src/main/scala/com/github/mmolimar/ksql/jdbc/resultset/ResultSet.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ private[resultset] abstract class AbstractResultSet[T](private val metadata: Res
477477

478478
override def getString(columnLabel: String): String = getColumn[String](columnLabel)
479479

480+
override def getObject(columnIndex: Int): AnyRef = getColumn[AnyRef](columnIndex)
481+
482+
override def getObject(columnLabel: String): AnyRef = getColumn[AnyRef](columnLabel)
483+
480484
override def getMetaData: ResultSetMetaData = metadata
481485

482486
override def getWarnings: SQLWarning = None.orNull
@@ -512,7 +516,7 @@ private[resultset] abstract class AbstractResultSet[T](private val metadata: Res
512516

513517
import ImplicitClasses._
514518
ev.runtimeClass match {
515-
case Any_ if ev.runtimeClass == value.getClass => value
519+
case Any_ if ev.runtimeClass == Option(value).map(_.getClass).getOrElse(classOf[Object]) => value
516520
case String_ => Option(value).map(_.toString).getOrElse(None.orNull)
517521
case JBoolean_ if value.isInstanceOf[String] => JBoolean.parseBoolean(value.asInstanceOf[String])
518522
case JBoolean_ if value.isInstanceOf[Number] => value.asInstanceOf[Number].intValue != 0

src/test/scala/com/github/mmolimar/ksql/jdbc/KsqlConnectionSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class KsqlConnectionSpec extends AnyWordSpec with Matchers with MockFactory {
6464
ksqlConnection.setAutoCommit(true)
6565
ksqlConnection.setAutoCommit(false)
6666
ksqlConnection.getAutoCommit should be(false)
67+
ksqlConnection.getSchema should be(None.orNull)
6768
ksqlConnection.getWarnings should be(None.orNull)
6869
ksqlConnection.getCatalog should be(None.orNull)
6970
ksqlConnection.setCatalog("test")

src/test/scala/com/github/mmolimar/ksql/jdbc/KsqlDatabaseMetaDataSpec.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.mmolimar.ksql.jdbc
22

33
import java.io.InputStream
4-
import java.sql.{Connection, ResultSet, SQLException, SQLFeatureNotSupportedException}
4+
import java.sql.{Connection, ResultSet, RowIdLifetime, SQLException, SQLFeatureNotSupportedException}
55
import java.util.{Collections, Properties}
66

77
import com.github.mmolimar.ksql.jdbc.utils.TestUtils._
@@ -180,11 +180,14 @@ class KsqlDatabaseMetaDataSpec extends AnyWordSpec with Matchers with MockFactor
180180
metadata.getSearchStringEscape should be("%")
181181
metadata.getExtraNameCharacters should be("#@")
182182
metadata.getMaxConnections should be(0)
183+
metadata.getMaxIndexLength should be(0)
184+
metadata.getMaxSchemaNameLength should be(0)
183185
metadata.getMaxTableNameLength should be(0)
184186
metadata.getMaxTablesInSelect should be(0)
185187
metadata.getMaxUserNameLength should be(0)
186188
metadata.getMaxUserNameLength should be(0)
187189
metadata.getDefaultTransactionIsolation should be(Connection.TRANSACTION_NONE)
190+
metadata.getRowIdLifetime should be(RowIdLifetime.ROWID_VALID_OTHER)
188191
metadata.getUserName should be ("")
189192

190193
metadata.allProceduresAreCallable should be(false)
@@ -241,6 +244,9 @@ class KsqlDatabaseMetaDataSpec extends AnyWordSpec with Matchers with MockFactor
241244
metadata.supportsFullOuterJoins should be(true)
242245
metadata.supportsLimitedOuterJoins should be(true)
243246
metadata.supportsTransactions should be(false)
247+
metadata.supportsPositionedUpdate should be(false)
248+
metadata.supportsPositionedDelete should be(false)
249+
metadata.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY) should be(true)
244250
metadata.supportsUnion should be(false)
245251
metadata.supportsUnionAll should be(false)
246252
}

src/test/scala/com/github/mmolimar/ksql/jdbc/resultset/KsqlResultSetSpec.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,32 @@ class KsqlResultSetSpec extends AnyWordSpec with Matchers with MockFactory with
144144
resultSet.getDouble(index + 1) should be(e(8))
145145
resultSet.wasNull should be(false)
146146
}
147+
resultSet.getObject(1) should be(Int.box(1))
148+
resultSet.getObject(2) should be(Long.box(2L))
149+
resultSet.getObject(3) should be(Double.box(3.3d))
150+
resultSet.getObject(4) should be(Boolean.box(true))
151+
resultSet.getObject(5) should be("1")
152+
resultSet.getObject(6) should be(Map.empty)
153+
resultSet.getObject(7) should be(scala.Array.empty)
154+
resultSet.getObject(8) should be(Map.empty)
155+
156+
resultSet.getString(9) should be(None.orNull)
157+
resultSet.getBytes(9) should be(None.orNull)
158+
resultSet.getBoolean(9) should be(Boolean.box(false))
159+
resultSet.getByte(9) should be(Byte.box(0))
160+
resultSet.getShort(9) should be(Short.box(0))
161+
resultSet.getInt(9) should be(Int.box(0))
162+
resultSet.getLong(9) should be(Long.box(0L))
163+
resultSet.getFloat(9) should be(Float.box(0.0f))
164+
resultSet.getDouble(9) should be(Double.box(0.0d))
165+
resultSet.getObject(9) should be(None.orNull)
147166

148167
assertThrows[SQLException] {
149168
resultSet.getString(1000)
150169
}
170+
assertThrows[SQLException] {
171+
resultSet.getObject("UNKNOWN")
172+
}
151173
assertThrows[SQLException] {
152174
resultSet.getString("UNKNOWN")
153175
}

0 commit comments

Comments
 (0)