Skip to content

Commit

Permalink
Merge branch 'feature/13-queryresultrow-conversion-for-product-types'…
Browse files Browse the repository at this point in the history
… of https://github.com/AbsaOSS/balta into feature/13-queryresultrow-conversion-for-product-types
  • Loading branch information
benedeki committed Oct 4, 2024
2 parents fa0d06d + 8c9fcd4 commit 87177d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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))})
Expand All @@ -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)
Expand Down

0 comments on commit 87177d8

Please sign in to comment.