From fc4752cc860437ace0047651b1e16a429a2d78b7 Mon Sep 17 00:00:00 2001 From: David Benedeki <14905969+benedeki@users.noreply.github.com> Date: Tue, 1 Oct 2024 23:33:18 +0200 Subject: [PATCH] #38: SimpleJsonString cannot be used as an input parameter (#39) * Added `SimpleJsonString` among `AllowedParamTypes` --- .../absa/db/balta/classes/setter/AllowedParamTypes.scala | 4 +++- .../za/co/absa/db/balta/classes/setter/SetterFnc.scala | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/balta/src/main/scala/za/co/absa/db/balta/classes/setter/AllowedParamTypes.scala b/balta/src/main/scala/za/co/absa/db/balta/classes/setter/AllowedParamTypes.scala index 7383c40..fff4514 100644 --- a/balta/src/main/scala/za/co/absa/db/balta/classes/setter/AllowedParamTypes.scala +++ b/balta/src/main/scala/za/co/absa/db/balta/classes/setter/AllowedParamTypes.scala @@ -16,7 +16,7 @@ package za.co.absa.db.balta.classes.setter -import za.co.absa.db.balta.classes.simple.JsonBString +import za.co.absa.db.balta.classes.simple.{JsonBString, SimpleJsonString} import java.time.{Instant, LocalDate, LocalTime, OffsetDateTime} import java.util.UUID @@ -52,6 +52,8 @@ object AllowedParamTypes { implicit object JsonBParamType extends AllowedParamTypes[JsonBString] + implicit object SimpleJsonStringParamType extends AllowedParamTypes[SimpleJsonString] + implicit object InstantParamType extends AllowedParamTypes[Instant] implicit object OffsetDateTimeParamType extends AllowedParamTypes[OffsetDateTime] diff --git a/balta/src/main/scala/za/co/absa/db/balta/classes/setter/SetterFnc.scala b/balta/src/main/scala/za/co/absa/db/balta/classes/setter/SetterFnc.scala index 6722abd..09be127 100644 --- a/balta/src/main/scala/za/co/absa/db/balta/classes/setter/SetterFnc.scala +++ b/balta/src/main/scala/za/co/absa/db/balta/classes/setter/SetterFnc.scala @@ -19,7 +19,7 @@ package za.co.absa.db.balta.classes.setter import java.sql.{Date, PreparedStatement, Time, Types => SqlTypes} import java.util.UUID import org.postgresql.util.PGobject -import za.co.absa.db.balta.classes.simple.JsonBString +import za.co.absa.db.balta.classes.simple.{JsonBString, SimpleJsonString} import java.time.{Instant, LocalDate, LocalTime, OffsetDateTime, ZoneOffset} @@ -50,7 +50,8 @@ object SetterFnc { case ch: Char => simple((prep: PreparedStatement, position: Int) => {prep.setString(position, ch.toString)}) case s: String => simple((prep: PreparedStatement, position: Int) => {prep.setString(position, s)}) case u: UUID => new UuidSetterFnc(u) - case js: JsonBString => new JsonBSetterFnc(js) + case js: JsonBString => new JsonSetterFnc(js.value) + case js: SimpleJsonString => new JsonSetterFnc(js.value) case i: Instant => simple((prep: PreparedStatement, position: Int) => {prep.setObject(position, OffsetDateTime.ofInstant(i, ZoneOffset.UTC))}) case ts: OffsetDateTime => simple((prep: PreparedStatement, position: Int) => {prep.setObject(position, ts)}) case lt: LocalTime => simple((prep: PreparedStatement, position: Int) => {prep.setTime(position, Time.valueOf(lt))}) @@ -73,10 +74,10 @@ object SetterFnc { } } - private class JsonBSetterFnc(value: JsonBString) extends SetterFnc { + private class JsonSetterFnc(jsonString: String) extends SetterFnc { private val jsonObject = new PGobject() jsonObject.setType("jsonb") - jsonObject.setValue(value.value) + jsonObject.setValue(jsonString) def apply(prep: PreparedStatement, position: Int): Unit = { prep.setObject(position, jsonObject)