Skip to content

Commit

Permalink
#12 - Working through postgres driver incompatibilities 2
Browse files Browse the repository at this point in the history
  • Loading branch information
hohonuuli committed Apr 21, 2022
1 parent 9953511 commit 9fb2b19
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class JdbcRepository(entityManagerFactory: EntityManagerFactory) {
def countByQueryConstraint(constraints: QueryConstraints): Int = {
implicit val entityManager: EntityManager = entityManagerFactory.createEntityManager()
val query = QueryConstraints.toCountQuery(constraints, entityManager)
val count = query.getResultList.get(0).asInstanceOf[Int]
// Postgresql returns a Long, Everything else returns an Int
val count = query.getResultList.get(0).toString().toInt
entityManager.close()
count
}
Expand Down Expand Up @@ -371,7 +372,12 @@ class JdbcRepository(entityManagerFactory: EntityManagerFactory) {
): Seq[Image] = {
implicit val entityManager: EntityManager = entityManagerFactory.createEntityManager()
val query = entityManager.createNativeQuery(ImagedMomentSQL.byVideoReferenceUuid)
query.setParameter(1, videoReferenceUuid.toString)
if (DatabaseProductName.isPostgres()) {
query.setParameter(1, videoReferenceUuid)
}
else {
query.setParameter(1, videoReferenceUuid.toString)
}
limit.foreach(query.setMaxResults)
offset.foreach(query.setFirstResult)
val results = query.getResultList.asScala.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class AssociationDAOImpl(entityManager: EntityManager)
query
.getResultList
.asScala
.map(_.asInstanceOf[Long])
.map(_.toString().toLong)
.head

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ImagedMomentDAOImpl(entityManager: EntityManager)
query
.getResultList
.asScala
.map(_.asInstanceOf[Int])
.map(_.toString().toInt)
.head
}

Expand All @@ -162,8 +162,8 @@ class ImagedMomentDAOImpl(entityManager: EntityManager)
.asScala
.map(_.asInstanceOf[Array[Object]])
.map(xs => {
val uuid = UUID.fromString(xs(0).asInstanceOf[String])
val count = xs(1).asInstanceOf[Number].intValue()
val uuid = UUID.fromString(xs(0).toString())
val count = xs(1).toString().toInt
uuid -> count
})
.toMap
Expand All @@ -175,7 +175,7 @@ class ImagedMomentDAOImpl(entityManager: EntityManager)
query
.getResultList
.asScala
.map(_.asInstanceOf[Int])
.map(_.toString().toInt)
.head
}

Expand All @@ -199,7 +199,7 @@ class ImagedMomentDAOImpl(entityManager: EntityManager)
query
.getResultList
.asScala
.map(_.asInstanceOf[Int])
.map(_.toString().toInt)
.head
}

Expand All @@ -210,7 +210,7 @@ class ImagedMomentDAOImpl(entityManager: EntityManager)
query
.getResultList
.asScala
.map(_.asInstanceOf[Int])
.map(_.toString().toInt)
.head
}

Expand All @@ -228,11 +228,16 @@ class ImagedMomentDAOImpl(entityManager: EntityManager)

override def countByVideoReferenceUUID(uuid: UUID): Int = {
val query = entityManager.createNamedQuery("ImagedMoment.countByVideoReferenceUUID")
query.setParameter(1, uuid.toString)
if (DatabaseProductName.isPostgres()) {
query.setParameter(1, uuid)
}
else {
query.setParameter(1, uuid.toString)
}
query
.getResultList
.asScala
.map(_.asInstanceOf[Int])
.map(_.toString().toInt)
.head
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ class ObservationDAOImpl(entityManager: EntityManager)

override def findAllConceptsByVideoReferenceUUID(uuid: UUID): Seq[String] = {
val query = entityManager.createNamedQuery("Observation.findAllNamesByVideoReferenceUUID")
query.setParameter(1, uuid.toString().toLowerCase())
if (DatabaseProductName.isPostgres()) {
query.setParameter(1, uuid)
}
else {
query.setParameter(1, uuid.toString().toLowerCase())
}

query
.getResultList
.asScala
Expand All @@ -194,8 +200,7 @@ class ObservationDAOImpl(entityManager: EntityManager)
query
.getResultList
.asScala
.map(_.asInstanceOf[Number])
.map(_.intValue())
.map(_.toString().toInt)
.head
}

Expand Down

0 comments on commit 9fb2b19

Please sign in to comment.